我试图在使用systemd引导系统时自动运行以下命令。
/usr/bin/node /var/www/html/rest-api/dist/index.js
我已经通过手动运行这个命令来验证它的工作,但是当我尝试用一个rest.service
文件启动它时,我会得到错误。
rest.service:
[Unit]
Description=REST API
After=network.target
[Service]
ExecStart=/usr/bin/node /var/www/html/rest-api/dist/index.js
Restart=always
User=nobody
Group=nobody
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/var/www/rest-api/dist
[Install]
WantedBy=multi-user.target
journalctl -u rest-api
输出:
其中rest.service
用户和组=任何人:
Oct 06 02:10:28 ip-172-31-26-208 systemd[7172]: rest-api.service: Failed at step GROUP spawning /usr/bin/node: No such process
Oct 06 02:10:28 ip-172-31-26-208 systemd[1]: rest-api.service: Main process exited, code=exited, status=216/GROUP
Oct 06 02:10:28 ip-172-31-26-208 systemd[1]: rest-api.service: Unit entered failed state.
Oct 06 02:10:28 ip-172-31-26-208 systemd[1]: rest-api.service: Failed with result 'exit-code'.
Oct 06 02:10:29 ip-172-31-26-208 systemd[1]: rest-api.service: Service hold-off time over, scheduling restart.
Oct 06 02:10:29 ip-172-31-26-208 systemd[1]: Stopped REST API.
其中rest.service
User & Group = root:
Oct 06 02:20:11 ip-172-31-26-208 systemd[1]: Started REST API.
Oct 06 02:20:11 ip-172-31-26-208 systemd[1]: rest-api.service: Main process exited, code=exited, status=200/CHDIR
Oct 06 02:20:11 ip-172-31-26-208 systemd[1]: rest-api.service: Unit entered failed state.
Oct 06 02:20:11 ip-172-31-26-208 systemd[1]: rest-api.service: Failed with result 'exit-code'.
Oct 06 02:20:12 ip-172-31-26-208 systemd[1]: rest-api.service: Service hold-off > time over, scheduling restart.
Oct 06 02:20:12 ip-172-31-26-208 systemd[1]: Stopped REST API.
有什么解决办法吗?
发布于 2016-10-06 05:09:34
code=exited, status=200/CHDIR
是您的关键错误消息。
它表示在您的服务试图运行时,/var/www/rest-api/dist
不存在或无法访问。
如果它是通过网络挂载的,After=network.target
并不一定意味着已经安装了任何给定的网络挂载。它甚至有可能,一个缓慢的启动本地驱动器可能还没有被安装。要查看您是否处于竞争状态,请尝试添加一个延迟,或者可能使用RequiresMountsFor=
,甚至ConditionPathExists=
。
来源:https://www.freedesktop.org/software/systemd/man/systemd.unit.html
发布于 2022-11-20 13:37:21
我面临着类似的情况,我让所有文件夹都正确存在,但得到了相同的错误。我通过更改"User“参数使其工作。我把它设为根然后开始工作。菲伊。
https://askubuntu.com/questions/833636
复制相似问题