capistrano3-unicorn 0.0.3
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 +7 -0
- data/LICENSE +22 -0
- data/README.md +65 -0
- data/capistrano3-unicorn.gemspec +19 -0
- data/lib/capistrano3-unicorn.rb +0 -0
- data/lib/capistrano3/tasks/unicorn.rake +97 -0
- data/lib/capistrano3/unicorn.rb +1 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 21cdfa47278fc01afee49c867e167933ed9f8873
|
4
|
+
data.tar.gz: ed8d4b69050e9b406400ba43f8cd999603059f1f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0f31d8e78f01572681d99aaadcb1a1448d2d790e77f4746e2b6d892e05a845407740920a3da5a0b38a791b1ccd322328567762c6a13a31e6427df2dbcc001f82
|
7
|
+
data.tar.gz: b29f0e1d23e9d669c059af76d5adcc23258a21538da8e7a3a3a2dc149dddf73ebad44257cb190cf56319a41a064a86086f1622ff16480d643c20795b5954da6a
|
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,65 @@
|
|
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 the application's shared path `.../shared/pids/unicorn.pid` so that it survives zero-downtime re-deployments
|
20
|
+
|
21
|
+
- `:unicorn_config_path`
|
22
|
+
|
23
|
+
Assumes that your Unicorn configuration will be located in `config/unicorn/RAILS_ENV.rb`
|
24
|
+
|
25
|
+
- `:unicorn_restart_sleep_time`
|
26
|
+
|
27
|
+
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
|
28
|
+
|
29
|
+
### Setup
|
30
|
+
|
31
|
+
Add the library to your `Gemfile`:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
group :development do
|
35
|
+
gem 'capistrano3-unicorn'
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
Add the library to your `Capfile`:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'capistrano3/unicorn'
|
43
|
+
```
|
44
|
+
|
45
|
+
Invoke Unicorn from your `config/deploy.rb` or `config/deploy/ENVIRONMENT.rb`:
|
46
|
+
|
47
|
+
If `preload_app:true` use:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
namespace :deploy do
|
51
|
+
task :restart do
|
52
|
+
invoke 'unicorn:restart'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
Otherwise use:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
namespace :deploy do
|
61
|
+
task :restart do
|
62
|
+
invoke 'unicorn:reload'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
```
|
@@ -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 = "capistrano3-unicorn"
|
6
|
+
gem.version = '0.0.3'
|
7
|
+
gem.authors = ["Matthew Lineen"]
|
8
|
+
gem.email = ["matthew@lineen.com"]
|
9
|
+
gem.description = "Unicorn specific Capistrano tasks"
|
10
|
+
gem.summary = "Unicorn specific Capistrano tasks"
|
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.0.0'
|
19
|
+
end
|
File without changes
|
@@ -0,0 +1,97 @@
|
|
1
|
+
namespace :load do
|
2
|
+
task :defaults do
|
3
|
+
set :unicorn_pid, -> { File.join(shared_path, "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
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
namespace :unicorn do
|
10
|
+
desc 'Start Unicorn'
|
11
|
+
task :start do
|
12
|
+
on roles(:app) do
|
13
|
+
within release_path do
|
14
|
+
with rails_env: fetch(:rails_env) do
|
15
|
+
if test("[ -e #{fetch(:unicorn_pid)} ] && kill -0 #{pid}")
|
16
|
+
info "unicorn is running..."
|
17
|
+
else
|
18
|
+
execute :bundle, "exec unicorn", "-c", fetch(:unicorn_config_path), "-E", fetch(:rails_env), "-D"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Stop Unicorn (QUIT)'
|
26
|
+
task :stop do
|
27
|
+
on roles(:app) do
|
28
|
+
within release_path do
|
29
|
+
if test("[ -e #{fetch(:unicorn_pid)} ]")
|
30
|
+
if test("kill -0 #{pid}")
|
31
|
+
info "stopping unicorn..."
|
32
|
+
execute :kill, "-s QUIT", pid
|
33
|
+
else
|
34
|
+
info "cleaning up dead unicorn pid..."
|
35
|
+
execute :rm, fetch(:unicorn_pid)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
info "unicorn is not running..."
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'Reload Unicorn (HUP); use this when preload_app: false'
|
45
|
+
task :reload do
|
46
|
+
invoke 'unicorn:start'
|
47
|
+
on roles(:app) do
|
48
|
+
within release_path do
|
49
|
+
info "reloading..."
|
50
|
+
execute :kill, "-s HUP", pid
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
desc 'Restart Unicorn (USR2 + QUIT); use this when preload_app: true'
|
56
|
+
task :restart do
|
57
|
+
invoke 'unicorn:start'
|
58
|
+
on roles(:app) do
|
59
|
+
within release_path do
|
60
|
+
info "unicorn restarting..."
|
61
|
+
execute :kill, "-s USR2", pid
|
62
|
+
execute :sleep, fetch(:unicorn_restart_sleep_time)
|
63
|
+
if test("[ -e #{fetch(:unicorn_pid)}.oldbin ]")
|
64
|
+
execute :kill, "-s QUIT", pid_oldbin
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
desc 'Add a worker (TTIN)'
|
71
|
+
task :add_worker do
|
72
|
+
on roles(:app) do
|
73
|
+
within release_path do
|
74
|
+
info "adding worker"
|
75
|
+
execute :kill, "-s TTIN", pid
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
desc 'Remove a worker (TTOU)'
|
81
|
+
task :remove_worker do
|
82
|
+
on roles(:app) do
|
83
|
+
within release_path do
|
84
|
+
info "removing worker"
|
85
|
+
execute :kill, "-s TTOU", pid
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def pid
|
92
|
+
"`cat #{fetch(:unicorn_pid)}`"
|
93
|
+
end
|
94
|
+
|
95
|
+
def pid_oldbin
|
96
|
+
"`cat #{fetch(:unicorn_pid)}.oldbin`"
|
97
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../tasks/unicorn.rake", __FILE__)
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano3-unicorn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Lineen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
description: Unicorn specific Capistrano tasks
|
28
|
+
email:
|
29
|
+
- matthew@lineen.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- capistrano3-unicorn.gemspec
|
37
|
+
- lib/capistrano3-unicorn.rb
|
38
|
+
- lib/capistrano3/tasks/unicorn.rake
|
39
|
+
- lib/capistrano3/unicorn.rb
|
40
|
+
homepage: https://github.com/tablexi/capistrano3-unicorn
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.1.11
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Unicorn specific Capistrano tasks
|
64
|
+
test_files: []
|