ubuntu-16.04 – 无法为Puma创建systemd脚本

我在/ etc / systemd / system /中创建了一个名为“puma.service”的服务脚本,其中包含以下内容:

[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

我启用了该服务,启动时,我从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.

虽然,当我在SSH终端中发出命令时,服务器启动并运行完美.我必须在服务文件中进行任何更改吗?

注意:

>为方便起见,我更改了dirnames.
>我做了一些研究,状态127的原因是由于可执行文件不在路径中.但是,我想这不会是一个问题.

你能解开一些光吗?

最佳答案
我发现了问题并改变了ExecStart,如下所述,它就像一个魅力:

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应该从rbenv垫片中取出,而且puma的配置文件(config / puma.rb)和应用程序的配置文件(config.ru)可以在相对路径中给出.

转载注明原文:ubuntu-16.04 – 无法为Puma创建systemd脚本 - 代码日志