capistrano: clean up unicorn:terminate task.
Do a SIGQUIT (graceful shutdown, allow workers to finish current request) before doing a SIGTERM (immediate shutdown).
This commit is contained in:
@@ -1,16 +1,25 @@
|
|||||||
|
# https://bogomips.org/unicorn/SIGNALS.html
|
||||||
namespace :unicorn do
|
namespace :unicorn do
|
||||||
desc "Terminate unicorn processes (blocks until complete)"
|
desc "Terminate unicorn processes (blocks until complete)"
|
||||||
task :terminate do
|
task :terminate do
|
||||||
on roles(:app) do
|
on roles(:app) do
|
||||||
execute "[[ -n $(pgrep -f unicorn) ]] && pgrep -f unicorn | xargs kill -SIGTERM"
|
within current_path do
|
||||||
sleep(5)
|
kill_unicorn("SIGQUIT")
|
||||||
|
sleep(10)
|
||||||
|
kill_unicorn("SIGTERM")
|
||||||
|
sleep(2)
|
||||||
|
kill_unicorn("SIGKILL")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Kills unicorn processes (blocks until complete)"
|
def unicorn_running?
|
||||||
task :kill do
|
test("[ -f #{fetch(:unicorn_pid)} ] && pkill --count --pidfile #{fetch(:unicorn_pid)}")
|
||||||
on roles(:app) do
|
end
|
||||||
execute "[[ -n $(pgrep -f unicorn) ]] && pgrep -f unicorn | xargs kill -SIGKILL"
|
|
||||||
|
def kill_unicorn(signal)
|
||||||
|
if unicorn_running?
|
||||||
|
execute :pkill, "--signal #{signal}", "--pidfile #{fetch(:unicorn_pid)}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user