capper 1.2.4 → 2.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capper (1.2.2)
4
+ capper (2.0.0.pre1)
5
5
  capistrano (~> 2.12.0)
6
6
  capistrano_colors (~> 0.5.5)
7
7
  dedent
@@ -9,7 +9,7 @@ PATH
9
9
  rvm-capistrano (~> 1.2.7)
10
10
 
11
11
  GEM
12
- remote: http://rubygems.org/
12
+ remote: https://rubygems.org/
13
13
  specs:
14
14
  capistrano (2.12.0)
15
15
  highline
@@ -21,13 +21,13 @@ GEM
21
21
  dedent (0.0.2)
22
22
  erubis (2.7.0)
23
23
  highline (1.6.15)
24
- net-scp (1.0.4)
25
- net-ssh (>= 1.99.1)
26
- net-sftp (2.0.5)
27
- net-ssh (>= 2.0.9)
28
- net-ssh (2.6.3)
29
- net-ssh-gateway (1.1.0)
30
- net-ssh (>= 1.99.1)
24
+ net-scp (1.1.0)
25
+ net-ssh (>= 2.6.5)
26
+ net-sftp (2.1.1)
27
+ net-ssh (>= 2.6.5)
28
+ net-ssh (2.6.5)
29
+ net-ssh-gateway (1.2.0)
30
+ net-ssh (>= 2.6.5)
31
31
  rvm-capistrano (1.2.7)
32
32
  capistrano (>= 2.0.0)
33
33
 
data/README.rst CHANGED
@@ -272,6 +272,9 @@ The whenever recipe is a simplified version of whenevers native capistrano
272
272
  integration. With one application per user account the whole crontab can be
273
273
  used for whenever. Additionally this recipe take the ``ruby_exec_prefix``
274
274
  setting into account.
275
+ To define the target servers user the cron role.
276
+
277
+ server "app1.example.com", :app, :cron
275
278
 
276
279
  node deployment
277
280
  --------
data/lib/capper.rb CHANGED
@@ -9,11 +9,8 @@ include Capper::Utils::Templates
9
9
  require 'capper/utils/multistage'
10
10
  include Capper::Utils::Multistage
11
11
 
12
- require 'capper/utils/monit'
13
- include Capper::Utils::Monit
14
-
15
- require 'capper/utils/bluepill'
16
- include Capper::Utils::Bluepill
12
+ require 'capper/utils/systemd'
13
+ include Capper::Utils::Systemd
17
14
 
18
15
  # see https://github.com/capistrano/capistrano/issues/168
19
16
  Capistrano::Configuration::Namespaces::Namespace.class_eval do
data/lib/capper/base.rb CHANGED
@@ -59,6 +59,7 @@ _cset(:bin_path) { File.join(deploy_to, "bin") }
59
59
  _cset(:pid_path) { File.join(shared_path, "pids") }
60
60
  _cset(:log_path) { File.join(shared_path, "log") }
61
61
  _cset(:config_path) { File.join(shared_path, "config") }
62
+ _cset(:units_path) { File.join(deploy_to, ".config/systemd/user") }
62
63
 
63
64
  _cset(:releases) { capture("ls -x #{releases_path}", :except => { :no_release => true }).split.sort }
64
65
  _cset(:current_release) { releases.length > 0 ? File.join(releases_path, releases.last) : nil }
@@ -23,25 +23,6 @@ monit_config "delayed_job", <<EOF.dedent, :roles => :worker
23
23
  <% end %>
24
24
  EOF
25
25
 
26
- bluepill_config "delayed_job", <<EOF, :roles => :worker
27
- <% delayed_job_workers.each do |name, range| %>
28
- app.process("delayed_job_<%= name %>") do |process|
29
- process.group = "delayed_job"
30
-
31
- process.pid_file = "<%= pid_path %>/delayed_job.<%= name %>.pid"
32
- process.working_dir = "<%= current_path %>"
33
-
34
- <% if range.nil? %>
35
- process.start_command = "<%= delayed_job_script %> start <%= name %>"
36
- process.stop_command = "<%= delayed_job_script %> stop <%= name %>"
37
- <% else %>
38
- process.start_command = "<%= delayed_job_script %> start <%= name %> <%= range.begin %> <%= range.end %>"
39
- process.stop_command = "<%= delayed_job_script %> stop <%= name %> <%= range.begin %> <%= range.end %>"
40
- <% end %>
41
- end
42
- <% end %>
43
- EOF
44
-
45
26
  namespace :delayed_job do
