capistrano-simple-unicorn 1.0.0 → 1.1.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/README.md +5 -5
- data/lib/capistrano/simple_unicorn/helpers.rb +3 -3
- data/lib/capistrano/simple_unicorn/version.rb +1 -1
- data/lib/capistrano/tasks/nginx.rake +1 -1
- data/lib/capistrano/tasks/unicorn.rake +58 -36
- data/lib/generators/capistrano/simple_unicorn/templates/unicorn.rb.erb +22 -12
- data/lib/generators/capistrano/simple_unicorn/templates/unicorn_init.erb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc900d264d6068259766d0fd89b6a73eccd7fe8b
|
4
|
+
data.tar.gz: 4815ed5cbe0251e1f4d06cbea417cd914223e9bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab7943a6de75ce9c6e43c646029f48716ff3156176a5f1c1fbdea7de0414469f4d190abd3c405de8bc7a1724d5baaaa2028733ed115f68eb9b89884794cd3f62
|
7
|
+
data.tar.gz: 44f112be6584c1dd2f7d793d9c73cbf33d904fba841d2c638007903ee1a9fa7cdd9a14bbbf2743dbd8a7494fdf3fa5df2000b70cd9744defb04fbf094b84946b
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Capistrano::
|
1
|
+
# Capistrano::SimpleUnicorn
|
2
2
|
Support for Capistrano 3.x
|
3
3
|
|
4
4
|
Capistrano task for automatic and unicorn configuration
|
@@ -40,9 +40,9 @@ Default value:
|
|
40
40
|
```
|
41
41
|
set :unicorn_service, -> { "unicorn_#{fetch(:application)}" }
|
42
42
|
set :user_home_path, -> { "/home/#{fetch(:user)}" }
|
43
|
-
set :
|
44
|
-
set :
|
45
|
-
set :
|
43
|
+
set :unicorn_config_path, -> { shared_path.join("config", "unicorn.rb") }
|
44
|
+
set :unicorn_pid_path, -> { shared_path.join("tmp", "pids", "unicorn.pid") }
|
45
|
+
set :unicorn_sock_path, -> { shared_path.join("tmp", "unicorn.sock") }
|
46
46
|
set :unicorn_log_file, -> { shaed_path.join("log", "unicorn.stdout.log") }
|
47
47
|
set :unicorn_error_log_file, -> {shared_path.join("log","unicorn.stderr.log")}
|
48
48
|
set :ruby_version, -> { fetch(:rvm_ruby_version) || fetch(:rbenv_ruby) }
|
@@ -96,5 +96,5 @@ set :nginx_upstream_file, "/tmp/unicorn.sock"
|
|
96
96
|
set :nginx_fail_timeout, 0
|
97
97
|
set :nginx_access_log_file, -> { "/var/log/nginx/#{fetch(:nginx_config_name)}.access.log" } # access log file
|
98
98
|
set :nginx_error_log_file, -> { "/var/log/nginx/#{fetch(:nginx_config_name)}.error.log" } # error log file
|
99
|
-
set :nginx_upstream_file, -> { "#{fetch(:
|
99
|
+
set :nginx_upstream_file, -> { "#{fetch(:unicorn_sock_path)}" } # .sock file path
|
100
100
|
```
|
@@ -44,15 +44,15 @@ module Capistrano
|
|
44
44
|
"/etc/init.d/#{fetch(:unicorn_service)}"
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
47
|
+
def unicorn_sock_path
|
48
48
|
shared_path.join("tmp", "unicorn.sock")
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
51
|
+
def unicorn_config_path
|
52
52
|
shared_path.join("config", "unicorn.rb")
|
53
53
|
end
|
54
54
|
|
55
|
-
def
|
55
|
+
def unicorn_pid_path
|
56
56
|
shared_path.join("tmp", "pids", "unicorn.pid")
|
57
57
|
end
|
58
58
|
|
@@ -10,7 +10,7 @@ namespace :load do
|
|
10
10
|
set :nginx_fail_timeout, 0
|
11
11
|
set :nginx_access_log_file, -> { "/var/log/nginx/#{fetch(:nginx_config_name)}.access.log" }
|
12
12
|
set :nginx_error_log_file, -> { "/var/log/nginx/#{fetch(:nginx_config_name)}.error.log" }
|
13
|
-
set :nginx_upstream_file, -> { "#{fetch(:
|
13
|
+
set :nginx_upstream_file, -> { "#{fetch(:unicorn_sock_path)}" }
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -5,11 +5,15 @@ namespace :load do
|
|
5
5
|
task :defaults do
|
6
6
|
set :unicorn_service, -> { "unicorn_#{fetch(:application)}" }
|
7
7
|
set :user_home_path, -> { "/home/#{fetch(:user)}" }
|
8
|
-
set :
|
9
|
-
set :
|
10
|
-
set :
|
11
|
-
set :
|
12
|
-
set :
|
8
|
+
set :unicorn_config_path, -> { unicorn_config_path }
|
9
|
+
set :unicorn_pid_path, -> { unicorn_pid_path }
|
10
|
+
set :unicorn_sock_path, -> { unicorn_sock_path }
|
11
|
+
set :unicorn_stdout_path, -> { unicorn_log_file }
|
12
|
+
set :unicorn_stderr_path, -> { unicorn_error_log_file }
|
13
|
+
set :unicorn_roles, -> { :app }
|
14
|
+
set :unicorn_restart_sleep_time, 3
|
15
|
+
set :unicorn_options, -> { '' }
|
16
|
+
set :unicorn_env, -> { fetch(:rails_env) || 'deployment' }
|
13
17
|
set :ruby_version, -> { fetch(:rvm_ruby_version) || fetch(:rbenv_ruby) }
|
14
18
|
set :unicorn_worker_processes, 2
|
15
19
|
set :unicorn_timeout, 30
|
@@ -19,52 +23,70 @@ namespace :load do
|
|
19
23
|
end
|
20
24
|
|
21
25
|
namespace :unicorn do
|
22
|
-
desc 'Unicorn
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
desc 'Start Unicorn' do
|
27
|
+
task :start do
|
28
|
+
on roles(fetch(:unicorn_roles)) do
|
29
|
+
within current_path do
|
30
|
+
if test("[ -e #{fetch(:unicorn_pid)} ] && kill -0 #{pid}")
|
31
|
+
info 'unicorn is running...'
|
32
|
+
else
|
33
|
+
with rails_env: fetch(:rails_env) do
|
34
|
+
execute :bundle, 'exec unicorn', '-c', fetch(:unicorn_config_path), '-E', fetch(:unicorn_env), '-D', fetch(:unicorn_options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
31
38
|
end
|
32
39
|
end
|
33
40
|
end
|
34
41
|
|
35
|
-
desc '
|
36
|
-
task :
|
37
|
-
on roles
|
38
|
-
|
39
|
-
|
42
|
+
desc 'Stop Unicorn (QUIT)'
|
43
|
+
task :stop do
|
44
|
+
on roles(fetch(:unicorn_roles)) do
|
45
|
+
within current_path do
|
46
|
+
if test("[ -e #{fetch(:unicorn_pid_path)} ]")
|
47
|
+
if test("kill -0 #{pid}")
|
48
|
+
info 'stopping unicorn...'
|
49
|
+
execute :kill, '-s QUIT', pid
|
50
|
+
else
|
51
|
+
info 'cleaning up dead unicorn pid...'
|
52
|
+
execute :rm, fetch(:unicorn_pid_path)
|
53
|
+
end
|
54
|
+
else
|
55
|
+
info 'unicorn is not running...'
|
56
|
+
end
|
40
57
|
end
|
41
|
-
upload! template('unicorn.rb.erb'), fetch(:unicorn_config_file)
|
42
58
|
end
|
43
59
|
end
|
44
60
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
61
|
+
desc 'Restart Unicorn (USR2); use this when preload_app: true'
|
62
|
+
task :restart do
|
63
|
+
invoke 'unicorn:start'
|
64
|
+
on roles(fetch(:unicorn_roles)) do
|
65
|
+
within current_path do
|
66
|
+
info 'unicorn restarting...'
|
67
|
+
execute :kill, '-s USR2', pid
|
50
68
|
end
|
51
69
|
end
|
52
70
|
end
|
53
71
|
|
54
|
-
desc '
|
55
|
-
task
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
72
|
+
desc 'Legacy Restart (USR2 + QUIT); use this when preload_app: true and oldbin pid needs cleanup'
|
73
|
+
task :legacy_restart do
|
74
|
+
invoke 'unicorn:restart'
|
75
|
+
on roles(fetch(:unicorn_roles)) do
|
76
|
+
within current_path do
|
77
|
+
execute :sleep, fetch(:unicorn_restart_sleep_time)
|
78
|
+
if test("[ -e #{fetch(:unicorn_pid_path)}.oldbin ]")
|
79
|
+
execute :kill, '-s QUIT', pid_oldbin
|
80
|
+
end
|
63
81
|
end
|
64
82
|
end
|
65
83
|
end
|
66
84
|
end
|
67
85
|
|
68
|
-
|
69
|
-
|
86
|
+
def pid
|
87
|
+
"`cat #{fetch(:unicorn_pid_path)}`"
|
88
|
+
end
|
89
|
+
|
90
|
+
def pid_oldbin
|
91
|
+
"`cat #{fetch(:unicorn_pid_path)}.oldbin`"
|
70
92
|
end
|
@@ -1,26 +1,36 @@
|
|
1
1
|
worker_processes <%= fetch(:unicorn_worker_processes) %>
|
2
2
|
timeout <%= fetch(:unicorn_timeout) %>
|
3
|
+
app_path = "<%= fetch(:deploy_to) %>"
|
4
|
+
listen "<%= fetch(:unicorn_sock_path) %>"
|
5
|
+
pid "<%= fetch(:unicorn_pid_path) %>"
|
3
6
|
|
4
|
-
|
5
|
-
|
7
|
+
stderr_path "<%= fetch(:unicorn_stderr_path) %>"
|
8
|
+
stdout_path "<%= fetch(:unicorn_stdout_path %>"
|
6
9
|
|
7
|
-
|
8
|
-
|
10
|
+
preload_app true
|
11
|
+
|
12
|
+
# use correct Gemfile on restarts
|
13
|
+
before_exec do |server|
|
14
|
+
ENV['BUNDLE_GEMFILE'] = "#{app_path}/current/Gemfile"
|
15
|
+
end
|
9
16
|
|
10
17
|
preload_app true
|
11
18
|
|
12
19
|
before_fork do |server, worker|
|
13
|
-
|
20
|
+
# the following is highly recomended for Rails + "preload_app true"
|
21
|
+
# as there's no need for the master process to hold a connection
|
22
|
+
if defined?(ActiveRecord::Base)
|
23
|
+
ActiveRecord::Base.connection.disconnect!
|
24
|
+
end
|
14
25
|
|
15
|
-
|
16
|
-
|
26
|
+
# Before forking, kill the master process that belongs to the .oldbin PID.
|
27
|
+
# This enables 0 downtime deploys.
|
28
|
+
old_pid = "#{server.config[:pid]}.oldbin"
|
29
|
+
if File.exists?(old_pid) && server.pid != old_pid
|
17
30
|
begin
|
18
|
-
Process.kill
|
31
|
+
Process.kill("QUIT", File.read(old_pid).to_i)
|
19
32
|
rescue Errno::ENOENT, Errno::ESRCH
|
33
|
+
# someone else did our job for us
|
20
34
|
end
|
21
35
|
end
|
22
36
|
end
|
23
|
-
|
24
|
-
after_fork do |server, worker|
|
25
|
-
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
|
26
|
-
end
|
@@ -11,11 +11,11 @@
|
|
11
11
|
set -e
|
12
12
|
HOME=<%= fetch(:user_home_path) %>
|
13
13
|
APP_ROOT=<%= current_path %>
|
14
|
-
PID=<%= fetch(:
|
14
|
+
PID=<%= fetch(:unicorn_pid_path) %>
|
15
15
|
USER=<%= fetch(:user) %>
|
16
16
|
ENV="<%= fetch(:stage) %>"
|
17
17
|
RUBY_VERSION="<%= fetch(:ruby_version) %>"
|
18
|
-
CONFIG_FILE="<%= fetch(:
|
18
|
+
CONFIG_FILE="<%= fetch(:unicorn_config_path) %>"
|
19
19
|
CMD="cd $APP_ROOT && export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION=$RUBY_VERSION; $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c $CONFIG_FILE -E $ENV -D"
|
20
20
|
|
21
21
|
set -u
|