systemd服务无法启动nodejs

systemd服务无法启动nodejs

我正在尝试让我的 Nodejs 应用程序在启动时启动。如果我以 odroid 用户身份从命令行启动它,它运行得很好。

这是我的服务文件:

[Unit]
Description=ProImage
After=network.target mysql.service

[Service]
ExecStart=/bin/node /proimage/app.js
Restart=on-failure
RootDirectory=/proimage
WorkingDirectory=/proimage
User=root

[Install]
WantedBy=multi-user.target

当我跑步时:

sudo systemctl status proimage_daemon

我得到:

odroid@odroid:~$ sudo systemctl status proimage_daemon
● proimage_daemon.service - ProImage
   Loaded: loaded (/lib/systemd/system/proimage_daemon.service; enabled; vendor preset: enabled)
   Active: inactive (dead) (Result: exit-code) since Tue 2019-02-26 09:45:30 EST; 6s ago
  Process: 30797 ExecStart=/bin/node /proimage/app.js (code=exited, status=200/CHDIR)
 Main PID: 30797 (code=exited, status=200/CHDIR)

Feb 26 09:45:29 odroid systemd[1]: proimage_daemon.service: Unit entered failed state.
Feb 26 09:45:29 odroid systemd[1]: proimage_daemon.service: Failed with result 'exit-code'.
Feb 26 09:45:30 odroid systemd[1]: proimage_daemon.service: Service hold-off time over, scheduling restart.
Feb 26 09:45:30 odroid systemd[1]: Stopped ProImage.
Feb 26 09:45:30 odroid systemd[1]: proimage_daemon.service: Start request repeated too quickly.
Feb 26 09:45:30 odroid systemd[1]: Failed to start ProImage.

我使用以下方法查看了journalctl:

journalctl -u proimage_daemon.service

它给了我同样的以下内容:

odroid@odroid:~$ journalctl -u proimage_daemon.service --since 09:38
-- Logs begin at Tue 2019-02-26 09:02:47 EST, end at Tue 2019-02-26 10:02:34 EST. --
Feb 26 09:38:12 odroid systemd[1]: proimage_daemon.service: Trying to enqueue job proimage_daemon.service/stop/replace
Feb 26 09:38:12 odroid systemd[1]: proimage_daemon.service: Installed new job proimage_daemon.service/stop as 13040
Feb 26 09:38:12 odroid systemd[1]: proimage_daemon.service: Enqueued job proimage_daemon.service/stop as 13040
Feb 26 09:38:12 odroid systemd[1]: proimage_daemon.service: Job proimage_daemon.service/stop finished, result=done
Feb 26 09:38:12 odroid systemd[1]: Stopped ProImage ICU.
Feb 26 09:39:19 odroid systemd[1]: Started ProImage ICU.
Feb 26 09:39:19 odroid systemd[1]: proimage_daemon.service: Main process exited, code=exited, status=200/CHDIR
Feb 26 09:39:19 odroid systemd[1]: proimage_daemon.service: Unit entered failed state.
Feb 26 09:39:19 odroid systemd[1]: proimage_daemon.service: Failed with result 'exit-code'.
Feb 26 09:39:19 odroid systemd[1]: proimage_daemon.service: Service hold-off time over, scheduling restart.
Feb 26 09:39:19 odroid systemd[1]: Stopped ProImage ICU.

我看了十几篇关于这个问题的帖子。他们都说 status=200/CHDIR 表明工作目录有问题。

就我而言,工作目录肯定存在并且由 root 用户拥有。我已将此目录的权限递归设置为 777。我已经对服务文件尝试了很多不同的方法,但都无济于事。

有人对我的问题有什么建议吗?

答案1

根据systemd 执行文档,设置RootDirectory类似于 chroot。与设置结合使用WorkingDirectory,这意味着 systemd 正在将您的应用程序 chroot 到/proimage,然后尝试在该目录中cd /proimage,这将转换为/proimage/proimage.

如果您不需要 chroot 进程,请删除该RootDirectory指令。如果您打算 chroot 进程,请删除该WorkingDirectory指令。

相关内容