Failure to restart puma after capistrano deployment

Viewed 940

I'm trying to deploy a rails app from my machine to an aws linux ec2 using capistrano.

I used the bundle exec cap production deploy command and it actually deploys a new release to the server successfully but it fails to (re)start puma. At the puma restart phase I get this error (For privacy, I replaced the actual app name in the error with <app-name>):

01:23 puma:restart
      01 sudo /bin/systemctl restart puma_<app-name>_production
      01 Failed to restart puma_<app-name>_production.service: Unit puma_<app-name>_production.service not found.
      01
#<Thread:0x00007f93fb8d2700@/Users/sary/.rvm/gems/ruby-2.6.4/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
        12: from /Users/sary/.rvm/gems/ruby-2.6.4/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
        11: from /Users/sary/.rvm/gems/ruby-2.6.4/gems/sshkit-1.21.2/lib/sshkit/backends/abstract.rb:31:in `run'
        10: from /Users/sary/.rvm/gems/ruby-2.6.4/gems/sshkit-1.21.2/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
         9: from /Users/sary/.rvm/gems/ruby-2.6.4/bundler/gems/capistrano-puma-f9801f6762d1/lib/capistrano/tasks/systemd.rake:105:in `block (3 levels) in eval_rakefile'
         8: from /Users/sary/.rvm/gems/ruby-2.6.4/bundler/gems/capistrano-puma-f9801f6762d1/lib/capistrano/puma/systemd.rb:55:in `execute_systemd'
         7: from /Users/sary/.rvm/gems/ruby-2.6.4/bundler/gems/capistrano-puma-f9801f6762d1/lib/capistrano/puma/systemd.rb:48:in `sudo_if_needed'
         6: from /Users/sary/.rvm/gems/ruby-2.6.4/gems/capistrano-3.12.0/lib/capistrano/dsl.rb:44:in `sudo'
         5: from /Users/sary/.rvm/gems/ruby-2.6.4/gems/sshkit-1.21.2/lib/sshkit/backends/abstract.rb:80:in `execute'
         4: from /Users/sary/.rvm/gems/ruby-2.6.4/gems/sshkit-1.21.2/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute'
         3: from /Users/sary/.rvm/gems/ruby-2.6.4/gems/sshkit-1.21.2/lib/sshkit/backends/abstract.rb:148:in `tap'
         2: from /Users/sary/.rvm/gems/ruby-2.6.4/gems/sshkit-1.21.2/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute'
         1: from /Users/sary/.rvm/gems/ruby-2.6.4/gems/sshkit-1.21.2/lib/sshkit/backends/netssh.rb:170:in `execute_command'
/Users/sary/.rvm/gems/ruby-2.6.4/gems/sshkit-1.21.2/lib/sshkit/command.rb:97:in `exit_status=': sudo exit status: 5 (SSHKit::Command::Failed)
sudo stdout: Failed to restart puma_<app-name>_production.service: Unit puma_<app-name>_production.service not found.
sudo stderr: Nothing written
        1: from /Users/sary/.rvm/gems/ruby-2.6.4/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/sary/.rvm/gems/ruby-2.6.4/gems/sshkit-1.21.2/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing on host 54.78.252.112: sudo exit status: 5 (SSHKit::Runner::ExecuteError)
sudo stdout: Failed to restart puma_<app-name>_production.service: Unit puma_<app-name>_production.service not found.
sudo stderr: Nothing written
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host 54.78.252.112: sudo exit status: 5
sudo stdout: Failed to restart puma_<app-name>_production.service: Unit puma_<app-name>_production.service not found.
sudo stderr: Nothing written


Caused by:
SSHKit::Command::Failed: sudo exit status: 5
sudo stdout: Failed to restart puma_<app-name>_production.service: Unit puma_<app-name>_production.service not found.
sudo stderr: Nothing written

Tasks: TOP => puma:restart
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing on host 54.78.252.112: sudo exit status: 5
sudo stdout: Failed to restart puma_<app-name>_production.service: Unit puma_<app-name>_production.service not found.
sudo stderr: Nothing written


** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:

Disclaimer: I inherited this deployment process from a previous engineer so rails/puma/capistrano aren't my specialty.Any help is greatly appreciated.

1 Answers

It appears like you do not have a puma service unit file yet on your Production server. You can create one at, /etc/systemd/system/puma_<app-name>_production.service.

You should add a Unit entry into the service file. Refer to this, https://gist.github.com/arteezy/5d53d99f6ee617fae1f0db0576fdd418

Once you have created this. Next step is to test this service:

$ systemctl start puma_<app_name>_production.service 
$ systemctl status puma_<app_name>_production.service # Check status is running

In case the puma service doesn't start, thoroughly check the paths mentioned in your service file.

If this still persists, hope this unblocks you to make progress.

Related