2016-12-14 65 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相同。至於爲什麼錯誤信息是這樣,我不確定我自己,並且也對答案感興趣。

相關問題