I'd like to keep my unit files in source control (e.g. in config), such that after a capistrano deploy, the unit will be copied to the systemd dir, and the service (e.g. puma) will be restarted. What would be the best way to achieve this?
I've thought simply adding a post-deploy task such as (untested code)
namespace :deploy do
[...]
before :published, :systemd
desc 'systemd'
task :systemd do
on roles(:web), in: :groups, limit: 3, wait: 10 do
within release_path do
execute "sudo cp config/puma.service /etc/systemd/system/puma.service"
execute "sudo cp config/puma-init /usr/bin/puma-init"
execute "sudo systemctl daemon-reload"
execute "sudo systemctl restart puma"
end
end
end
end
This seems to work, but I still wonder if there's a more elegant solution
namespace :deploy do
[...]
before :published, :systemd
desc 'systemd integration'
task :systemd do
on roles(:web), in: :groups, limit: 3, wait: 10 do
within shared_path do
execute "sudo cp #{shared_path}/config/puma.service /etc/systemd/system/puma.service"
execute "sudo cp #{shared_path}/config/puma-init /usr/bin/puma-init"
execute "sudo systemctl daemon-reload"
execute "sudo systemctl restart puma"
end
end
end
end
Also, note that you need to
set :pty, true
Otherwise sudo won't work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With