glebtv-capistrano-unicorn 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -5
- data/LICENSE +2 -1
- data/README.md +19 -77
- data/Rakefile +0 -7
- data/examples/rails3.rb +50 -28
- data/glebtv-capistrano-unicorn.gemspec +1 -1
- data/lib/capistrano/tasks/{unicorn.cap → unicorn.rake} +6 -6
- data/lib/capistrano/unicorn.rb +1 -1
- data/lib/capistrano/unicorn/utility.rb +0 -2
- data/lib/capistrano/unicorn/version.rb +1 -1
- metadata +6 -8
- data/NEWS.md +0 -27
- data/lib/unicorn.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b3e269b06dadaa79a330e1a68de83b93e18b4b9
|
4
|
+
data.tar.gz: e875511de350029514c58e2c8ec618b1a8488fdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28fa51f25b0a60172019f9108f4d9e6b08c462fa792c525341c13b040fa278e33d4214cde391b2be2dc3a5c02c14f8f77d3de0ead8db2d60fcc4d9a6fcc4686f
|
7
|
+
data.tar.gz: aaddf4ce3444d94714c68a8f25e73208e282f6229f9427ab4063d7658aeac63ef5df1a62251ca484cde8a2f70c3c8207eeaf1cccd48d86174223666685b78eb3
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
Copyright (c) 2011-2013 Dan Sosedoff.
|
2
|
+
Copyright (c) 2014-2015 GlebTv
|
2
3
|
|
3
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
5
|
this software and associated documentation files (the "Software"), to deal in
|
@@ -15,4 +16,4 @@ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
15
16
|
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
16
17
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
17
18
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
18
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -3,12 +3,6 @@
|
|
3
3
|
Capistrano 3.x plugin that integrates Unicorn tasks into capistrano deployment script.
|
4
4
|
Taken from https://github.com/sosedoff/capistrano-unicorn and adapted to work with Capistrano 3.x.
|
5
5
|
|
6
|
-
**Note: this code is not well tested, if anything fails, please report it. Use at your own risk.**
|
7
|
-
|
8
|
-
**Developers:** Please consider contributing your forked changes, or opening an
|
9
|
-
issue if there is no existing relevant one. There are a lot of forks--we'd love
|
10
|
-
to reabsorb some of the issues/solutions the community has encountered.
|
11
|
-
|
12
6
|
[](http://badge.fury.io/rb/glebtv-capistrano-unicorn)
|
13
7
|
|
14
8
|
## Usage
|
@@ -25,7 +19,7 @@ group :development do
|
|
25
19
|
end
|
26
20
|
```
|
27
21
|
|
28
|
-
|
22
|
+
Add it to `Capfile`:
|
29
23
|
|
30
24
|
```ruby
|
31
25
|
require 'capistrano/unicorn'
|
@@ -42,7 +36,12 @@ after 'deploy:restart', 'unicorn:duplicate' # before_fork hook implemented (zero
|
|
42
36
|
Create a new configuration file `config/unicorn.rb` or `config/unicorn/STAGE.rb`,
|
43
37
|
where stage is your deployment environment.
|
44
38
|
|
45
|
-
Example config
|
39
|
+
## Example config
|
40
|
+
|
41
|
+
Includes zero-downtime deployments
|
42
|
+
|
43
|
+
[examples/rails3.rb](https://github.com/glebtv/capistrano-unicorn/blob/master/examples/rails3.rb).
|
44
|
+
|
46
45
|
Please refer to Unicorn documentation for more examples and configuration options.
|
47
46
|
|
48
47
|
### Deploy
|
@@ -50,15 +49,15 @@ Please refer to Unicorn documentation for more examples and configuration option
|
|
50
49
|
First, make sure you're running the latest release:
|
51
50
|
|
52
51
|
```
|
53
|
-
cap deploy
|
52
|
+
cap production deploy
|
54
53
|
```
|
55
54
|
|
56
55
|
Then you can test each individual task:
|
57
56
|
|
58
57
|
```
|
59
|
-
cap unicorn:start
|
60
|
-
cap unicorn:stop
|
61
|
-
cap unicorn:reload
|
58
|
+
cap production unicorn:start
|
59
|
+
cap production unicorn:stop
|
60
|
+
cap production unicorn:reload
|
62
61
|
```
|
63
62
|
|
64
63
|
## Configuration
|
@@ -106,73 +105,16 @@ are set correctly.
|
|
106
105
|
To get a list of all capistrano tasks, run `cap -T`:
|
107
106
|
|
108
107
|
```
|
109
|
-
cap unicorn:add_worker # Add a new worker
|
110
|
-
cap unicorn:remove_worker # Remove amount of workers
|
111
|
-
cap unicorn:reload # Reload Unicorn
|
112
|
-
cap unicorn:restart # Restart Unicorn
|
113
|
-
cap unicorn:show_vars # Debug Unicorn variables
|
114
|
-
cap unicorn:shutdown # Immediately shutdown Unicorn
|
115
|
-
cap unicorn:start # Start Unicorn master process
|
116
|
-
cap unicorn:stop # Stop Unicorn
|
117
|
-
```
|
118
|
-
|
119
|
-
## Tests
|
120
|
-
|
121
|
-
To execute test suite run:
|
122
|
-
|
123
|
-
```
|
124
|
-
bundle exec rake test
|
125
|
-
```
|
126
|
-
|
127
|
-
### Multistage
|
128
|
-
|
129
|
-
The issue here is that capistrano loads default configuration and then
|
130
|
-
executes your staging task and overrides previously defined
|
131
|
-
variables. The default environment before executing your stage task is
|
132
|
-
set to `:production`, so it will use a wrong environment unless you
|
133
|
-
take steps to ensure that `:rails_env` and `:unicorn_env` are
|
134
|
-
set correctly.
|
135
|
-
|
136
|
-
Let's say you have a scenario involving two deployment stages: staging
|
137
|
-
and production. You’ll need to add `config/deploy/staging.rb` and
|
138
|
-
`config/deploy/production.rb` files. However, it makes sense to
|
139
|
-
adhere to DRY and avoid duplicating lines between the two files. So
|
140
|
-
it would be nicer to keep common settings in `config/deploy.rb`, and
|
141
|
-
only put stuff in each staging definition file which is really
|
142
|
-
specific to that staging environment. Fortunately this can be done
|
143
|
-
using the [lazy evaluation form of `set`](https://github.com/capistrano/capistrano/wiki/2.x-DSL-Configuration-Variables-Set).
|
144
|
-
|
145
|
-
So `config/deploy.rb` file would contain something like:
|
146
|
-
|
147
|
-
```ruby
|
148
|
-
set :stages, %w(production staging)
|
149
|
-
set :default_stage, "staging"
|
150
|
-
require 'capistrano/ext/multistage'
|
151
|
-
|
152
|
-
role(:web) { domain }
|
153
|
-
role(:app) { domain }
|
154
|
-
role(:db, :primary => true) { domain }
|
155
|
-
|
156
|
-
set(:deploy_to) { "/home/#{user}/#{application}/#{fetch :rails_env}" }
|
157
|
-
set(:current_path) { File.join(deploy_to, current_dir) }
|
158
|
-
```
|
159
|
-
|
160
|
-
Then `config/deploy/production.rb` would contain something like:
|
161
|
-
|
162
|
-
```ruby
|
163
|
-
set :domain, "app.mydomain.com"
|
164
|
-
set :rails_env, "production"
|
165
|
-
```
|
166
|
-
|
167
|
-
and `config/deploy/staging.rb` would only need to contain something like:
|
168
|
-
|
169
|
-
```ruby
|
170
|
-
set :domain, "app.staging.mydomain.com"
|
171
|
-
set :rails_env, "staging"
|
108
|
+
cap production unicorn:add_worker # Add a new worker
|
109
|
+
cap production unicorn:remove_worker # Remove amount of workers
|
110
|
+
cap production unicorn:reload # Reload Unicorn
|
111
|
+
cap production unicorn:restart # Restart Unicorn
|
112
|
+
cap production unicorn:show_vars # Debug Unicorn variables
|
113
|
+
cap production unicorn:shutdown # Immediately shutdown Unicorn
|
114
|
+
cap production unicorn:start # Start Unicorn master process
|
115
|
+
cap production unicorn:stop # Stop Unicorn
|
172
116
|
```
|
173
117
|
|
174
|
-
Nice and clean!
|
175
|
-
|
176
118
|
## License
|
177
119
|
|
178
120
|
See LICENSE file for details.
|
data/Rakefile
CHANGED
data/examples/rails3.rb
CHANGED
@@ -1,45 +1,67 @@
|
|
1
|
-
|
2
|
-
# Sample rails 3 config
|
3
|
-
# ------------------------------------------------------------------------------
|
1
|
+
rails_env = ENV['RAILS_ENV'] || 'production'
|
4
2
|
|
5
|
-
|
6
|
-
|
3
|
+
deploy_to = "/data/rt/app"
|
4
|
+
rails_root = "#{deploy_to}/current"
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
preload_app true
|
11
|
-
timeout 180
|
12
|
-
listen "127.0.0.1:9000"
|
6
|
+
pid_dir = "#{deploy_to}/shared/tmp/pids"
|
7
|
+
FileUtils.mkdir_p(pid_dir, mode: 0777) unless File.directory?(pid_dir)
|
13
8
|
|
14
|
-
|
15
|
-
|
9
|
+
pid_file = "#{pid_dir}/unicorn.pid"
|
10
|
+
#socket_file= "#{deploy_to}/shared/sockets/unicorn.sock"
|
11
|
+
log_file = "#{deploy_to}/shared/log/unicorn.log"
|
12
|
+
err_log_file = "#{deploy_to}/shared/log/unicorn.error.log"
|
16
13
|
|
17
|
-
|
18
|
-
working_directory app_path
|
14
|
+
old_pid_file = pid_file + '.oldbin'
|
19
15
|
|
20
|
-
|
21
|
-
|
16
|
+
worker_processes 2
|
17
|
+
working_directory rails_root
|
18
|
+
|
19
|
+
timeout 300
|
22
20
|
|
23
|
-
#
|
24
|
-
|
25
|
-
stdout_path "log/unicorn.log"
|
21
|
+
# Specify path to socket unicorn listens to,
|
22
|
+
# we will use this in our nginx.conf later
|
26
23
|
|
27
|
-
|
28
|
-
|
24
|
+
listen "127.0.0.1:4000"
|
25
|
+
|
26
|
+
pid pid_file
|
27
|
+
|
28
|
+
# Set log file paths
|
29
|
+
stderr_path err_log_file
|
30
|
+
stdout_path log_file
|
31
|
+
|
32
|
+
# http://tech.tulentsev.com/2012/03/deploying-with-sinatra-capistrano-unicorn/
|
33
|
+
# NOTE: http://unicorn.bogomips.org/SIGNALS.html
|
34
|
+
preload_app true
|
35
|
+
|
36
|
+
# make sure that Bundler finds the Gemfile
|
37
|
+
before_exec do |server|
|
38
|
+
ENV['BUNDLE_GEMFILE'] = File.join( rails_root, 'Gemfile' )
|
39
|
+
end
|
29
40
|
|
30
41
|
before_fork do |server, worker|
|
31
|
-
|
42
|
+
# при использовании preload_app = true здесь должно быть закрытие всех открытых сокетов
|
32
43
|
|
33
|
-
|
34
|
-
|
44
|
+
# uncomment for AR
|
45
|
+
# ActiveRecord::Base.connection.disconnect
|
46
|
+
# Mongoid reconnects itself
|
47
|
+
# http://two.mongoid.org/docs/upgrading.html
|
48
|
+
|
49
|
+
# http://stackoverflow.com/a/9498372/2041969
|
50
|
+
if File.exists?( old_pid_file )
|
35
51
|
begin
|
36
|
-
Process.kill("QUIT", File.read(
|
52
|
+
Process.kill( "QUIT", File.read( old_pid_file ).to_i )
|
37
53
|
rescue Errno::ENOENT, Errno::ESRCH
|
38
|
-
|
54
|
+
puts "Old master alerady dead"
|
39
55
|
end
|
40
56
|
end
|
41
57
|
end
|
42
58
|
|
43
59
|
after_fork do |server, worker|
|
44
|
-
|
45
|
-
|
60
|
+
# uncomment for AR
|
61
|
+
# ActiveRecord::Base.establish_connection
|
62
|
+
|
63
|
+
# child process pids for monitoring if you need them
|
64
|
+
child_pid_file = server.config[:pid].sub( '.pid', ".#{worker.nr}.pid" )
|
65
|
+
system( "echo #{Process.pid} > #{child_pid_file}" )
|
66
|
+
end
|
67
|
+
|
@@ -85,28 +85,28 @@ namespace :unicorn do
|
|
85
85
|
|
86
86
|
desc 'Start Unicorn master process'
|
87
87
|
task :start do
|
88
|
-
on
|
88
|
+
on release_roles(unicorn_roles) do
|
89
89
|
execute start_unicorn
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
93
|
desc 'Stop Unicorn'
|
94
94
|
task :stop do
|
95
|
-
on
|
95
|
+
on release_roles(unicorn_roles) do
|
96
96
|
execute kill_unicorn('QUIT')
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
100
|
desc 'Immediately shutdown Unicorn'
|
101
101
|
task :shutdown do
|
102
|
-
on
|
102
|
+
on release_roles(unicorn_roles) do
|
103
103
|
execute kill_unicorn('TERM')
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
107
|
desc 'Restart Unicorn'
|
108
108
|
task :restart do
|
109
|
-
on
|
109
|
+
on release_roles(unicorn_roles) do
|
110
110
|
duplicate_unicorn
|
111
111
|
execute :sleep, fetch(:unicorn_restart_sleep_time)
|
112
112
|
|
@@ -118,14 +118,14 @@ namespace :unicorn do
|
|
118
118
|
|
119
119
|
desc 'Duplicate Unicorn'
|
120
120
|
task :duplicate do
|
121
|
-
on
|
121
|
+
on release_roles(unicorn_roles) do
|
122
122
|
duplicate_unicorn
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
126
|
desc 'Reload Unicorn'
|
127
127
|
task :reload do
|
128
|
-
on
|
128
|
+
on release_roles(unicorn_roles) do
|
129
129
|
if unicorn_is_running?
|
130
130
|
unicorn_send_signal('HUP')
|
131
131
|
else
|
data/lib/capistrano/unicorn.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
load File.expand_path(File.join('..', 'tasks', 'unicorn.
|
1
|
+
load File.expand_path(File.join('..', 'tasks', 'unicorn.rake'), __FILE__)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glebtv-capistrano-unicorn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebtv, Sebastian Gassner, Dan Sosedoff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.4'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
54
|
+
version: '3.4'
|
55
55
|
description: Capistrano 3.x plugin that integrates Unicorn server tasks.
|
56
56
|
email: glebtv@gmail.com
|
57
57
|
executables: []
|
@@ -65,18 +65,16 @@ files:
|
|
65
65
|
- ".travis.yml"
|
66
66
|
- Gemfile
|
67
67
|
- LICENSE
|
68
|
-
- NEWS.md
|
69
68
|
- README.md
|
70
69
|
- Rakefile
|
71
70
|
- examples/rails3.rb
|
72
71
|
- glebtv-capistrano-unicorn.gemspec
|
73
72
|
- lib/capistrano-unicorn.rb
|
74
|
-
- lib/capistrano/tasks/unicorn.
|
73
|
+
- lib/capistrano/tasks/unicorn.rake
|
75
74
|
- lib/capistrano/unicorn.rb
|
76
75
|
- lib/capistrano/unicorn/utility.rb
|
77
76
|
- lib/capistrano/unicorn/version.rb
|
78
77
|
- lib/glebtv-capistrano-unicorn.rb
|
79
|
-
- lib/unicorn.rb
|
80
78
|
homepage: https://github.com/glebtv/capistrano-unicorn
|
81
79
|
licenses:
|
82
80
|
- MIT
|
@@ -97,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
95
|
version: '0'
|
98
96
|
requirements: []
|
99
97
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.
|
98
|
+
rubygems_version: 2.4.5
|
101
99
|
signing_key:
|
102
100
|
specification_version: 4
|
103
101
|
summary: Unicorn integration for Capistrano 3.x
|
data/NEWS.md
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# Capistrano Unicorn NEWS
|
2
|
-
|
3
|
-
## 0.2.0
|
4
|
-
|
5
|
-
Significant changes since 0.1.10 are as follows. Backwards-incompatible changes are **in bold**.
|
6
|
-
|
7
|
-
* Ensured `RAILS_ENV` is set correctly.
|
8
|
-
* Embedded multistage docs directly within the [README](README.md) (the wiki page was version-specific and misleading).
|
9
|
-
* Significantly tidied up the usage and documentation of configuration variables:
|
10
|
-
* **In most cases, it should now be sufficient to simply set `rails_env` correctly,
|
11
|
-
and other variables should assume the correct value by default.**
|
12
|
-
* **Make `unicorn_env` default to `rails_env` or `'production'`.**
|
13
|
-
* **Rename `app_env` to `unicorn_rack_env` and fix default value.**
|
14
|
-
* Add `unicorn_options` variable which allows passing of arbitrary options to unicorn.
|
15
|
-
* Added `app_subdir` to support app running in a subdirectory.
|
16
|
-
* Updated documentation in [README](README.md) to fix inaccuracies and ambiguities.
|
17
|
-
* `unicorn_pid` defaults to attempting to auto-detect from unicorn config file.
|
18
|
-
This avoids having to keep two paths in sync.
|
19
|
-
https://github.com/sosedoff/capistrano-unicorn/issues/7
|
20
|
-
* Also added the `unicorn:show_vars` task to make it easier to debug
|
21
|
-
config variable values client-side.
|
22
|
-
* Defer calculation of `unicorn-roles`.
|
23
|
-
|
24
|
-
It was noticed that there are a
|
25
|
-
[huge number of unmerged forks on github](https://github.com/sosedoff/capistrano-unicorn/issues/45),
|
26
|
-
so we also updated the [README](README.md) asking the community to
|
27
|
-
contribute back any useful changes they make.
|
data/lib/unicorn.rb
DELETED
File without changes
|