simple-capistrano-unicorn 0.0.9 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d961de957ac4a70c2b060a66a73bcf7b5e270712
4
- data.tar.gz: 8829e70333ad54057c2674e0f8f7899e01f3ffbc
3
+ metadata.gz: d3cadd75682e8ac7b4b4663531a5a517a11717a8
4
+ data.tar.gz: 125ceba8136b40b6f57c72893cc33acd4e4d4f84
5
5
  SHA512:
6
- metadata.gz: dba1c5196f5223a44bc425436ad39772b28847880aca4363ac590663d8c24986b0b05116b8568d7875632af4827033dd8afc512980c73fbb17d471e84ba90fc1
7
- data.tar.gz: be5934e5b45013c3151788625f1fef53bf34cfeeda8193410d092b6ba4fe73478fd78b02d65415cca2f9685ada051de086bc0e45e55a45e57cc4070addfb3cac
6
+ metadata.gz: 8a81c15963662013f632c2ebd6ea0964fd935656f79e9135e70e6f1054b923140cbe2d91c6ab789c7e6900c95101295c6eadf416b692d1c479fa230969778b49
7
+ data.tar.gz: 5b39f16bc8086ec4f338f0c38f68f7d868153e0c929c58f96d62959e18d80fac7b0ca8dd399142918b858f3d4db2bd746b1e3f16250e62c9d4d5983a5c377c67
data/CHANGELOG.md CHANGED
@@ -1,3 +1,5 @@
1
+ ## v 1.0.0: Rewrite to Capistrano v3
2
+
1
3
  ## v 0.0.9: Lock gem dependencies to use Capistrano v2 until we can rewrite to Capistrano v3.
2
4
 
3
5
  ## v 0.0.6: Added a debug-task to see which variables this gem sees
data/README.md CHANGED
@@ -14,7 +14,7 @@ gem 'simple-capistrano-unicorn'
14
14
 
15
15
  ### 2. Require this gem in deploy.rb
16
16
 
17
- You should add this line in the bottom of `RAILS_ROOT/config/deploy.rb`:
17
+ You should add this line to your `Capfile`:
18
18
 
19
19
  ```ruby
20
20
  require 'simple-capistrano-unicorn'
@@ -22,70 +22,28 @@ require 'simple-capistrano-unicorn'
22
22
 
23
23
  ### 3. Restart Unicorn on deploy
24
24
 
25
- You should place this line in `RAILS_ROOT/config/deploy.rb`:
25
+ You should place this line in `PROJECT_ROOT/config/deploy.rb`:
26
26
 
27
27
  ```ruby
