capistrano3-unicorn 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f84ba3c17bf1822dc5df22d3e72df5d5b82abbdc
4
- data.tar.gz: 33cb944e9facfb6596d3047a83ec2cd08754fb19
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NmNiYWFhN2NkM2ZhZTI0MzMyNGFkM2RmMzQxODc4MjNmM2Y5N2VhYQ==
5
+ data.tar.gz: !binary |-
6
+ YTMyMWNjM2I2YjIxN2Q2ODRmYzg4ZTZkOTk1NzZiNjg5NjUwNjUyYQ==
5
7
  SHA512:
6
- metadata.gz: 1c59388ca7b771f37a9b6a4d7c296f0d17de5474007258709b9652f69c3e4c9b9d8e09702570c20eb28af5910a64319490cda821e90292762fade656644db551
7
- data.tar.gz: 8ba5dc92bdc7eeb4253c6564098335ab431e85821799aff734ec73682a7322a6b9ff6b9fea14b0287bdee9a7640345379b58ace51d638f01642f97d2cf32f2dc
8
+ metadata.gz: !binary |-
9
+ NzkzYzI2ODJkYTMyYTcxYjg5ZTE5ODRlNDQ5MzZiMmQzYzRjMDFjNGE5MGMy
10
+ ZmQ3ZDlkNmM3NGRkYThhZmM5MzU0NjcxYTViNWUyZWNlMTA2YTJjZTU3ODQ3
11
+ NzA1OTc2YTFiZjVhNDdmMjk2ZWQ2NmU3ODE0YjhkMDk5YWYzMzk=
12
+ data.tar.gz: !binary |-
13
+ MmQ5OTRhOTBjMjViMjNiZGI4NjJiNzIzODgxMzZiOWRkMzdkZTA5Y2NmNDZi
14
+ ZWZmMDQxZWM1ZjU2Y2NhNTUzODc3MWI2MWE1ODMxMjBjYjRkZjZkMTBkYzhj
15
+ Yzg4YzViMWY2ZWI2MGE1ZDhlNzZiMThkMmFiNWMwNzVmNTk3Nzk=
@@ -0,0 +1,4 @@
1
+ Gemfile.lock
2
+ .ruby-version
3
+ .ruby-gemset
4
+ pkg/
@@ -1,5 +1,19 @@
1
1
  # Capistrano3 Unicorn Changelog
2
2
 
3
+ ## `0.2.1`
4
+
5
+ - Revert `:unicorn_config_path` falling back to `config/unicorn/unicorn.rb` due to flawed implementation
6
+
7
+ ## `0.2.0`
8
+
9
+ - `unicorn:restart` no longer sends QUIT to oldbin since most people use a callback in `unicorn.rb`
10
+ - `unicorn:legacy_restart` preserves the QUIT to oldbin
11
+ - `:unicorn_config_path` adds `config/unicorn/unicorn.rb` as a default path
12
+ - added example unicorn.rb
13
+ - removed `:unicorn_bundle_gemfile`, this should have been in a before_exec in the unicorn configuration
14
+
15
+ Thanks to @spectator, @lxxdn, @ahorner, and @soulcutter
16
+
3
17
  ## `0.1.1`
4
18
 
5
19
  - Removed default value for `:unicorn_bundle_gemfile` of `:bundle_gemfile` so that current_path is the default
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md CHANGED
@@ -12,21 +12,17 @@ This is a capistrano v3 plugin that integrates Unicorn tasks into capistrano dep
12
12
 
13
13
  ### Conventions
14
14
 
15
- You can override the defaults by `set :unicorn_example, value` in the `config/deploy.rb` or `config/deploy/ENVIRONMENT.rb` capistrano deployment files
15
+ You can override the defaults by `set :unicorn_example, value` in the `config/deploy.rb` or `config/deploy/ENVIRONMENT.rb` capistrano deployment files.
16
16
 
