Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phased restart #329

Merged
merged 1 commit into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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