46
27
  desc "Generate DelayedJob configuration files"
47
28
  task :setup, :roles => :worker, :except => { :no_release => true } do
@@ -0,0 +1,11 @@
1
+ [Unit]
2
+ Description=Thin Server
3
+
4
+ [Service]
5
+ Type=forking
6
+ PIDFile=<%= thin_pidfile %>
7
+ ExecStart=<%= thin_script %> start
8
+ ExecStop=/bin/kill -QUIT $MAINPID
9
+
10
+ [Install]
11
+ WantedBy=default.target
@@ -0,0 +1,12 @@
1
+ [Unit]
2
+ Description=Unicorn Server
3
+
4
+ [Service]
5
+ Type=forking
6
+ PIDFile=<%= unicorn_pidfile %>
7
+ ExecStart=<%= unicorn_script %> start
8
+ ExecReload=/bin/kill -HUP $MAINPID
9
+ ExecStop=/bin/kill -QUIT $MAINPID
10
+
11
+ [Install]
12
+ WantedBy=default.target
@@ -31,13 +31,11 @@ kill)
31
31
  ;;
32
32
  reload)
33
33
  sig HUP && echo reloaded OK && exit 0
34
- echo >&2 "Couldn't reload, starting '$CMD' instead"
35
- $CMD
34
+ echo >&2 "Couldn't reload, process dead?" && exit 1
36
35
  ;;
37
36
  upgrade)
38
37
  sig USR2 && exit 0
39
- echo >&2 "Couldn't upgrade, starting '$CMD' instead"
40
- $CMD
38
+ echo >&2 "Couldn't upgrade, process dead?" && exit 1
41
39
  ;;
42
40
  addworker)
43
41
  sig TTIN && echo added one worker to the pool OK && exit 0
@@ -0,0 +1,12 @@
1
+ [Unit]
2
+ Description=UWSGi Server
3
+
4
+ [Service]
5
+ Type=forking
6
+ PIDFile=<%= uwsgi_pidfile %>
7
+ ExecStart=<%= uwsgi_script %> start
8
+ ExecReload=/bin/kill -HUP $MAINPID
9
+ ExecStop=/bin/kill -QUIT $MAINPID
10
+
11
+ [Install]
12
+ WantedBy=default.target
@@ -23,8 +23,7 @@ stop)
23
23
  ;;
24
24
  reload)
25
25
  sig HUP && echo reloaded OK && exit 0
26
- echo >&2 "Couldn't reload, starting '$CMD' instead"
27
- $CMD
26
+ echo >&2 "Couldn't reload, process dead?"
28
27
  ;;
29
28
  *)
30
29
  echo >&2 "Usage: $0 <start|stop|reload>"
data/lib/capper/thin.rb CHANGED
@@ -1,31 +1,14 @@
1
1
  # these cannot be overriden
2
2
  set(:thin_script) { File.join(bin_path, "thin") }
3
+ set(:thin_service) { File.join(bin_path, "thin.service") }
3
4
  set(:thin_pidfile) { File.join(pid_path, "thin.pid") }
4
5
 
5
6
  _cset(:thin_port, 3000)
6
7
 
7
8
  after "deploy:update_code", "thin:setup"
8
9
  after "deploy:restart", "thin:restart"
