diff --git a/lib/capistrano/puma/systemd.rb b/lib/capistrano/puma/systemd.rb index 49f31cc..4eca408 100644 --- a/lib/capistrano/puma/systemd.rb +++ b/lib/capistrano/puma/systemd.rb @@ -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 diff --git a/lib/capistrano/tasks/systemd.rake b/lib/capistrano/tasks/systemd.rake index dee09a6..781ea2d 100644 --- a/lib/capistrano/tasks/systemd.rake +++ b/lib/capistrano/tasks/systemd.rake @@ -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 diff --git a/lib/capistrano/templates/puma.service.erb b/lib/capistrano/templates/puma.service.erb index ba7368c..28265c4 100644 --- a/lib/capistrano/templates/puma.service.erb +++ b/lib/capistrano/templates/puma.service.erb @@ -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) %>