我刚开始学习 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
3) 打字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
就可以了 - 请告知我缺少的内容