prey-capistrano-unicorn 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +26 -0
- data/LICENSE +22 -0
- data/README.md +87 -0
- data/capistrano3-unicorn.gemspec +19 -0
- data/lib/capistrano3-unicorn.rb +0 -0
- data/lib/capistrano3/tasks/unicorn.rake +101 -0
- data/lib/capistrano3/unicorn.rb +1 -0
- metadata +69 -0
data/CHANGELOG.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Capistrano3 Unicorn Changelog
|
2
|
+
|
3
|
+
## `0.1.1`
|
4
|
+
|
5
|
+
- Removed default value for `:unicorn_bundle_gemfile` of `:bundle_gemfile` so that current_path is the default
|
6
|
+
|
7
|
+
## `0.1.0`
|
8
|
+
|
9
|
+
- Changed default location of `:unicorn_pid`
|
10
|
+
- Depend on capistrano => 3.1.0
|
11
|
+
- Added `:unicorn_bundle_gemfile` to override `:bundle_gemfile`
|
12
|
+
- Bugfix; use current_path vs release_path
|
13
|
+
|
14
|
+
Thanks to @eLod, @mbrictson, and @complistic-gaff
|
15
|
+
|
16
|
+
## `0.0.6`
|
17
|
+
|
18
|
+
- Buxfix; unicorn -E should be passed a RACK_ENV (not a RAILS_ENV). [More here](http://www.hezmatt.org/~mpalmer/blog/2013/10/13/rack_env-its-not-for-you)
|
19
|
+
|
20
|
+
## `0.0.5`
|
21
|
+
|
22
|
+
- Added `:unicorn_options`
|
23
|
+
|
24
|
+
## `0.0.4`
|
25
|
+
|
26
|
+
- Added `:unicorn_roles`
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Matthew Lineen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Capistrano3 Unicorn
|
2
|
+
|
3
|
+
This is a capistrano v3 plugin that integrates Unicorn tasks into capistrano deployment scripts; it was heavily inspired by [sosedoff/capistrano-unicorn](https://github.com/sosedoff/capistrano-unicorn) but written from scratch to use the capistrano 3 syntax.
|
4
|
+
|
5
|
+
### Gotchas
|
6
|
+
|
7
|
+
- The `unicorn:start` task invokes unicorn as `bundle exec unicorn`.
|
8
|
+
|
9
|
+
- When running tasks not during a full deployment, you may need to run the `rvm:hook`:
|
10
|
+
|
11
|
+
`cap production rvm:hook unicorn:start`
|
12
|
+
|
13
|
+
### Conventions
|
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
|
16
|
+
|
17
|
+
- `:unicorn_pid`
|
18
|
+
|
19
|
+
Assumes your pid file will be located in `tmp/pids/unicorn.pid` which is symlinked by `:linked_dirs` to survive across deployments
|
20
|
+
|
21
|
+
*NOTE: THIS PATH WAS CHANGED AS OF v0.1.0*
|
22
|
+
|
23
|
+
- `:unicorn_config_path`
|
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
|
30
|
+
|
31
|
+
- `:unicorn_roles`
|
32
|
+
|
33
|
+
Roles to run unicorn commands on. Defaults to :app
|
34
|
+
|
35
|
+
- `:unicorn_options`
|
36
|
+
|
37
|
+
Set any additional options to be passed to unicorn on startup. Defaults to none
|
38
|
+
|
39
|
+
- `:unicorn_rack_env`
|
40
|
+
|
41
|
+
Set the RACK_ENV. Defaults to deployment unless the RAILS_ENV is development. Valid options are "development", "deployment", or "none". See the [RACK ENVIRONMENT](http://unicorn.bogomips.org/unicorn_1.html) section of the unicorn documentation for more information.
|
42
|
+
|
43
|
+
- `:unicorn_bundle_gemfile`
|
44
|
+
|
45
|
+
Sets the BUNDLE_GEMFILE so that unicorn will point at the new Gemfile after unicorn:restart. Defaults to `current/Gemfile`.
|
46
|
+
|
47
|
+
### Setup
|
48
|
+
|
49
|
+
Add the library to your `Gemfile`:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
group :development do
|
53
|
+
gem 'capistrano3-unicorn'
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
Add the library to your `Capfile`:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
require 'capistrano3/unicorn'
|
61
|
+
```
|
62
|
+
|
63
|
+
Invoke Unicorn from your `config/deploy.rb` or `config/deploy/ENVIRONMENT.rb`:
|
64
|
+
|
65
|
+
If `preload_app:true` use:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
after 'deploy:publishing', 'deploy:restart'
|
69
|
+
namespace :deploy do
|
70
|
+
task :restart do
|
71
|
+
invoke 'unicorn:restart'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
Otherwise use:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
after 'deploy:publishing', 'deploy:restart'
|
80
|
+
namespace :deploy do
|
81
|
+
task :restart do
|
82
|
+
invoke 'unicorn:reload'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
Note that presently you must put the `invoke` outside any `on` block since the task handles this for you; otherwise you will get an `undefined method 'verbosity'` error.
|
@@ -0,0 +1,19 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "prey-capistrano-unicorn"
|
6
|
+
gem.version = '0.0.1'
|
7
|
+
gem.authors = ["Boris Quiroz"]
|
8
|
+
gem.email = ["boris@forkhq.com"]
|
9
|
+
gem.description = "Unicorn specific Capistrano tasks - forked from Matthew Lineen's gem"
|
10
|
+
gem.summary = "Unicorn specific Capistrano tasks - forked from Matthew Lineen's gem"
|
11
|
+
gem.homepage = "https://github.com/tablexi/capistrano3-unicorn"
|
12
|
+
gem.license = "MIT"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
|
18
|
+
gem.add_dependency 'capistrano', '>= 3.1.0'
|
19
|
+
end
|
File without changes
|
@@ -0,0 +1,101 @@
|
|
1
|
+
namespace :load do
|
2
|
+
task :defaults do
|
3
|
+
set :unicorn_pid, -> { File.join(current_path, "tmp", "pids", "unicorn.pid") }
|
4
|
+
set :unicorn_config_path, -> { File.join(current_path, "config", "unicorn", "#{fetch(:rails_env)}.rb") }
|
5
|
+
set :unicorn_restart_sleep_time, 3
|
6
|
+
set :unicorn_roles, -> { :app }
|
7
|
+
set :unicorn_options, -> { "" }
|
8
|
+
set :unicorn_rack_env, -> { fetch(:rails_env) == "development" ? "development" : "deployment" }
|
9
|
+
set :unicorn_bundle_gemfile, -> { File.join(current_path, "Gemfile") }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
namespace :unicorn do
|
14
|
+
desc "Start Unicorn"
|
15
|
+
task :start do
|
16
|
+
on roles(fetch(:unicorn_roles)) do
|
17
|
+
within current_path do
|
18
|
+
if test("[ -e #{fetch(:unicorn_pid)} ] && kill -0 #{pid}")
|
19
|
+
info "unicorn is running..."
|
20
|
+
else
|
21
|
+
with rails_env: fetch(:rails_env), bundle_gemfile: fetch(:unicorn_bundle_gemfile) do
|
22
|
+
execute :bundle, "exec unicorn", "-c", fetch(:unicorn_config_path), "-E", fetch(:rails_env), "-D", fetch(:unicorn_options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Stop Unicorn (QUIT)"
|
30
|
+
task :stop do
|
31
|
+
on roles(fetch(:unicorn_roles)) do
|
32
|
+
within current_path do
|
33
|
+
if test("[ -e #{fetch(:unicorn_pid)} ]")
|
34
|
+
if test("kill -0 #{pid}")
|
35
|
+
info "stopping unicorn..."
|
36
|
+
execute :kill, "-s QUIT", pid
|
37
|
+
else
|
38
|
+
info "cleaning up dead unicorn pid..."
|
39
|
+
execute :rm, fetch(:unicorn_pid)
|
40
|
+
end
|
41
|
+
else
|
42
|
+
info "unicorn is not running..."
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Reload Unicorn (HUP); use this when preload_app: false"
|
49
|
+
task :reload do
|
50
|
+
invoke "unicorn:start"
|
51
|
+
on roles(fetch(:unicorn_roles)) do
|
52
|
+
within current_path do
|
53
|
+
info "reloading..."
|
54
|
+
execute :kill, "-s HUP", pid
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "Restart Unicorn (USR2 + QUIT); use this when preload_app: true"
|
60
|
+
task :restart do
|
61
|
+
invoke "unicorn:start"
|
62
|
+
on roles(fetch(:unicorn_roles)) do
|
63
|
+
within current_path do
|
64
|
+
info "unicorn restarting..."
|
65
|
+
execute :kill, "-s USR2", pid
|
66
|
+
execute :sleep, fetch(:unicorn_restart_sleep_time)
|
67
|
+
if test("[ -e #{fetch(:unicorn_pid)}.oldbin ]")
|
68
|
+
execute :kill, "-s QUIT", pid_oldbin
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
desc "Add a worker (TTIN)"
|
75
|
+
task :add_worker do
|
76
|
+
on roles(fetch(:unicorn_roles)) do
|
77
|
+
within current_path do
|
78
|
+
info "adding worker"
|
79
|
+
execute :kill, "-s TTIN", pid
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
desc "Remove a worker (TTOU)"
|
85
|
+
task :remove_worker do
|
86
|
+
on roles(fetch(:unicorn_roles)) do
|
87
|
+
within current_path do
|
88
|
+
info "removing worker"
|
89
|
+
execute :kill, "-s TTOU", pid
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def pid
|
96
|
+
"`cat #{fetch(:unicorn_pid)}`"
|
97
|
+
end
|
98
|
+
|
99
|
+
def pid_oldbin
|
100
|
+
"`cat #{fetch(:unicorn_pid)}.oldbin`"
|
101
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../tasks/unicorn.rake", __FILE__)
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prey-capistrano-unicorn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Boris Quiroz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capistrano
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.1.0
|
30
|
+
description: Unicorn specific Capistrano tasks - forked from Matthew Lineen's gem
|
31
|
+
email:
|
32
|
+
- boris@forkhq.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- CHANGELOG.md
|
38
|
+
- LICENSE
|
39
|
+
- README.md
|
40
|
+
- capistrano3-unicorn.gemspec
|
41
|
+
- lib/capistrano3-unicorn.rb
|
42
|
+
- lib/capistrano3/tasks/unicorn.rake
|
43
|
+
- lib/capistrano3/unicorn.rb
|
44
|
+
homepage: https://github.com/tablexi/capistrano3-unicorn
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.23
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Unicorn specific Capistrano tasks - forked from Matthew Lineen's gem
|
69
|
+
test_files: []
|