puma systemd脚本无法启动puma

时间:2019-01-04 16:20:10

标签: ruby-on-rails systemd puma

我一直在复制和粘贴以下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 个答案:

答案 0 :(得分:1)

  

此脚本有什么问题?

可能只是服务的类型:

  

主要PID:3239(代码=已退出,状态= 0 /成功)

似乎主要过程是分叉。尝试使用forking代替simplehttps://www.freedesktop.org/software/systemd/man/systemd.service.html#Options

答案 1 :(得分:0)

在我的情况下,我在 ExecStart 更新到这样的东西中有错误的命令ExecStart=/bin/bash -lc 'RAILS_ENV=production bundle exec puma -C /home/ubuntu/rails_current_server/config/puma.rb'

答案 2 :(得分: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

答案 3 :(得分:-1)

这是解决方案:

[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