9
-
10
- monit_config "thin", <<EOF.dedent, :roles => :app
11
- check process thin
12
- with pidfile "<%= thin_pidfile %>"
13
- start program = "<%= thin_script %> start" with timeout 60 seconds
14
- stop program = "<%= thin_script %> stop"
15
- EOF
16
-
17
- bluepill_config "thin", <<EOF, :roles => :app
18
- app.process("thin") do |process|
19
- process.pid_file = "<%= thin_pidfile %>"
20
- process.working_dir = "<%= current_path %>"
21
-
22
- process.start_command = "<%= thin_script %> start"
23
- process.start_grace_time = 60.seconds
24
-
25
- process.stop_signals = [:quit, 5.seconds, :quit, 30.seconds, :term, 5.seconds, :kill]
26
- process.stop_grace_time = 45.seconds
27
- end
28
- EOF
10
+ after "deploy:start", "thin:start"
11
+ after "deploy:stop", "thin:stop"
29
12
 
30
13
  namespace :thin do
31
14
  desc "Generate thin configuration files"
@@ -33,26 +16,25 @@ namespace :thin do
33
16
  upload_template_file("thin.sh",
34
17
  thin_script,
35
18
  :mode => "0755")
19
+ upload_template_file("thin.service",
20
+ thin_service,
21
+ :mode => "0755")
22
+ systemctl "daemon-reload"
23
+ systemctl :enable, :thin
36
24
  end
37
25
 
38
26
  desc "Start thin"
39
27
  task :start, :roles => :app, :except => { :no_release => true } do
40
- run "#{thin_script} start"
28
+ systemctl :start, :thin
41
29
  end
42
30
 
43
31
  desc "Stop thin"
44
32
  task :stop, :roles => :app, :except => { :no_release => true } do
45
- run "#{thin_script} stop"
33
+ systemctl :stop, :thin
46
34
  end
47
35
 
48
36
  desc "Restart thin with zero downtime"
49
37
  task :restart, :roles => :app, :except => { :no_release => true } do
50
- run "#{thin_script} kill"
51
- run "#{thin_script} start"
52
- end
53
-
54
- desc "Kill thin (this should only be used if all else fails)"
55
- task :kill, :roles => :app, :except => { :no_release => true } do
56
- run "#{thin_script} kill"
38
+ systemctl :restart, :thin
57
39
  end
58
40
  end
@@ -4,31 +4,14 @@ _cset(:unicorn_timeout, 30)
4
4
 
5
5
  # these cannot be overriden
6
6
  set(:unicorn_script) { File.join(bin_path, "unicorn") }
7
+ set(:unicorn_service) { File.join(units_path, "unicorn.service") }
7
8
  set(:unicorn_config) { File.join(config_path, "unicorn.rb") }
8
9
  set(:unicorn_pidfile) { File.join(pid_path, "unicorn.pid") }
9
10
 
10
11
  after "deploy:update_code", "unicorn:setup"
11
- after "deploy:restart", "unicorn:restart"
12
-
13
- monit_config "unicorn", <<EOF.dedent, :roles => :app
14
- check process unicorn
15
- with pidfile "<%= unicorn_pidfile %>"
16
- start program = "<%= unicorn_script %> start" with timeout 60 seconds
17
- stop program = "<%= unicorn_script %> stop"
18
- EOF
19
-
20
- bluepill_config "unicorn", <<EOF, :roles => :app
21
- app.process("unicorn") do |process|
22
- process.pid_file = "<%= unicorn_pidfile %>"
23
- process.working_dir = "<%= current_path %>"
24
-
25
- process.start_command = "<%= unicorn_script %> start"
26
- process.start_grace_time = 60.seconds
27
-
28
- process.stop_signals = [:quit, 5.seconds, :quit, 30.seconds, :term, 5.seconds, :kill]
29
- process.stop_grace_time = 45.seconds
30
- end
31
- EOF
12
+ after "deploy:restart", "unicorn:upgrade"
13
+ after "deploy:start", "unicorn:start"
14
+ after "deploy:stop", "unicorn:stop"
32
15
 
33
16
  namespace :unicorn do
34
17
  desc "Generate unicorn configuration files"
@@ -39,20 +22,30 @@ namespace :unicorn do
39
22
  upload_template_file("unicorn.sh",
40
23
  unicorn_script,
41
24
  :mode => "0755")
