我刚刚开始了解systemctl,我尝试创建一个将运行nodejs脚本的服务文件,但是它失败了,并且错误并没有真正告诉我原因。
以下是我所采取的步骤:
1)导航到/lib/systemd/system并使用以下命令创建了一个文件:
sudo nano /lib/systemd/system/hello_env.service2)创建了以下服务文件:
[Unit]
Description=
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/node /home/dev/index.js
Restart=always
[Install]
WantedBy=multi.user.target3)类型sudo systemctl daemon-reload
4)启动这一进程:
sudo systemctl start hello_env5)检查状态:
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运行脚本,它工作得很好--请告诉我缺少了什么
发布于 2020-02-02 11:19:53
我试图通过回显这一行ExecStart=/usr/bin/node /home/dev/index.js来解决这个问题,然后我看到脚本中出现了一个错误。
因此,为了将来的参考,调试ExecStart以确保它实际工作。
https://unix.stackexchange.com/questions/564751
复制相似问题