28
- after :deploy, "unicorn:restart"
28
+ after 'deploy', 'unicorn:restart'
29
29
  ```
30
30
 
31
- ### 4. Add unicorn.rb (only for single-stage setup)
31
+ ### 4. Add your `unicorn.rb`
32
32
 
33
33
  Grab the sample Unicorn configuration here: https://github.com/kaspergrubbe/simple-capistrano-unicorn/blob/master/configs/unicorn.conf.rb
34
34
 
35
- And place it here: `RAILS_ROOT/config/unicorn.rb` change the `app_root` variable if you deploy user isn't named `deployer`.
36
-
37
- #### 4.1 Should my Unicorn suicide or not?
38
-
39
- My prefered way of killing off Unicorns is to let Unicorn kill it old master after forking, this means that workers is up when you kill off the old master. If you use the sample unicorn config described here, Unicorn is doing exactly this. You can see it by this:
40
-
41
- ```ruby
42
- after_fork do |server, worker|
43
- # (...)
44
-
45
- # Kill off the new master after forking
46
- old_pid = "#{app_dir}/shared/pids/unicorn.pid.oldbin"
47
- if File.exists?(old_pid) && server.pid != old_pid
48
- begin
49
- Process.kill("QUIT", File.read(old_pid).to_i)
50
- rescue Errno::ENOENT, Errno::ESRCH
51
- # someone else did our job for us
52
- end
53
- end
54
- end
55
- ```
56
-
57
- If you want Unicorn to suicide, set this variable in your `deploy.rb`-file:
58
-
59
- ```ruby
60
- set(:unicorn_suicide) { true }
61
- ```
62
-
63
- ### 5. Add unicorn stage files (only for multi-stage setup)
64
-
65
- Make sure that you are using the multi-stage extension for Capistrano ( https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension )
66
-
67
- You can get a sample of the Unicorn configuration here: http://unicorn.bogomips.org/examples/unicorn.conf.rb
68
-
69
- You should create different Unicorn files to use for each of your different environments. The most common setup is to place the Unicorn configuration files in `RAILS_ROOT/config/unicorn/{staging|beta|production}.rb`.
70
-
71
- You can then override the `unicorn_config`-variable that this gem is listening for, by placing this in `RAILS_ROOT/config/deploy.rb`:
72
-
73
- ```ruby
74
- set(:unicorn_config) { "#{fetch(:current_path)}/config/unicorn/#{fetch(:stage)}.rb" }
75
- ```
35
+ And place it here: `PROJECT_ROOT/config/unicorn.rb` change the `app_root` variable if you deploy user isn't named `deployer`.
76
36
 
77
37
  ## Usage
78
38
 
79
- Go through the setup and run: `cap deploy` or `cap production deploy` (for multistage)
39
+ Go through the setup and run: `cap production deploy`
80
40
 
81
- The gem gives you access to the following methods within the `unicorn.<method>` namespace.
41
+ The gem gives you access to the following tasks:
82
42
 
83
- * `unicorn.start` starts the Unicorn processes
84
- * `unicorn.stop` stops the Unicorn processes
43
+ * `unicorn:start` starts the Unicorn processes
44
+ * `unicorn:stop` stops the Unicorn processes
85
45
  * `unicorn.restart` makes a seamless zero-downtime restart
86
- * `unicorn.hard_restart` basically runs `unicorn.stop` followed with a `unicorn.start`
87
- * `unicorn.log` prints out from the Unicorn log in `tail -f`-like fashion
88
- * `unicorn.cleanup` removes the old running Unicorn master
46
+ * `unicorn.hard_restart` basically runs `unicorn:stop` followed with a `unicorn:start`
89
47
 
90
48
  ## Requirements
91
49
 
@@ -97,10 +55,7 @@ The gem gives you access to the following methods within the `unicorn.<method>`
97
55
  You can customize the gems behavior by setting any (or all) of the following options within capistrano's configuration:
98
56
 
99
57
  * `unicorn_pid` indicates the path for the pid file. Defaults to `"#{shared_path}/pids/unicorn.pid"`.
100
- * `unicorn_suicide` indicates whether Unicorn kills it own master after forking or not. Defaults to `false`.
101
58
  * `unicorn_old_pid` indicates the path for the old pid file, which Unicorn creates when forking a new master. Defaults to `#{shared_path}/pids/unicorn.pid.oldbin`.
102
59
  * `unicorn_config` the path to the unicorn config file. Defaults to `"#{current_path}/config/unicorn.rb"`.
103
60
  * `unicorn_log` the path where unicorn places its STDERR-log. Defaults to `"#{shared_path}/log/unicorn.stderr.log"`.