25
+ upload_template_file("unicorn.service",
26
+ unicorn_service,
27
+ :mode => "0755")
28
+ systemctl "daemon-reload"
29
+ systemctl :enable, :unicorn
42
30
  end
43
31
 
44
32
  desc "Start unicorn"
45
33
  task :start, :roles => :app, :except => { :no_release => true } do
46
- run "#{unicorn_script} start"
34
+ systemctl :start, :unicorn
47
35
  end
48
36
 
49
37
  desc "Stop unicorn"
50
38
  task :stop, :roles => :app, :except => { :no_release => true } do
51
- run "#{unicorn_script} stop"
39
+ systemctl :stop, :unicorn
52
40
  end
53
41
 
54
- desc "Restart unicorn with zero downtime"
42
+ desc "Restart unicorn"
55
43
  task :restart, :roles => :app, :except => { :no_release => true } do
44
+ systemctl :restart, :unicorn
45
+ end
46
+
47
+ desc "Upgrade unicorn with zero downtime"
48
+ task :upgrade, :roles => :app, :except => { :no_release => true } do
56
49
  run "#{unicorn_script} upgrade"
57
50
  end
58
51
 
@@ -0,0 +1,13 @@
1
+ require "erubis"
2
+
3
+ module Capper
4
+ module Utils
5
+ module Systemd
6
+
7
+ def systemctl(*args)
8
+ run("systemctl --user " + [args].flatten.map(&:to_s).join(" "))
9
+ end
10
+
11
+ end
12
+ end
13
+ end
data/lib/capper/uwsgi.rb CHANGED
@@ -3,31 +3,14 @@ _cset(:uwsgi_worker_processes, 4)
3
3
 
4
4
  # these cannot be overriden
5
5
  set(:uwsgi_script) { File.join(bin_path, "uwsgi") }
6
+ set(:uwsgi_service) { File.join(units_path, "uwsgi.service") }
6
7
  set(:uwsgi_config) { File.join(config_path, "uwsgi.xml") }
7
8
  set(:uwsgi_pidfile) { File.join(pid_path, "uwsgi.pid") }
8
9
 
9
10
  after "deploy:update_code", "uwsgi:setup"
10
- after "deploy:restart", "uwsgi:restart"
11
-
12
- monit_config "uwsgi", <<EOF.dedent, :roles => :app
13
- check process uwsgi
14
- with pidfile "<%= uwsgi_pidfile %>"
15
- start program = "<%= uwsgi_script %> start" with timeout 60 seconds
16
- stop program = "<%= uwsgi_script %> stop"
17
- EOF
18
-
19
- bluepill_config "uwsgi", <<EOF, :roles => :app
20
- app.process("uwsgi") do |process|
21
- process.pid_file = "<%= uwsgi_pidfile %>"
22
- process.working_dir = "<%= current_path %>"
23
-
24
- process.start_command = "<%= uwsgi_script %> start"
25
- process.start_grace_time = 60.seconds
26
-
27
- process.stop_signals = [:quit, 5.seconds, :quit, 30.seconds, :term, 5.seconds, :kill]
28
- process.stop_grace_time = 45.seconds
29
- end
30
- EOF
11
+ after "deploy:restart", "uwsgi:reload"
12
+ after "deploy:start", "uwsgi:start"
13
+ after "deploy:stop", "uwsgi:stop"
31
14
 
32
15
  namespace :uwsgi do
33
16
  desc "Generate uwsgi configuration files"
@@ -38,20 +21,30 @@ namespace :uwsgi do
38
21
  upload_template_file("uwsgi.sh",
39
22
  uwsgi_script,
40
23
  :mode => "0755")
24
+ upload_template_file("uwsgi.service",
25
+ uwsgi_service,
26
+ :mode => "0755")
27
+ systemctl "daemon-reload"
28
+ systemctl :enable, :uwsgi
41
29
  end
42
30
 
43
31
  desc "Start uwsgi"
44
32
  task :start, :roles => :app, :except => { :no_release => true } do
45
- run "#{uwsgi_script} start"
33
+ systemctl :start, :uwsgi
46
34
  end
