Puma的systemd脚本无法启动Puma。

4

我一直从多个来源复制和粘贴以下 Puma 系统启动脚本的片段,但它无法正常工作。系统是 Debian 9.6,用户 rails 已经通过 rvm 安装了 Ruby。用户 rails 可以运行命令 RAILS_ENV=production bundle exec puma -C /var/www/test-optimum/current/config/puma.rb --daemon

这个脚本有什么问题吗?

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

[Service]
Type=simple
User=rails
WorkingDirectory=/var/www/test-optimum/current
ExecStart=/bin/bash -lc 'RAILS_ENV=production bundle exec puma -C /var/www/test-optimum/current/config/puma.rb --daemon'
ExecStop=/home/rails/.rvm/bin/rvm default do bundle exec pumactl -S /var/www/test-optimum/shared/tmp/pids/puma.pid stop

PIDFile=/var/www/test-optimum/shared/tmp/pids/puma.pid
Restart=always

[Install]
WantedBy=multi-user.target

尝试使用systemctl start puma启动时,出现以下错误:
● test-puma.service - test Puma HTTP Server
  Loaded: loaded (/etc/systemd/system/test-puma.service; disabled; vendor preset: enabled)
  Active: failed (Result: exit-code) since Fri 2019-01-04 17:10:43 CET; 6min ago
  Process: 3351 ExecStop=/home/rails/.rvm/bin/rvm default do bundle exec pumactl -S /var/www/test-optimum/shared/tmp/pids/puma.pid stop (code=exited, status=1/FAILURE)
  Process: 3239 ExecStart=/bin/bash -lc RAILS_ENV=production bundle exec puma -C /var/www/test-optimum/current/config/puma.rb --daemon (code=exited, status=0/SUCCESS)
Main PID: 3239 (code=exited, status=0/SUCCESS)
      CPU: 1.179s

Jan 04 17:10:42 test.example.com systemd[1]: test-puma.service: Unit entered failed state.
Jan 04 17:10:42 test.example.com systemd[1]: test-puma.service: Failed with result 'exit-code'.
Jan 04 17:10:43 test.example.com systemd[1]: test-puma.service: Service hold-off time over, scheduling restart.
Jan 04 17:10:43 test.example.com systemd[1]: Stopped test Puma HTTP Server.
Jan 04 17:10:43 test.example.com systemd[1]: test-puma.service: Start request repeated too quickly.
Jan 04 17:10:43 test.example.com systemd[1]: Failed to start test Puma HTTP Server.
Jan 04 17:10:43 test.example.com systemd[1]: test-puma.service: Unit entered failed state.
Jan 04 17:10:43 test.example.com systemd[1]: test-puma.service: Failed with result 'exit-code'.
4个回答

11

这是解决方案:

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

[Service]
Type=simple
User=rails
WorkingDirectory=/var/www/test-optimum/current
ExecStart=/bin/bash -lc 'RAILS_ENV=production bundle exec puma -C /var/www/test-optimum/current/config/puma.rb'
ExecStop=/home/rails/.rvm/bin/rvm default do bundle exec pumactl -S /var/www/test-optimum/shared/tmp/pids/puma.pid stop

PIDFile=/var/www/test-optimum/shared/tmp/pids/puma.pid
Restart=always

[Install]
WantedBy=multi-user.target

1
他的解决方案对我有用。我也在使用RVM,Ubuntu 18。 - BSB
2
你救了我的一天。 - Iqbal Khan

0

0
一个改进的解决方案可能是:
[Unit]
Description=Test Puma HTTP Server
After=network.target

[Service]
Type=simple
User=rails
WorkingDirectory=/var/www/test-optimum/current
ExecStart=/home/rails/.rvm/bin/rvm default do bundle exec puma -C /var/www/test-optimum/current/config/puma.rb --daemon
ExecStop=/home/rails/.rvm/bin/rvm default do bundle exec pumactl -S /var/www/test-optimum/shared/tmp/pids/puma.pid stop

PIDFile=/var/www/test-optimum/shared/tmp/pids/puma.pid
Restart=always

[Install]
WantedBy=multi-user.target

-1

在我的情况下,我在ExecStart中使用了错误的命令,更新为类似以下内容即可解决问题:ExecStart=/bin/bash -lc 'RAILS_ENV=production bundle exec puma -C /home/ubuntu/rails_current_server/config/puma.rb'


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接