Systemctl
systemctl 拋出錯誤
我剛開始學習 systemctl,我嘗試創建一個將執行 nodejs 腳本的服務文件,但它無法執行,並且錯誤並沒有真正告訴我原因。
以下是我採取的步驟:
/lib/systemd/system
1)使用以下命令導航到並創建一個文件:sudo nano /lib/systemd/system/hello_env.service
2)創建以下服務文件:
[Unit] Description= After=network.target [Service] Type=simple ExecStart=/usr/bin/node /home/dev/index.js Restart=always [Install] WantedBy=multi.user.target
- 打字
sudo systemctl daemon-reload
4)啟動過程:
sudo systemctl start hello_env
5)檢查狀態:
sudo systemctl status hello_env
並得到以下錯誤:
> hello_env.service Loaded: loaded > (/lib/systemd/system/hello_env.service; disabled; vendor pres > Active: failed (Result: exit-code) since Wed 2020-01-29 16:00:37 IST; > 2s ago Process: 25605 ExecStart=/usr/bin/node > /home/dev/index.j Main PID: 25605 (code=exited, > status=1/FAILURE) > > Jan 29 16:00:37 sf-env systemd[1]: hello_env.service: Main process > exited, code Jan 29 16:00:37 sf-env systemd[1]: hello_env.service: > Failed with result 'exit- Jan 29 16:00:37 sf-env systemd[1]: > hello_env.service: Service hold-off time ove Jan 29 16:00:37 sf-env > systemd[1]: hello_env.service: Scheduled restart job, re Jan 29 > 16:00:37 sf-env systemd[1]: Stopped index.js - starting the bot. Jan > 29 16:00:37 sf-env systemd[1]: hello_env.service: Start request > repeated to Jan 29 16:00:37 sf-env systemd[1]: hello_env.service: > Failed with result 'exit- Jan 29 16:00:37 sf-env systemd[1]: Failed to > start index.js.
請注意,如果我導航到
/home/dev/index.js
並使用它執行腳本node index.js
就可以了 - 請告知我缺少的內容
我設法通過回顯這一行來解決它
ExecStart=/usr/bin/node /home/dev/index.js
,然後我看到腳本中有錯誤。因此,為了將來參考,調試 ExecStart 以查看它是否確實有效。