capistrano-unicorn-pleary 0.1.6.1
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.
- data/.gitignore +41 -0
- data/Gemfile +3 -0
- data/README.md +57 -0
- data/Rakefile +2 -0
- data/capistrano-unicorn-pleary.gemspec +18 -0
- data/examples/rails3.rb +45 -0
- data/lib/capistrano-unicorn.rb +1 -0
- data/lib/capistrano-unicorn/capistrano_integration.rb +104 -0
- metadata +86 -0
data/.gitignore
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
!.gitignore
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
*.sw[a-p]
|
5
|
+
*.tmproj
|
6
|
+
*.tmproject
|
7
|
+
*.un~
|
8
|
+
*~
|
9
|
+
.DS_Store
|
10
|
+
.Spotlight-V100
|
11
|
+
.Trashes
|
12
|
+
._*
|
13
|
+
.bundle
|
14
|
+
.config
|
15
|
+
.directory
|
16
|
+
.elc
|
17
|
+
.redcar
|
18
|
+
.yardoc
|
19
|
+
/.emacs.desktop
|
20
|
+
/.emacs.desktop.lock
|
21
|
+
Desktop.ini
|
22
|
+
Gemfile.lock
|
23
|
+
Icon?
|
24
|
+
InstalledFiles
|
25
|
+
Session.vim
|
26
|
+
Thumbs.db
|
27
|
+
\#*\#
|
28
|
+
_yardoc
|
29
|
+
auto-save-list
|
30
|
+
coverage
|
31
|
+
doc/
|
32
|
+
lib/bundler/man
|
33
|
+
pkg
|
34
|
+
pkg/*
|
35
|
+
rdoc
|
36
|
+
spec/reports
|
37
|
+
test/tmp
|
38
|
+
test/version_tmp
|
39
|
+
tmp
|
40
|
+
tmtags
|
41
|
+
tramp
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Capistrano Unicorn
|
2
|
+
|
3
|
+
Capistrano plugin that integrates Unicorn tasks into capistrano deployment script.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
gem install capistrano-unicorn
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Add the gem to your ```Gemfile```:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
group :development do
|
17
|
+
gem 'capistrano-unicorn'
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
Add unicorn plugin into your deploy.rb file.
|
22
|
+
|
23
|
+
**NOTE:** Should be placed after all hooks
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'capistrano-unicorn'
|
27
|
+
```
|
28
|
+
|
29
|
+
This should add a unicorn server start task after ```deploy:restart```.
|
30
|
+
|
31
|
+
Unicorn configuration file should be placed under ```config/unicorn/YOUR_ENV.rb```
|
32
|
+
|
33
|
+
To test if it works type:
|
34
|
+
|
35
|
+
```
|
36
|
+
cap unicorn:start
|
37
|
+
cap unicorn:stop
|
38
|
+
cap unicorn:reload
|
39
|
+
```
|
40
|
+
|
41
|
+
**NOTE:** This plugin uses bundler.
|
42
|
+
|
43
|
+
## Configuration options
|
44
|
+
|
45
|
+
- ```unicorn_env``` - Set unicorn environment. Default to ```rails_env``` variable.
|
46
|
+
- ```unicorn_pid``` - Set unicorn PID file path. Default to ```current_path/tmp/pids/unicorn.pid```
|
47
|
+
- ```unicorn_bin``` - Set unicorn executable file. Default to ```unicorn```.
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
Copyright (c) 2011-2012 Dan Sosedoff.
|
52
|
+
|
53
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
54
|
+
|
55
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
56
|
+
|
57
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'capistrano-unicorn-pleary'
|
5
|
+
gem.version = '0.1.6.1'
|
6
|
+
gem.author = 'Dan Sosedoff; Patrick Leary'
|
7
|
+
gem.email = 'dan.sosedoff@gmail.com; pleary@mbl.edu'
|
8
|
+
gem.homepage = 'https://github.com/pleary/capistrano-unicorn'
|
9
|
+
gem.summary = %q{Unicorn integration for Capistrano}
|
10
|
+
gem.description = %q{Capistrano plugin that integrates Unicorn server tasks.}
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
15
|
+
gem.require_paths = ['lib']
|
16
|
+
|
17
|
+
gem.add_runtime_dependency 'capistrano'
|
18
|
+
end
|
data/examples/rails3.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# ------------------------------------------------------------------------------
|
2
|
+
# Sample rails 3 config
|
3
|
+
# ------------------------------------------------------------------------------
|
4
|
+
|
5
|
+
# Set your full path to application.
|
6
|
+
app_path = "/path/to/app"
|
7
|
+
|
8
|
+
# Set unicorn options
|
9
|
+
worker_processes 1
|
10
|
+
preload_app true
|
11
|
+
timeout 180
|
12
|
+
listen "127.0.0.1:9000"
|
13
|
+
|
14
|
+
# Spawn unicorn master worker for user apps (group: apps)
|
15
|
+
user 'apps', 'apps'
|
16
|
+
|
17
|
+
# Fill path to your app
|
18
|
+
working_directory app_path
|
19
|
+
|
20
|
+
# Should be 'production' by default, otherwise use other env
|
21
|
+
rails_env = ENV['RAILS_ENV'] || 'production'
|
22
|
+
|
23
|
+
# Log everything to one file
|
24
|
+
stderr_path "log/unicorn.log"
|
25
|
+
stdout_path "log/unicorn.log"
|
26
|
+
|
27
|
+
# Set master PID location
|
28
|
+
pid "#{app_path}/tmp/pids/unicorn.pid"
|
29
|
+
|
30
|
+
before_fork do |server, worker|
|
31
|
+
ActiveRecord::Base.connection.disconnect!
|
32
|
+
|
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
|
+
ActiveRecord::Base.establish_connection
|
45
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'capistrano-unicorn/capistrano_integration'
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
|
3
|
+
module CapistranoUnicorn
|
4
|
+
class CapistranoIntegration
|
5
|
+
def self.load_into(capistrano_config)
|
6
|
+
capistrano_config.load do
|
7
|
+
|
8
|
+
# Check if remote file exists
|
9
|
+
#
|
10
|
+
def remote_file_exists?(full_path)
|
11
|
+
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
|
12
|
+
end
|
13
|
+
|
14
|
+
# Check if process is running
|
15
|
+
#
|
16
|
+
def process_exists?(pid_file)
|
17
|
+
capture("ps -p $(cat #{pid_file}) ; true").strip.split("\n").size == 2
|
18
|
+
end
|
19
|
+
|
20
|
+
# Set unicorn vars
|
21
|
+
#
|
22
|
+
_cset(:unicorn_pid, "#{fetch(:current_path)}/tmp/pids/unicorn.pid")
|
23
|
+
_cset(:app_env, (fetch(:rails_env) rescue 'production'))
|
24
|
+
_cset(:unicorn_env, (fetch(:app_env)))
|
25
|
+
_cset(:unicorn_env_variables, (fetch(:app_env_variables) rescue ''))
|
26
|
+
_cset(:unicorn_bin, "unicorn")
|
27
|
+
|
28
|
+
namespace :unicorn do
|
29
|
+
desc 'Start Unicorn'
|
30
|
+
task :start, :roles => :app, :except => {:no_release => true} do
|
31
|
+
if remote_file_exists?(unicorn_pid)
|
32
|
+
if process_exists?(unicorn_pid)
|
33
|
+
logger.important("Unicorn is already running!", "Unicorn")
|
34
|
+
next
|
35
|
+
else
|
36
|
+
run "rm #{unicorn_pid}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
config_path = "#{current_path}/config/unicorn/#{unicorn_env}.rb"
|
41
|
+
if remote_file_exists?(config_path)
|
42
|
+
logger.important("Starting...", "Unicorn")
|
43
|
+
run "cd #{current_path} && #{unicorn_env_variables} BUNDLE_GEMFILE=#{current_path}/Gemfile bundle exec #{unicorn_bin} -c #{config_path} -E #{app_env} -D"
|
44
|
+
else
|
45
|
+
logger.important("Config file for \"#{unicorn_env}\" environment was not found at \"#{config_path}\"", "Unicorn")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
desc 'Stop Unicorn'
|
50
|
+
task :stop, :roles => :app, :except => {:no_release => true} do
|
51
|
+
if remote_file_exists?(unicorn_pid)
|
52
|
+
if process_exists?(unicorn_pid)
|
53
|
+
logger.important("Stopping...", "Unicorn")
|
54
|
+
run "#{try_sudo} kill `cat #{unicorn_pid}`"
|
55
|
+
else
|
56
|
+
run "rm #{unicorn_pid}"
|
57
|
+
logger.important("Unicorn is not running.", "Unicorn")
|
58
|
+
end
|
59
|
+
else
|
60
|
+
logger.important("No PIDs found. Check if unicorn is running.", "Unicorn")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc 'Unicorn graceful shutdown'
|
65
|
+
task :graceful_stop, :roles => :app, :except => {:no_release => true} do
|
66
|
+
if remote_file_exists?(unicorn_pid)
|
67
|
+
if process_exists?(unicorn_pid)
|
68
|
+
logger.important("Stopping...", "Unicorn")
|
69
|
+
run "#{try_sudo} kill -s QUIT `cat #{unicorn_pid}`"
|
70
|
+
else
|
71
|
+
run "rm #{unicorn_pid}"
|
72
|
+
logger.important("Unicorn is not running.", "Unicorn")
|
73
|
+
end
|
74
|
+
else
|
75
|
+
logger.important("No PIDs found. Check if unicorn is running.", "Unicorn")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
desc 'Reload Unicorn'
|
80
|
+
task :reload, :roles => :app, :except => {:no_release => true} do
|
81
|
+
if remote_file_exists?(unicorn_pid)
|
82
|
+
logger.important("Stopping...", "Unicorn")
|
83
|
+
run "#{try_sudo} kill -s USR2 `cat #{unicorn_pid}`"
|
84
|
+
else
|
85
|
+
logger.important("No PIDs found. Starting Unicorn server...", "Unicorn")
|
86
|
+
config_path = "#{current_path}/config/unicorn/#{unicorn_env}.rb"
|
87
|
+
if remote_file_exists?(config_path)
|
88
|
+
run "cd #{current_path} && #{unicorn_env_variables} BUNDLE_GEMFILE=#{current_path}/Gemfile bundle exec #{unicorn_bin} -c #{config_path} -E #{app_env} -D"
|
89
|
+
else
|
90
|
+
logger.important("Config file for \"#{unicorn_env}\" environment was not found at \"#{config_path}\"", "Unicorn")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
after "deploy:restart", "unicorn:reload"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
if Capistrano::Configuration.instance
|
103
|
+
CapistranoUnicorn::CapistranoIntegration.load_into(Capistrano::Configuration.instance)
|
104
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-unicorn-pleary
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 93
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 6
|
10
|
+
- 1
|
11
|
+
version: 0.1.6.1
|
12
|
+
platform: ruby
|
13
|
+
authors:
|
14
|
+
- Dan Sosedoff; Patrick Leary
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2012-11-21 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: capistrano
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Capistrano plugin that integrates Unicorn server tasks.
|
36
|
+
email: dan.sosedoff@gmail.com; pleary@mbl.edu
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- capistrano-unicorn-pleary.gemspec
|
49
|
+
- examples/rails3.rb
|
50
|
+
- lib/capistrano-unicorn.rb
|
51
|
+
- lib/capistrano-unicorn/capistrano_integration.rb
|
52
|
+
homepage: https://github.com/pleary/capistrano-unicorn
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.24
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Unicorn integration for Capistrano
|
85
|
+
test_files: []
|
86
|
+
|