capistrano-toolbox 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/capistrano-toolbox/helpers.rb +2 -2
- data/lib/capistrano-toolbox/unicorn.rb +26 -19
- metadata +1 -1
@@ -27,7 +27,7 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def remote_file_exists?(path)
|
31
|
-
'true' == capture("test -f #{path} && echo true || echo false").strip
|
30
|
+
def remote_file_exists?(path, options={})
|
31
|
+
'true' == capture("test -f #{path} && echo true || echo false", options).strip
|
32
32
|
end
|
33
33
|
end
|
@@ -4,30 +4,37 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
4
4
|
namespace :deploy do
|
5
5
|
namespace :unicorn do
|
6
6
|
task :restart, :roles => :app, :except => { :no_release => true } do
|
7
|
-
|
8
|
-
|
9
|
-
old_pid =
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
servers = find_servers roles: :app
|
8
|
+
servers.each do |server|
|
9
|
+
old_pid = nil
|
10
|
+
if remote_file_exists?(unicorn_pid, hosts: [server])
|
11
|
+
old_pid = capture("cat #{unicorn_pid}", hosts: [server])
|
12
|
+
cmd = "kill -s USR2 #{old_pid}"
|
13
|
+
else
|
14
|
+
cmd = "RAILS_ENV=production /etc/init.d/unicorn start"
|
15
|
+
end
|
14
16
|
|
15
|
-
|
17
|
+
run(cmd, shell: '/bin/bash', hosts: [server])
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
echo -n
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
sleep(1)
|
20
|
+
|
21
|
+
cmd = "echo -n ' Waiting for unicorn' ; while [ ! -s #{
|
22
|
+
unicorn_pid
|
23
|
+
} -o -s #{
|
24
|
+
unicorn_pid
|
25
|
+
}.oldbin ] ; do echo -n '.' ; sleep 1 ; done"
|
26
|
+
|
27
|
+
run(cmd, shell: '/bin/bash', hosts: [server]) do |channel, stream, data|
|
28
|
+
print(data)
|
29
|
+
end
|
24
30
|
|
25
|
-
|
31
|
+
new_pid = capture("cat #{unicorn_pid}", hosts: [server])
|
26
32
|
|
27
|
-
|
28
|
-
|
33
|
+
if new_pid == old_pid
|
34
|
+
raise "Unicorn failed to restart!"
|
35
|
+
end
|
29
36
|
end
|
30
37
|
end
|
31
38
|
end
|
32
39
|
end
|
33
|
-
end
|
40
|
+
end
|