Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create systemd script for Puma

I created a service script named "puma.service" in /etc/systemd/system/ with the following contents:

[Unit]
Description=Puma HTTP Server
After=network.target

[Service]
Type=simple

User=ubuntu

WorkingDirectory=/home/username/appdir/current

ExecStart=/bin/bash -lc "/home/username/appdir/current/sbin/puma -C /home/username/appdir/current/config/puma.rb /home/username/appdir/current/config.ru"

Restart=always

[Install]
WantedBy=multi-user.target

I enabled the service and when started, I'm getting the following log from systemctl:

● puma.service - Puma HTTP Server
   Loaded: loaded (/etc/systemd/system/puma.service; enabled; vendor preset: enabled)
   Active: inactive (dead) (Result: exit-code) since Wed 2016-12-14 10:09:46 UTC; 12min ago
  Process: 16889 ExecStart=/bin/bash -lc cd /home/username/appdir/current && bundle exec puma -C /home/username/appdir..
 Main PID: 16889 (code=exited, status=127)

Dec 14 10:09:46 ip-172-31-29-40 systemd[1]: puma.service: Main process exited, code=exited, status=127/n/a
Dec 14 10:09:46 ip-172-31-29-40 systemd[1]: puma.service: Unit entered failed state.
Dec 14 10:09:46 ip-172-31-29-40 systemd[1]: puma.service: Failed with result 'exit-code'.
Dec 14 10:09:46 ip-172-31-29-40 systemd[1]: puma.service: Service hold-off time over, scheduling restart.
Dec 14 10:09:46 ip-172-31-29-40 systemd[1]: Stopped Puma HTTP Server.
Dec 14 10:09:46 ip-172-31-29-40 systemd[1]: puma.service: Start request repeated too quickly.
Dec 14 10:09:46 ip-172-31-29-40 systemd[1]: Failed to start Puma HTTP Server.

Although, when I give the command in SSH terminal the server started and was running perfect. Is there any changes I have to make in the service file?

Note:

  1. I have changed the dirnames for your convenience.
  2. I did some research and the cause of status 127 is due to the executable not in the path. But, I guess that won't be a problem.

Can you shed some light?

like image 450
Gowtham Avatar asked Dec 14 '16 10:12

Gowtham


1 Answers

I found the problem and changed the ExecStart as mentioned below and it worked like a charm:

ExecStart=/home/username/.rbenv/shims/bundle exec puma -e production -C ./config/puma.rb config.ru
PIDFile=/home/username/appdir/shared/tmp/pids/puma.pid

bundle should be taken from the rbenv shims and also the puma's config file (config/puma.rb) and application's config file (config.ru) can be given in relative path.

like image 66
Gowtham Avatar answered Oct 26 '22 12:10

Gowtham