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

标签 ubuntu-16.04 puma systemd

我创建了一个名为 "puma.service" 的服务脚本在 /etc/systemd/system/内容如下:

[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 终端中给出命令时,服务器启动并运行良好。我必须在服务文件中进行任何更改吗?

注:
  • 为了您的方便,我已经更改了目录名。
  • 我做了一些研究,状态 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 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41140312/

    相关文章:

    intellij-idea - intellij 导航回快捷方式不起作用

    serial-port - 使用在 Flatpak 中运行的应用程序访问串行端口

    linux - 在 Ubuntu 16.04 中启动 kdevelop 时出错

    amazon-web-services - aws ubuntu 16.04 服务器上的 HTTPS

    ruby-on-rails - 在 Heroku 上设置 Puma Worker 数量

    node.js - 无法使用 systemd 运行 Node 应用程序

    ruby-on-rails - Sidekiq错误: could not connect to server: No such file or directory

    ruby-on-rails - Rails、ActionController::Live、Puma:ThreadError

    MySQL 5.6 默认存储引擎是 MyISAM 而不是 InnoDB

    Debian Jessie 陷入 systemd-fsck 困境