104
- * `use_bundler` defines whether Unicorn should start with `bundle exec` or not. Default to `true`.
105
- * `rails_env` sets the environment that the server will run in. Defaults to `"production"`.
106
- * `unicorn_command` lets you specify the Unicorn command if you want to use `unicorn_rails`. Defaults to `"unicorn"`.
61
+ * `rack_env` sets the environment that the server will run in. Defaults to `"production"`.
data/configs/deploy.rb CHANGED
@@ -1,60 +1,28 @@
1
- set :application, "testapp"
2
- set :repository, "git@github.com:kaspergrubbe/testapp.git"
3
- set :branch, "master"
4
- set :scm, :git
5
-
6
- # Server settings
7
- set :user, "deployer"
8
- #set :ssh_options, { :forward_agent => true }
9
- set :use_sudo, false
10
- set :use_bundler, true
11
- set :deploy_to, "/home/#{user}/apps/#{application}"
12
-
13
- # Unicorn options
14
- set :unicorn_suicide, true
15
-
16
- role :web, "176.58.122.173" # Your HTTP server, Apache/etc
17
- role :app, "176.58.122.173" # This may be the same as your `Web` server
18
- role :db, "176.58.122.173", :primary => true # This is where Rails migrations will run
19
- role :db, "176.58.122.173"
20
-
21
- # if you want to clean up old releases on each deploy uncomment this:
22
- after "deploy:restart", "deploy:cleanup"
23
-
24
- # Restart unicorn after deploy
25
- after :deploy, "unicorn:restart"
26
-
27
- # The deploy strategies are:
28
- # checkout (default) - This makes the servers do a git clone to update code
29
- # export - This makes a git export instead of checkout (But what really happens is a checkout
30
- # followed by a deletion of the .git-dirs, use checkout instead)
31
- # remote_cache - This keeps a remote git repo on the servers, when deploying it does a git pull
32
- # and copies the files to the release path.
33
- # copy - This strategy checks out the branch to your local machine, compresses it, and copies
34
- # the code to each server and uncompress it. This is smart when Github is failing.
35
- # But if you live in Belgium and need to upload it to the danish servers, you might
36
- # not want to use it.
37
- #
38
- # source: https://github.com/capistrano/capistrano/tree/master/lib/capistrano/recipes/deploy/strategy
39
- # https://help.github.com/articles/deploying-with-capistrano
40
- set :deploy_via, :copy
41
-
42
- # rbenv
43
- set :default_environment, {
44
- "PATH" => "/home/#{user}/.rbenv/shims:/home/#{user}/.rbenv/bin:$PATH",
45
- }
1
+ # config valid only for current version of Capistrano
2
+ lock '3.4.0'
3
+
4
+ set :application, "application"
5
+ set :repo_url, "git@github.com:kaspergrubbe/application.git"
6
+ set :deploy_to, "/home/deploy/apps/#{fetch(:application)}"
7
+
8
+ set :user, "deploy"
9
+ set :use_sudo, false
10
+
11
+ # Default branch is :master
12
+ # ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
46
13
 
47
- # if you're still using the script/reaper helper you will need
48
- # these http://github.com/rails/irs_process_scripts
14
+ # Default value for :linked_files is []
15
+ # set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
16
+
17
+ # Default value for linked_dirs is []
18
+ set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
19
+
20
+ # Default value for default_env is {}
21
+ set :default_env, {
22
+ PATH: "/home/#{fetch(:user)}/.rbenv/shims:/home/#{fetch(:user)}/.rbenv/bin:$PATH"
23
+ }
49
24
 
50
- # If you are using Passenger mod_rails uncomment this:
51
- # namespace :deploy do
52
- # task :start do ; end
53
- # task :stop do ; end
54
- # task :restart, :roles => :app, :except => { :no_release => true } do
55
- # run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
56
- # end
57
- # end
25
+ # Default value for keep_releases is 5
26
+ set :keep_releases, 5
58
27
 
59
- require "bundler/capistrano"
60
- require 'simple-capistrano-unicorn'
28
+ after 'deploy', 'unicorn:restart'
@@ -59,6 +59,12 @@ GC.respond_to?(:copy_on_write_friendly=) and
59
59
  # fast LAN.
60
60
  check_client_connection false
61
61
 
62
+ # Forcibly clean environment variables between bundlings
63
+ # http://www.mail-archive.com/mongrel-unicorn@rubyforge.org/msg00276.html
64
+ before_exec do |server|
65
+ ENV["BUNDLE_GEMFILE"] = "#{app_dir}/current/Gemfile"
66
+ end
67
+
62
68
  before_fork do |server, worker|
