Skip to content

Commit

Permalink
systemd phased restart feature (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
mksvdmtr authored Sep 2, 2021
1 parent e4ffe6d commit 7406c97
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/capistrano/puma/systemd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Puma::Systemd < Capistrano::Plugin
include PumaCommon

def register_hooks
after 'deploy:finished', 'puma:restart'
after 'deploy:finished', 'puma:reload'
end

def define_tasks
Expand Down
16 changes: 16 additions & 0 deletions lib/capistrano/tasks/systemd.rake
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ namespace :puma do
end
end

desc 'Reload Puma service via systemd'
task :reload do
on roles(fetch(:puma_role)) do
service_ok = execute("#{fetch(:puma_systemctl_bin)} --user status #{fetch(:puma_service_unit_name)} > /dev/null", raise_on_non_zero_exit: false)
cmd = 'reload'
if !service_ok
cmd = 'restart'
end
if fetch(:puma_systemctl_user) == :system
sudo "#{fetch(:puma_systemctl_bin)} #{cmd} #{fetch(:puma_service_unit_name)}"
else
execute "#{fetch(:puma_systemctl_bin)}", "--user", cmd, fetch(:puma_service_unit_name)
end
end
end

desc 'Get Puma service status via systemd'
task :status do
on roles(fetch(:puma_role)) do
Expand Down
2 changes: 1 addition & 1 deletion lib/capistrano/templates/puma.service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WorkingDirectory=<%= current_path %>
# Support older bundler versions where file descriptors weren't kept
# See https://github.com/rubygems/rubygems/issues/3254
ExecStart=<%= expanded_bundle_command %> exec --keep-file-descriptors puma -C <%= fetch(:puma_conf) %>
ExecReload=/bin/kill -TSTP $MAINPID
ExecReload=/bin/kill -USR1 $MAINPID
StandardOutput=append:<%= fetch(:puma_access_log) %>
StandardError=append:<%= fetch(:puma_error_log) %>
<%="EnvironmentFile=#{fetch(:puma_service_unit_env_file)}" if fetch(:puma_service_unit_env_file) %>
Expand Down

0 comments on commit 7406c97

Please sign in to comment.