2016-12-14 64 views
5
创建systemd脚本

我创建了/etc/systemd/system/名为"puma.service"具有下列内容的服务脚本:我启用了服务,开始的时候,我从systemctl得到以下日志无法为彪马

[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 

● 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终端中发出命令时服务器启动并运行完美。服务文件中是否有任何更改?

注:

  1. 我已经改变了dirnames中为您提供方便。
  2. 我做了一些研究,并且状态127的原因是由于可执行文件不在路径中。但是,我想这不会是一个问题。

你能说点什么吗?

回答

4

我发现这个问题,并改变了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垫片采取,也是彪马的配置文件(config/puma.rb)和应用程序的配置文件(config.ru)可以用相对路径给出。

+0

任何想法,如果这应该在rvm工作不同?我试过在rvm中使用相应的路径,仍然得到相同的结果 – unclesol

+0

对不起,我不知道。从未尝试rvm,我所有的部署脚本都在rbenv中。 –

0

解决它的一种方法是指定一个PID文件,systemd将查看该文件来检查服务状态。

下面是我们如何使用我们的脚本(适用于您的给定样本)

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 

留意,你可能通过你的-C puma.rb文件来配置,而不是--pidfile传递一个作为参数。我只是在这里展示它来说明--pidfile(在puma config中)应该与服务文件中的PIDFile相同。至于为什么错误信息是这样,我不确定我自己,并且也对答案感兴趣。

相关问题