47
35
 
48
36
  desc "Stop uwsgi"
49
37
  task :stop, :roles => :app, :except => { :no_release => true } do
50
- run "#{uwsgi_script} stop"
38
+ systemctl :stop, :uwsgi
51
39
  end
52
40
 
53
41
  desc "Reload uwsgi"
54
42
  task :restart, :roles => :app, :except => { :no_release => true } do
43
+ systemctl :restart, :uwsgi
44
+ end
45
+
46
+ desc "Reload uwsgi"
47
+ task :reload, :roles => :app, :except => { :no_release => true } do
55
48
  run "#{uwsgi_script} reload"
56
49
  end
57
50
  end
@@ -1,3 +1,3 @@
1
1
  module Capper
2
- VERSION = "1.2.4"
2
+ VERSION = "2.0.0.pre1"
3
3
  end
@@ -12,7 +12,7 @@ after "deploy:rollback", "whenever:update_crontab"
12
12
 
13
13
  namespace :whenever do
14
14
  desc "Update application's crontab entries"
15
- task :update_crontab do
15
+ task :update_crontab, :roles => :cron, :on_no_matching_servers => :continue do
16
16
  on_rollback do
17
17
  if previous_release
18
18
  run "cd #{previous_release} && #{whenever_command} #{whenever_update_flags}"
@@ -25,7 +25,7 @@ namespace :whenever do
25
25
  end
26
26
 
27
27
  desc "Remove all entries from application's crontab"
28
- task :clear_crontab do
28
+ task :clear_crontab, :roles => :cron, :on_no_matching_servers => :continue do
29
29
  run "crontab /dev/null"
30
30
  end
31
31
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
5
- prerelease:
4
+ version: 2.0.0.pre1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Benedikt Böhm
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-04 00:00:00.000000000 Z
12
+ date: 2013-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: erubis
@@ -110,12 +110,10 @@ files:
110
110
  - lib/capper.rb
111
111
  - lib/capper/airbrake.rb
112
112
  - lib/capper/base.rb
113
- - lib/capper/bluepill.rb
114
113
  - lib/capper/bundler.rb
115
114
  - lib/capper/delayed_job.rb
116
115
  - lib/capper/django.rb
117
116
  - lib/capper/forever.rb
118
- - lib/capper/monit.rb
119
117
  - lib/capper/multistage.rb
120
118
  - lib/capper/nave.rb
121
119
  - lib/capper/npm.rb
@@ -123,21 +121,22 @@ files:
123
121
  - lib/capper/rails.rb
124
122
  - lib/capper/ruby.rb
125
123
  - lib/capper/rvm.rb
126
- - lib/capper/templates/bluepill.sh.erb
127
124
  - lib/capper/templates/delayed_job.sh.erb
128
125
  - lib/capper/templates/maintenance.html.erb
129
126
  - lib/capper/templates/manage.py.erb
130
127
  - lib/capper/templates/rails.console.sh.erb
128
+ - lib/capper/templates/thin.service.erb
131
129
  - lib/capper/templates/thin.sh.erb
132
130
  - lib/capper/templates/unicorn.rb.erb
131
+ - lib/capper/templates/unicorn.service.erb
133
132
  - lib/capper/templates/unicorn.sh.erb
133
+ - lib/capper/templates/uwsgi.service.erb
134
134
  - lib/capper/templates/uwsgi.sh.erb
135
135
  - lib/capper/templates/uwsgi.xml.erb
136
136
  - lib/capper/thin.rb
137
137
  - lib/capper/unicorn.rb
138
- - lib/capper/utils/bluepill.rb
139
- - lib/capper/utils/monit.rb
140
138
  - lib/capper/utils/multistage.rb
139
+ - lib/capper/utils/systemd.rb
141
140
  - lib/capper/utils/templates.rb
142
141
  - lib/capper/uwsgi.rb
143
142
  - lib/capper/version.rb
@@ -158,9 +157,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
157
  required_rubygems_version: !ruby/object:Gem::Requirement
159
158
  none: false
160
159
  requirements:
