capistrano-simple-unicorn 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- 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 +36 -103
- data/lib/generators/capistrano/simple_unicorn/templates/unicorn.rb.erb +12 -22
- 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: '08716c38cf242db16b46c00b7575ce8b39fe1906'
|
4
|
+
data.tar.gz: e47a573ac35e442613bb5549c20e7deb790b10d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbeca25cf799f0a32261d203fdec7d5251711de7ffc6210afc35f71d7400da15e5f97f12643b9a6023ab9e543b8eaec43df9609eaba1f6f7b9ce87c4b297330d
|
7
|
+
data.tar.gz: 7abaae55f9462f0b3f059ba4999c6a2b7fea93b365b382f281c27fe0618b7bebb07429513d917c2fc7268e3f77ae788ed1959eebef236a87a0fb4f2b88c27cff
|
data/README.md
CHANGED
@@ -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_file, -> { shared_path.join("config", "unicorn.rb") }
|
44
|
+
set :unicorn_pid_file, -> { shared_path.join("tmp", "pids", "unicorn.pid") }
|
45
|
+
set :unicorn_sock_file, -> { 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_file)}" } # .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_file
|
48
48
|
shared_path.join("tmp", "unicorn.sock")
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
51
|
+
def unicorn_config_file
|
52
52
|
shared_path.join("config", "unicorn.rb")
|
53
53
|
end
|
54
54
|
|
55
|
-
def
|
55
|
+
def unicorn_pid_file
|
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_file)}" }
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -5,15 +5,11 @@ 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 :
|
13
|
-
set :unicorn_roles, -> { :app }
|
14
|
-
set :unicorn_restart_sleep_time, 3
|
15
|
-
set :unicorn_options, -> { '' }
|
16
|
-
set :unicorn_env, -> { fetch(:rails_env) || 'deployment' }
|
8
|
+
set :unicorn_config_file, -> { unicorn_config_file }
|
9
|
+
set :unicorn_pid_file, -> { unicorn_pid_file }
|
10
|
+
set :unicorn_sock_file, -> { unicorn_sock_file }
|
11
|
+
set :unicorn_log_file, -> { unicorn_log_file }
|
12
|
+
set :unicorn_error_log_file, -> { unicorn_error_log_file }
|
17
13
|
set :ruby_version, -> { fetch(:rvm_ruby_version) || fetch(:rbenv_ruby) }
|
18
14
|
set :unicorn_worker_processes, 2
|
19
15
|
set :unicorn_timeout, 30
|
@@ -23,115 +19,52 @@ namespace :load do
|
|
23
19
|
end
|
24
20
|
|
25
21
|
namespace :unicorn do
|
26
|
-
desc
|
27
|
-
task :
|
28
|
-
on roles
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
desc 'Unicorn Initializer'
|
23
|
+
task :unicorn_init do
|
24
|
+
on roles :app do
|
25
|
+
sudo_upload! template('unicorn_init.erb'), unicorn_initd_file
|
26
|
+
execute :chmod, '+x', unicorn_initd_file
|
27
|
+
if os_is_ubuntu?
|
28
|
+
sudo 'update-rc.d', '-f', fetch(:unicorn_service), 'defaults'
|
29
|
+
else
|
30
|
+
sudo 'chkconfig', '--add', fetch(:unicorn_service)
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|
35
34
|
|
36
|
-
desc
|
37
|
-
task :
|
38
|
-
on roles
|
39
|
-
|
40
|
-
|
41
|
-
info "unicorn is running..."
|
42
|
-
else
|
43
|
-
with rails_env: fetch(:rails_env) do
|
44
|
-
execute :bundle, "exec unicorn", "-c", fetch(:unicorn_config_path), "-E", fetch(:unicorn_env), "-D", fetch(:unicorn_options)
|
45
|
-
end
|
46
|
-
end
|
35
|
+
desc 'Setup unicorn config'
|
36
|
+
task :setup_unicorn_config do
|
37
|
+
on roles :app do
|
38
|
+
unless file_exists? fetch(:unicorn_config_file)
|
39
|
+
execute :mkdir, '-pv', File.dirname(fetch(:unicorn_config_file))
|
47
40
|
end
|
41
|
+
upload! template('unicorn.rb.erb'), fetch(:unicorn_config_file)
|
48
42
|
end
|
49
43
|
end
|
50
44
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
if test("kill -0 #{pid}")
|
57
|
-
info "stopping unicorn..."
|
58
|
-
execute :kill, "-s QUIT", pid
|
59
|
-
else
|
60
|
-
info "cleaning up dead unicorn pid..."
|
61
|
-
execute :rm, fetch(:unicorn_pid_path)
|
62
|
-
end
|
63
|
-
else
|
64
|
-
info "unicorn is not running..."
|
65
|
-
end
|
45
|
+
%w[start stop restart upgrade].each do |action|
|
46
|
+
desc "#{action} unicorn"
|
47
|
+
task action do
|
48
|
+
on roles :app do
|
49
|
+
sudo :service, fetch(:unicorn_service), action
|
66
50
|
end
|
67
51
|
end
|
68
52
|
end
|
69
53
|
|
70
|
-
desc
|
71
|
-
task
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
54
|
+
desc 'restart unicorn'
|
55
|
+
task 'reload' do
|
56
|
+
on roles :app do
|
57
|
+
invoke "unicorn:unicorn_init" unless file_exists?(unicorn_initd_file)
|
58
|
+
invoke 'unicorn:setup_unicorn_config'
|
59
|
+
if test "[ -f #{fetch(:unicorn_pid)} ]"
|
60
|
+
sudo 'service', fetch(:unicorn_service), 'restart'
|
61
|
+
else
|
62
|
+
sudo 'service', fetch(:unicorn_service), 'start'
|
77
63
|
end
|
78
64
|
end
|
79
65
|
end
|
80
|
-
|
81
|
-
desc "Restart Unicorn (USR2); use this when preload_app: true"
|
82
|
-
task :restart do
|
83
|
-
invoke "unicorn:start"
|
84
|
-
on roles(fetch(:unicorn_roles)) do
|
85
|
-
within current_path do
|
86
|
-
info "unicorn restarting..."
|
87
|
-
execute :kill, "-s USR2", pid
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
desc "Duplicate Unicorn; alias of unicorn:restart"
|
93
|
-
task :duplicate do
|
94
|
-
invoke "unicorn:restart"
|
95
|
-
end
|
96
|
-
|
97
|
-
desc "Legacy Restart (USR2 + QUIT); use this when preload_app: true and oldbin pid needs cleanup"
|
98
|
-
task :legacy_restart do
|
99
|
-
invoke "unicorn:restart"
|
100
|
-
on roles(fetch(:unicorn_roles)) do
|
101
|
-
within current_path do
|
102
|
-
execute :sleep, fetch(:unicorn_restart_sleep_time)
|
103
|
-
if test("[ -e #{fetch(:unicorn_pid_path)}.oldbin ]")
|
104
|
-
execute :kill, "-s QUIT", pid_oldbin
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
desc "Add a worker (TTIN)"
|
111
|
-
task :add_worker do
|
112
|
-
on roles(fetch(:unicorn_roles)) do
|
113
|
-
within current_path do
|
114
|
-
info "adding worker"
|
115
|
-
execute :kill, "-s TTIN", pid
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
desc "Remove a worker (TTOU)"
|
121
|
-
task :remove_worker do
|
122
|
-
on roles(fetch(:unicorn_roles)) do
|
123
|
-
within current_path do
|
124
|
-
info "removing worker"
|
125
|
-
execute :kill, "-s TTOU", pid
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def pid
|
132
|
-
"`cat #{fetch(:unicorn_pid_path)}`"
|
133
66
|
end
|
134
67
|
|
135
|
-
|
136
|
-
|
68
|
+
namespace :deploy do
|
69
|
+
after :publishing, 'unicorn:reload'
|
137
70
|
end
|
@@ -1,36 +1,26 @@
|
|
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) %>"
|
6
3
|
|
7
|
-
|
8
|
-
|
4
|
+
listen "<%= fetch(:unicorn_sock_file) %>"
|
5
|
+
pid "<%= fetch(:unicorn_pid_file) %>"
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
# use correct Gemfile on restarts
|
13
|
-
before_exec do |server|
|
14
|
-
ENV['BUNDLE_GEMFILE'] = "#{app_path}/current/Gemfile"
|
15
|
-
end
|
7
|
+
stderr_path "<%= fetch(:unicorn_error_log_file) %>"
|
8
|
+
stdout_path "<%= fetch(:unicorn_log_file) %>"
|
16
9
|
|
17
10
|
preload_app true
|
18
11
|
|
19
12
|
before_fork do |server, worker|
|
20
|
-
|
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
|
13
|
+
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
|
25
14
|
|
26
|
-
|
27
|
-
|
28
|
-
old_pid = "#{server.config[:pid]}.oldbin"
|
29
|
-
if File.exists?(old_pid) && server.pid != old_pid
|
15
|
+
old_pid = "#{ server.config[:pid] }.oldbin"
|
16
|
+
unless old_pid == server.pid
|
30
17
|
begin
|
31
|
-
Process.kill
|
18
|
+
Process.kill :QUIT, File.read(old_pid).to_i
|
32
19
|
rescue Errno::ENOENT, Errno::ESRCH
|
33
|
-
# someone else did our job for us
|
34
20
|
end
|
35
21
|
end
|
36
22
|
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_file) %>
|
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_file) %>"
|
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
|