2017-03-05 236 views
1

我使用http-server來服務一個簡單的Angular應用程序。當我從bash運行它時,應用程序運行正常。但是當我嘗試從systemd單元文件運行時,它會失敗。http-server無法在systemd中啓動

這是我用來運行它的systemd單元文件。

[Unit] 
Description=web_app 
Requires=network.target 
After=multi-user.target 

[Service] 
ExecStart=/usr/bin/http-server -p 80 
Type=forking 
WorkingDirectory=/home/ubuntu/jenkins/workspace/deepcareweb_dev 
Restart=always 
RestartSec=10       
StandardOutput=syslog    
StandardError=syslog     
SyslogIdentifier=web_app 
User=root 
#Group=<alternate group> 
#Environment=NODE_ENV=production PORT=1337 

[Install] 
WantedBy=multi-user.target 

我應該怎麼做,從systemd單元文件運行http-server

編輯1:systemctl status

$ sudo systemctl status web_app 


● web_app.service - web_app 
    Loaded: loaded (/etc/systemd/system/web_app.service; enabled; vendor preset: enabled) 
    Active: inactive (dead) (Result: exit-code) since Sun 2017-03-05 06:17:14 UTC; 10s ago 
    Process: 1879 ExecStart=/usr/bin/http-server -p 80 (code=exited, status=200/CHDIR) 
Main PID: 1354 (code=exited, status=200/CHDIR) 

Mar 05 06:17:14 ip-172-31-22-251 systemd[1]: web_app.service: Control process exited, code=exited status=200 
Mar 05 06:17:14 ip-172-31-22-251 systemd[1]: Failed to start web_app. 
Mar 05 06:17:14 ip-172-31-22-251 systemd[1]: web_app.service: Unit entered failed state. 
Mar 05 06:17:14 ip-172-31-22-251 systemd[1]: web_app.service: Failed with result 'exit-code'. 
Mar 05 06:17:14 ip-172-31-22-251 systemd[1]: web_app.service: Service hold-off time over, scheduling restart. 
Mar 05 06:17:14 ip-172-31-22-251 systemd[1]: Stopped web_app. 
Mar 05 06:17:14 ip-172-31-22-251 systemd[1]: web_app.service: Start request repeated too quickly. 
Mar 05 06:17:14 ip-172-31-22-251 systemd[1]: Failed to start web_app. 
+0

你如何運行它,你得到什麼錯誤? –

+0

@BurhanKhalid當我運行'sudo systemctl start web_app'時,它表示'Job for web_app.service失敗,因爲控制進程退出並顯示錯誤代碼。有關詳細信息,請參閱「systemctl status web_app.service」和「journalctl -xe」。# –

+0

...以及日誌說的是什麼? 'systemctl status web_app'? –

回答

0

嘗試刪除「重啓=總是」行,因爲它是觸發「開始的請求重複過快」的錯誤。刪除它後,你應該有一個真正的錯誤信息。

在我的情況下錯誤「步驟CHDIR產卵的/ usr/local/bin目錄/ HTTP服務器失敗:沒有這樣的文件或目錄」

更改「WorkingDirectory」變量「/」和「ExecStart 「到」/ usr/bin/http-server WORKING DIRECTORY -p 80「爲我解決了它。