systemctl 抛出错误

systemctl 抛出错误

我刚刚开始学习 systemctl,我尝试创建一个将运行 nodejs 脚本的服务文件,但它无法运行,并且错误并没有真正告诉我原因。

以下是我已采取的步骤:

1)使用以下命令导航/lib/systemd/system并创建文件:

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它就可以正常工作 - 请告知我缺少什么

答案1

我设法通过回显这一行来解决它ExecStart=/usr/bin/node /home/dev/index.js,然后我看到脚本中有一个错误。

因此,为了将来的参考,请调试 ExecStart 以查看它是否确实有效。

相关内容