63
69
  # the following is highly recomended for Rails + "preload_app true"
64
70
  # as there's no need for the master process to hold a connection
@@ -105,14 +111,13 @@ after_fork do |server, worker|
105
111
  # between any number of forked children (assuming your kernel
106
112
  # correctly implements pread()/pwrite() system calls)
107
113
 
108
-
109
114
  # Kill off the new master after forking
110
- old_pid = "#{app_dir}/shared/pids/unicorn.pid.oldbin"
111
- if File.exists?(old_pid) && server.pid != old_pid
112
- begin
113
- Process.kill("QUIT", File.read(old_pid).to_i)
114
- rescue Errno::ENOENT, Errno::ESRCH
115
- # someone else did our job for us
116
- end
117
- end
118
- end
115
+ # old_pid = "#{app_dir}/shared/pids/unicorn.pid.oldbin"
116
+ # if File.exists?(old_pid) && server.pid != old_pid
117
+ # begin
118
+ # Process.kill("QUIT", File.read(old_pid).to_i)
119
+ # rescue Errno::ENOENT, Errno::ESRCH
120
+ # # someone else did our job for us
121
+ # end
122
+ # end
123
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path('../tasks/unicorn.cap', __FILE__)
@@ -0,0 +1,123 @@
1
+ namespace :unicorn do
2
+
3
+ def process_running?(pidfile)
4
+ cmd = "if [ -e #{pidfile} ]; then ps cax | grep `cat #{pidfile}` > /dev/null; if [ $? -eq 0 ]; then echo -n running; fi; fi"
5
+ 'running' == capture(cmd)
6
+ end
7
+
8
+ def unicorn_is_running?(pidfile)
9
+ process_running?(pidfile)
10
+ end
11
+
12
+ def start_unicorn
13
+ within release_path do
14
+ execute *%W[bundle exec unicorn -c #{unicorn_config} -E #{rack_env} -D]
15
+ end
16
+ end
17
+
18
+ def update_progress(msg)
19
+ logger = SSHKit.config.output
20
+ logger << SSHKit::LogMessage.new(Logger::INFO, "Unicorn | #{msg}")
21
+ end
22
+
23
+ # Starts the unicorn process(es)
24
+ #
25
+ desc "Starts unicorn"
26
+ task :start do
27
+ on roles(:app) do |server|
28
+ if unicorn_is_running?(unicorn_pid)
29
+ update_progress("Unicorn already running on #{server.hostname}")
30
+ else
31
+ # Unicorn is not running, remove the pid-file if it exists
32
+ execute("if [ -e #{unicorn_pid} ]; then rm #{unicorn_pid}; fi")
33
+ start_unicorn
34
+ update_progress("Started Unicorn!")
35
+ end
36
+ end
37
+ end
38
+
39
+ # This will quit the unicorn process(es).
40
+ #
41
+ desc "Stop unicorn"
42
+ task :stop do
43
+ on roles(:app) do |server|
44
+ if unicorn_is_running?(unicorn_pid)
45
+ execute "if [ -e #{unicorn_pid} ]; then kill -s QUIT `cat #{unicorn_pid}`; fi"
46
+ update_progress "Stopped Unicorn on #{server.hostname}!"
47
+ else
48
+ update_progress "Unicorn _not_ running, nothing to stop!"
49
+ end
50
+ end
51
+ end
52
+
53
+ # Restarts the unicorn process(es) with the USR2 signal, to gracefully
54
+ # create a new server, and kill of the old one, leaving *no* downtime.
55
+ #
56
+ # It's following the: http://unicorn.bogomips.org/SIGNALS.html
57
+ #
58
+ desc "Zero-downtime restart of Unicorn"
59
+ task :restart do
60
+ # 1. MAKES SURE ALL SERVERS ARE RUNNING!
61
+ update_progress "Making sure all servers are running Unicorn"
62
+ on roles(:app) do |server|
63
+ unless unicorn_is_running?(unicorn_pid)
64
+ start_unicorn
65
+ end
66
+ end
67
+
68
+ # 2. MAKE ALL SERVERS RELOAD THE NEW CODE!
69
+ update_progress "Reloading new code (USR2)"
70
+ sleep(10)
71
+ on roles(:app) do |server|
72
+ pid = capture("cat #{unicorn_pid}").to_i
73
+ execute "kill -s USR2 #{pid}"
74
+ end
75
+
76
+ # 3. MAKE ALL SERVERS STOP SENDING TRAFFIC TO OLD MASTER
77
+ update_progress "Killing workers started from old masters (WINCH)"
78
+ sleep(10)
79
+ on roles(:app) do |server|
80
+ old_pid = capture("cat #{unicorn_old_pid}").to_i
81
+ execute "kill -s WINCH #{old_pid}"
82
+ end
83
+
84
+ # 3.1 ALL TRAFFIC GOES TO NEW SERVERS, KILL OLD
85
+ update_progress "All traffic is now handled by new master, now smile!"
86
+
87
+ # 4. NOW ALL OLD WORKERS ARE DOwN! KILL OLD MASTER!
88
+ update_progress "Killing old masters (QUIT)"
89
+ sleep(10)
90
+ on roles(:app) do |server|
91
+ old_pid = capture("cat #{unicorn_old_pid}").to_i
92
+ execute "kill -s QUIT #{old_pid}"
93
+ end
94
+ update_progress ".. code deployed!\n"
95
+ end
96
+
97
+ desc "Restart of Unicorn with downtime"
98
+ task :hard_restart do
99
+ invoke 'unicorn:stop'
100
+ sleep(1)
101
+ invoke 'unicorn:start'
102
+ end
103
+
104
+ def unicorn_pid
105
+ fetch(:unicorn_pid, "#{shared_path}/tmp/pids/unicorn.pid")
106
+ end
107
+
108
+ def unicorn_old_pid
109
+ fetch(:unicorn_old_pid, "#{shared_path}/tmp/pids/unicorn.pid.oldbin")
110
+ end
111
+
112
+ def unicorn_config
113
+ fetch(:unicorn_config, "#{current_path}/config/unicorn.rb")
114
+ end
115
+
116
+ def unicorn_log
117
+ fetch(:unicorn_log, "#{shared_path}/log/unicorn.stderr.log")
118
+ end
119
+
120
+ def rack_env
121
+ fetch(:rack_env, 'production')
122
+ end
123
+ end
@@ -1,2 +0,0 @@
1
- require "simple-capistrano-unicorn/version"
2
- require "simple-capistrano-unicorn/namespace"
@@ -1,10 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "simple-capistrano-unicorn/version"
4
3
 
5
4
  Gem::Specification.new do |gem|
6
5
  gem.name = "simple-capistrano-unicorn"
7
- gem.version = Capistrano::Unicorn::Methods::VERSION
6
+ gem.version = '1.0.1'
8
7
  gem.authors = ["Kasper Grubbe"]
9
8
  gem.email = ["kaspergrubbe@gmail.com"]
10
9
  gem.homepage = "http://github.com/kaspergrubbe/simple-capistrano-unicorn"
@@ -18,8 +17,6 @@ Gem::Specification.new do |gem|
18
17
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
18
  gem.require_paths = ["lib"]
20
19
 
21
- gem.add_development_dependency "rake"
22
-
23
- gem.add_runtime_dependency "unicorn"
24
- gem.add_runtime_dependency 'capistrano', '~> 2.15'
20
+ gem.add_runtime_dependency "unicorn", '~> 5.0'
21
+ gem.add_runtime_dependency 'capistrano', '~> 3.4'
25
22
  end
metadata CHANGED
@@ -1,57 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-capistrano-unicorn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Grubbe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-08 00:00:00.000000000 Z
11
+ date: 2016-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: unicorn
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - ">="
17
+ - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: '0'
19
+ version: '5.0'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - ">="
24
+ - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '5.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: capistrano
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '2.15'
33
+ version: '3.4'
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '2.15'
40
+ version: '3.4'
55
41
  description: Contains a collection of simple tasks to manage Unicorn with Capistrano.
56
42
  email:
57
43
  - kaspergrubbe@gmail.com
@@ -67,9 +53,9 @@ files:
67
53
  - Rakefile
68
54
  - configs/deploy.rb
69
55
  - configs/unicorn.conf.rb
56
+ - lib/capistrano/simple-capistrano-unicorn.rb
57
+ - lib/capistrano/tasks/unicorn.cap
70
58
  - lib/simple-capistrano-unicorn.rb
71
- - lib/simple-capistrano-unicorn/namespace.rb
72
- - lib/simple-capistrano-unicorn/version.rb
73
59
  - simple-capistrano-unicorn.gemspec
74
60
  homepage: http://github.com/kaspergrubbe/simple-capistrano-unicorn
75
61
  licenses: []
@@ -1,151 +0,0 @@
1
- require 'capistrano'
2
- require 'capistrano/version'
3
-
4
- module SimpleCapistranoUnicorn
5
- class CapistranoIntegration
6
- def self.load_into(capistrano_config)
7
- capistrano_config.load do
8
- # Defaulting these variables, because they could end up not being defined in deploy.rb.
9
- _cset(:unicorn_pid) { "#{shared_path}/pids/unicorn.pid" }
10
- _cset(:unicorn_old_pid) { "#{shared_path}/pids/unicorn.pid.oldbin" }
11
- _cset(:unicorn_config) { "#{current_path}/config/unicorn.rb" }
12
- _cset(:unicorn_log) { "#{shared_path}/log/unicorn.stderr.log" }
13
- _cset(:unicorn_suicide) { false }
14
- _cset(:use_bundler) { true }
15
- _cset(:rails_env) { "production" }
16
- _cset(:unicorn_command) { "unicorn" }
17
-
18
- def process_running?(server, pidfile)
19
- cmd = "if [ -e #{pidfile} ]; then ps cax | grep `cat #{pidfile}` > /dev/null; if [ $? -eq 0 ]; then echo -n running; fi; fi"
20
- 'running' == capture(cmd, :hosts => [server])
21
- end
22
-
23
- # Command to check if Unicorn is running.
24
- #
25
- def unicorn_is_running?(server)
26
- process_running?(server, unicorn_pid)
27
- end
28
-
29
- # Command to check if old Unicorn is running.
30
- #
31
- def old_unicorn_is_running?(server)
32
- process_running?(server, unicorn_old_pid)
33
- end
34
-
35
- def nice_output(output, server = nil)
36
- "#{server.to_s.ljust(20) if server} #{output}"
37
- end
38
-
39
- def start_unicorn(server)
40
- run "cd #{current_path}; #{'bundle exec' if use_bundler} #{unicorn_command} -c #{unicorn_config} -E #{rails_env} -D", :hosts => [server]
41
- end
42
-
43
- def clean_old_unicorn(server)
44
- if old_unicorn_is_running?(server)
45
- run "if [ -e #{unicorn_old_pid} ]; then kill -s QUIT `cat #{unicorn_old_pid}`; fi", :hosts => [server]
46
- run "if [ -e #{unicorn_old_pid} ]; then rm #{unicorn_old_pid}; fi", :hosts => [server]
47
- logger.info nice_output("Cleaned up old Unicorn", server)
48
- end
49
- end
50
-
51
- namespace :unicorn do
52
- # Starts the unicorn process(es)
53
- #
54
- desc "Starts unicorn"
55
- task :start, :roles => :app do
56
- find_servers(:roles => :app).each do |server|
57
- clean_old_unicorn(server)
58
-
59
- if unicorn_is_running?(server)
60
- logger.info("Unicorn already running on #{server}")
61
- else
62
- # Unicorn is not running, remove the pid-file if it exists
63
- run "if [ -e #{unicorn_pid} ]; then rm #{unicorn_pid}; fi", :hosts => [server]
64
- start_unicorn(server)
65
- logger.info nice_output("Started Unicorn!", server)
66
- end
67
- end
68
- end
69
-
70
- # This will quit the unicorn process(es).
71
- #
72
- desc "Stop unicorn"
73
- task :stop, :roles => :app do
74
- find_servers(:roles => :app).each do |server|
75
- if unicorn_is_running?(server)
76
- run "if [ -e #{unicorn_pid} ]; then kill -s QUIT `cat #{unicorn_pid}`; fi", :hosts => [server]
77
- run "if [ -e #{unicorn_pid} ]; then rm #{unicorn_pid}; fi", :hosts => [server]
78
- logger.info nice_output("Stopped Unicorn!", server)
79
- else
80
- logger.info nice_output("Unicorn _not_ running, nothing to stop!", server)
81
- end
82
- end
83
- end
84
-
85
- # Restarts the unicorn process(es) with the USR2 code, to gracefully
86
- # create a new server, and kill of the old one, leaving *no* downtime.
87
- #
88
- desc "Zero-downtime restart of Unicorn"
89
- task :restart do
90
- find_servers(:roles => :app).each do |server|
91
- if unicorn_is_running?(server)
92
- pid = capture "cat #{unicorn_pid}", :hosts => [server]
93
- run "kill -s USR2 #{pid.to_i}", :hosts => [server] if pid.to_i > 0
94
- logger.info nice_output("Restarted Unicorn!", server)
95
- else
96
- logger.info nice_output("Unicorn wasn't running, starting it!", server)
97
- start_unicorn(server)
98
- logger.info nice_output("Started Unicorn!", server)
99
- end
100
- end
101
- # Only clean-up if unicorn don't kill its old master
102
- unicorn.cleanup unless unicorn_suicide
103
- end
104
-
105
- desc "Restart of Unicorn with downtime"
106
- task :hard_restart do
107
- unicorn.stop
108
- sleep(1)
109
- unicorn.start
110
- end
111
-
112
- # Displays the unicorn log.
113
- #
114
- desc "Displays the unicorn log"
115
- task :log, :roles => :app do
116
- run "tail -f #{shared_path}/log/unicorn.stderr.log" do |channel,stream,data|
117
- logger.info nice_output(data, channel[:host])
118
- end
119
- end
120
-
121
- # This will clean up any old unicorn servers left behind by the USR2 kill
122
- # command.
123
- #
124
- desc "Cleans up the old unicorn processes"
125
- task :cleanup, :roles => :app do
126
- logger.info "Cleaning up old Unicorns.."
127
- find_servers(:roles => :app).each do |server|
128
- clean_old_unicorn(server)
129
- end
130
- end
131
-
132
- desc "Prints out variables that this gem listens for"
133
- task :debug do
134
- logger.info "unicorn_pid:\t#{fetch(:unicorn_pid)}"
135
- logger.info "unicorn_old_pid:\t#{fetch(:unicorn_old_pid)}"
136
- logger.info "unicorn_config:\t#{fetch(:unicorn_config)}"
137
- logger.info "unicorn_suicide:\t#{fetch(:unicorn_suicide)}"
138
- logger.info "unicorn_log:\t#{fetch(:unicorn_log)}"
139
- logger.info "use_bundler:\t#{fetch(:use_bundler)}"
140
- logger.info "rails_env: \t#{fetch(:rails_env)}"
141
- logger.info "unicorn_command:\t#{fetch(:unicorn_command)}"
142
- end
143
- end
144
- end
145
- end
146
- end
147
- end
148
-
149
- if Capistrano::Configuration.instance
150
- SimpleCapistranoUnicorn::CapistranoIntegration.load_into(Capistrano::Configuration.instance)
151
- end
@@ -1,7 +0,0 @@
1
- module Capistrano
2
- module Unicorn
3
- module Methods
4
- VERSION = "0.0.9"
5
- end
6
- end
7
- end