161
- - - ! '>='
160
+ - - ! '>'
162
161
  - !ruby/object:Gem::Version
163
- version: '0'
162
+ version: 1.3.1
164
163
  requirements: []
165
164
  rubyforge_project:
166
165
  rubygems_version: 1.8.24
@@ -1,43 +0,0 @@
1
- set(:bluepill_script) { File.join(bin_path, "bluepill") }
2
- set(:bluepillrc) { "#{latest_release}/.bluepillrc" }
3
-
4
- after "deploy:update_code", "bluepill:setup"
5
- before "deploy:restart", "bluepill:start"
6
-
7
- namespace :bluepill do
8
- desc "Setup bluepill config"
9
- task :setup do
10
- servers = find_servers
11
- configs = fetch(:bluepill_configs, {})
12
-
13
- upload_template(bluepillrc, :mode => "0644") do |server|
14
- config = configs.select do |name, config|
15
- roles = config[:options][:roles]
16
- if roles.nil?
17
- true
18
- else
19
- [roles].flatten.select do |r|
20
- self.roles[r.to_sym].include?(server)
21
- end.any?
22
- end
23
- end.map do |name, config|
24
- "# #{name}\n#{config[:body]}"
25
- end.join("\n\n")
26
-
27
- <<-EOS.dedent
28
- Bluepill.application("#{application}", :base_dir => "#{shared_path}") do |app|
29
- #{config}
30
- end
31
- EOS
32
- end
33
-
34
- upload_template_file("bluepill.sh",
35
- bluepill_script,
36
- :mode => "0755")
37
- end
38
-
39
- desc "Load bluepill configuration and start it"
40
- task :start, :roles => :app, :except => { :no_release => true } do
41
- run "cd #{current_path} && #{bluepill_script} load #{bluepillrc}"
42
- end
43
- end
data/lib/capper/monit.rb DELETED
@@ -1,32 +0,0 @@
1
- set(:monitrc) { "#{deploy_to}/.monitrc.local" }
2
-
3
- after "deploy:update_code", "monit:setup"
4
- before "deploy:restart", "monit:reload"
5
-
6
- namespace :monit do
7
- desc "Setup monit configuration files"
8
- task :setup do
9
- configs = fetch(:monit_configs, {})
10
- servers = find_servers
11
-
12
- upload_template(monitrc, :mode => "0644") do |server|
13
- configs.select do |name, config|
14
- roles = config[:options][:roles]
15
- if roles.nil?
16
- true
17
- else
18
- [roles].flatten.select do |r|
19
- self.roles[r.to_sym].include?(server)
20
- end.any?
21
- end
22
- end.map do |name, config|
23
- "# #{name}\n#{config[:body]}"
24
- end.join("\n\n")
25
- end
26
- end
27
-
28
- desc "Reload monit configuration"
29
- task :reload do
30
- run "monit reload &>/dev/null && sleep 1"
31
- end
32
- end
@@ -1,11 +0,0 @@
1
- #!/bin/bash
2
- export HOME=<%= deploy_to %>
3
- export RAILS_ENV=<%= rails_env rescue "production" %>
4
-
5
- if [[ -e "${HOME}"/.rvm/scripts/rvm ]]; then
6
- source "${HOME}"/.rvm/scripts/rvm
7
- fi
8
-
9
- cd <%= current_path %> >/dev/null
10
-
11
- exec <%= ruby_exec_prefix %> bluepill -c <%= shared_path %> "$@"
@@ -1,13 +0,0 @@
1
- module Capper
2
- module Utils
3
- module Bluepill
4
-
5
- def bluepill_config(name, body, options={})
6
- set(:bluepill_configs, fetch(:bluepill_configs, {}).merge(name => {
7
- :options => options, :body => body
8
- }))
9
- end
10
-
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module Capper
2
- module Utils
3
- module Monit
4
-
5
- def monit_config(name, body, options={})
6
- set(:monit_configs, fetch(:monit_configs, {}).merge(name => {
7
- :options => options, :body => body
8
- }))
9
- end
10
-
11
- end
12
- end
13
- end