17
- - `:unicorn_pid`
17
+ Example Unicorn config [examples/unicorn.rb](https://github.com/tablexi/capistrano3-unicorn/blob/master/examples/unicorn.rb)
18
18
 
19
- Assumes your pid file will be located in `tmp/pids/unicorn.pid` which is symlinked by `:linked_dirs` to survive across deployments
19
+ - `:unicorn_pid`
20
20
 
21
- *NOTE: THIS PATH WAS CHANGED AS OF v0.1.0*
21
+ Default assumes your pid file will be located in `CURRENT_PATH/tmp/pids/unicorn.pid`. The unicorn_pid should be defined with an absolute path.
22
22
 
23
23
  - `:unicorn_config_path`
24
24
 
25
- Assumes that your Unicorn configuration will be located in `config/unicorn/RAILS_ENV.rb`
26
-
27
- - `:unicorn_restart_sleep_time`
28
-
29
- When performing zero-downtime deployment via the `unicorn:restart` task, send the USR2 signal, sleep for this many seconds (defaults to 3), then send the QUIT signal
25
+ Default assumes that your Unicorn configuration will be located in `CURRENT_PATH/config/unicorn/RAILS_ENV.rb`
30
26
 
31
27
  - `:unicorn_roles`
32
28
 
@@ -42,7 +38,13 @@ You can override the defaults by `set :unicorn_example, value` in the `config/de
42
38
 
43
39
  - `:unicorn_bundle_gemfile`
44
40
 
45
- Sets the BUNDLE_GEMFILE so that unicorn will point at the new Gemfile after unicorn:restart. Defaults to `current/Gemfile`.
41
+ ***REMOVED in v0.2.0***
42
+
43
+ Set the BUNDLE_GEMFILE in a before_exec block in your unicorn.rb. See [sandbox](http://unicorn.bogomips.org/Sandbox.html) and [unicorn-restart-issue-with-capistrano](https://stackoverflow.com/questions/8330577/unicorn-restart-issue-with-capistrano)
44
+
45
+ - `:unicorn_restart_sleep_time`
46
+
47
+ In `unicorn:legacy_restart` send the USR2 signal, sleep for this many seconds (defaults to 3), then send the QUIT signal
46
48
 
47
49
  ### Setup
48
50
 
@@ -73,6 +75,17 @@ namespace :deploy do
73
75
  end
74
76
  ```
75
77
 
78
+ If `preload_app:true` and you need capistrano to cleanup your oldbin pid use:
79
+
80
+ ```ruby
81
+ after 'deploy:publishing', 'deploy:restart'
82
+ namespace :deploy do
83
+ task :restart do
84
+ invoke 'unicorn:legacy_restart'
85
+ end
86
+ end
87
+ ```
88
+
76
89
  Otherwise use:
77
90
 
78
91
  ```ruby
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = "capistrano3-unicorn"
6
- gem.version = '0.1.1'
6
+ gem.version = '0.2.1'
7
7
  gem.authors = ["Matthew Lineen"]
8
8
  gem.email = ["matthew@lineen.com"]
9
9
  gem.description = "Unicorn specific Capistrano tasks"
@@ -15,5 +15,5 @@ Gem::Specification.new do |gem|
15
15
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
16
  gem.require_paths = ["lib"]
17
17
 
18
- gem.add_dependency 'capistrano', '>= 3.1.0'
18
+ gem.add_runtime_dependency 'capistrano', '~> 3.1', '>= 3.1.0'
19
19
  end
@@ -0,0 +1,47 @@
1
+ # paths
2
+ app_path = "/home/example/www.example.com"
3
+ working_directory "#{app_path}/current"
4
+ pid "#{app_path}/current/tmp/pids/unicorn.pid"
5
+
6
+ # listen
7
+ listen "/tmp/unicorn-www.example.com.socket", :backlog => 64
8
+
9
+ # logging
10
+ stderr_path "log/unicorn.stderr.log"
11
+ stdout_path "log/unicorn.stdout.log"
12
+
13
+ # workers
14
+ worker_processes 3
15
+
16
+ # use correct Gemfile on restarts
17
+ before_exec do |server|
18
+ ENV['BUNDLE_GEMFILE'] = "#{app_path}/current/Gemfile"
19
+ end
20
+
21
+ # preload
22
+ preload_app true
23
+
24
+ before_fork do |server, worker|
25
+ # the following is highly recomended for Rails + "preload_app true"
26
+ # as there's no need for the master process to hold a connection
27
+ if defined?(ActiveRecord::Base)
28
+ ActiveRecord::Base.connection.disconnect!
29
+ end
30
+
31
+ # Before forking, kill the master process that belongs to the .oldbin PID.
32
+ # This enables 0 downtime deploys.
33
+ old_pid = "#{server.config[:pid]}.oldbin"
34
+ if File.exists?(old_pid) && server.pid != old_pid
35
+ begin
36
+ Process.kill("QUIT", File.read(old_pid).to_i)
37
+ rescue Errno::ENOENT, Errno::ESRCH
38
+ # someone else did our job for us
39
+ end
40
+ end
41
+ end
42
+
43
+ after_fork do |server, worker|
44
+ if defined?(ActiveRecord::Base)
45
+ ActiveRecord::Base.establish_connection
46
+ end
47
+ end
@@ -2,11 +2,10 @@ namespace :load do
2
2
  task :defaults do
3
3
  set :unicorn_pid, -> { File.join(current_path, "tmp", "pids", "unicorn.pid") }
4
4
  set :unicorn_config_path, -> { File.join(current_path, "config", "unicorn", "#{fetch(:rails_env)}.rb") }
5
- set :unicorn_restart_sleep_time, 3
6
5
  set :unicorn_roles, -> { :app }
7
6
  set :unicorn_options, -> { "" }
8
7
  set :unicorn_rack_env, -> { fetch(:rails_env) == "development" ? "development" : "deployment" }
9
- set :unicorn_bundle_gemfile, -> { File.join(current_path, "Gemfile") }
8
+ set :unicorn_restart_sleep_time, 3
10
9
  end
11
10
  end
12
11
 
@@ -18,7 +17,7 @@ namespace :unicorn do
18
17
  if test("[ -e #{fetch(:unicorn_pid)} ] && kill -0 #{pid}")
19
18
  info "unicorn is running..."
20
19
  else
21
- with rails_env: fetch(:rails_env), bundle_gemfile: fetch(:unicorn_bundle_gemfile) do
20
+ with rails_env: fetch(:rails_env) do
22
21
  execute :bundle, "exec unicorn", "-c", fetch(:unicorn_config_path), "-E", fetch(:unicorn_rack_env), "-D", fetch(:unicorn_options)
23
22
  end
24
23
  end
@@ -56,13 +55,27 @@ namespace :unicorn do
56
55
  end
57
56
  end
58
57
 
59
- desc "Restart Unicorn (USR2 + QUIT); use this when preload_app: true"
58
+ desc "Restart Unicorn (USR2); use this when preload_app: true"
60
59
  task :restart do
61
60
  invoke "unicorn:start"
62
61
  on roles(fetch(:unicorn_roles)) do
63
62
  within current_path do
64
63
  info "unicorn restarting..."
65
64
  execute :kill, "-s USR2", pid
65
+ end
66
+ end
67
+ end
68
+
69
+ desc "Duplicate Unicorn; alias of unicorn:restart"
70
+ task :duplicate do
71
+ invoke "unicorn:restart"
72
+ end
73
+
74
+ desc "Legacy Restart (USR2 + QUIT); use this when preload_app: true and oldbin pid needs cleanup"
75
+ task :legacy_restart do
76
+ invoke "unicorn:restart"
77
+ on roles(fetch(:unicorn_roles)) do
78
+ within current_path do
66
79
  execute :sleep, fetch(:unicorn_restart_sleep_time)
67
80
  if test("[ -e #{fetch(:unicorn_pid)}.oldbin ]")
68
81
  execute :kill, "-s QUIT", pid_oldbin
metadata CHANGED
@@ -1,27 +1,33 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano3-unicorn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Lineen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-22 00:00:00.000000000 Z
11
+ date: 2014-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ - - ! '>='
18
21
  - !ruby/object:Gem::Version
19
22
  version: 3.1.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - '>='
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ - - ! '>='
25
31
  - !ruby/object:Gem::Version
26
32
  version: 3.1.0
27
33
  description: Unicorn specific Capistrano tasks
@@ -31,10 +37,14 @@ executables: []
31
37
  extensions: []
32
38
  extra_rdoc_files: []
33
39
  files:
40
+ - .gitignore
34
41
  - CHANGELOG.md
42
+ - Gemfile
35
43
  - LICENSE
36
44
  - README.md
45
+ - Rakefile
37
46
  - capistrano3-unicorn.gemspec
47
+ - examples/unicorn.rb
38
48
  - lib/capistrano3-unicorn.rb
39
49
  - lib/capistrano3/tasks/unicorn.rake
40
50
  - lib/capistrano3/unicorn.rb
@@ -48,17 +58,17 @@ require_paths:
48
58
  - lib
49
59
  required_ruby_version: !ruby/object:Gem::Requirement
50
60
  requirements:
51
- - - '>='
61
+ - - ! '>='
52
62
  - !ruby/object:Gem::Version
53
63
  version: '0'
54
64
  required_rubygems_version: !ruby/object:Gem::Requirement
55
65
  requirements:
56
- - - '>='
66
+ - - ! '>='
57
67
  - !ruby/object:Gem::Version
58
68
  version: '0'
59
69
  requirements: []
60
70
  rubyforge_project:
61
- rubygems_version: 2.1.11
71
+ rubygems_version: 2.2.2
62
72
  signing_key:
63
73
  specification_version: 4
64
74
  summary: Unicorn specific Capistrano tasks