Unable to create systemd script for Puma

I created a script service called "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 turned on the service and when I started, I get 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 provide the command in the SSH terminal, the server starts up and works fine. Are there any changes I have to make to the service file?

Note:

  • I changed the dirnames for your convenience.
  • I did some research, and the reason for status 127 is related to an executable that is not in the way. But, I think this is not a problem.

Can you shed some light?

+5
source share
2 answers

I found the problem and modified ExecStart as follows, 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 gasket, as well as the puma configuration file ( config/puma.rb ), and the application configuration file ( config.ru ) can be specified in the relative path.

+5
source

One way to resolve this issue is to specify the PID file, and systemd will examine this file to check the status of the service.

Here we use it in our scripts (adapted to your sample)

 ExecStart=/bin/bash -lc '/home/username/appdir/current/sbin/puma -C /home/username/appdir/current/config/puma.rb /home/username/appdir/current/config.ru --pidfile /home/username/appdir/current/tmp/pids/puma.pid' PIDFile=/home/username/appdir/current/tmp/pids/puma.pid 

Note that you may need to configure --pidfile through your -C puma.rb file instead of passing it as a parameter. I just show it here to illustrate that --pidfile (in puma configuration) should be the same as the PIDFile in the service file.

As for the error message, I'm not sure myself and am also interested in the answer.

0
source

Source: https://habr.com/ru/post/1261254/


All Articles