I'm trying to get my nodejs app to start on boot. It runs fine if I start it from the command line as the user odroid.
Here is my service file:
[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
When I run:
sudo systemctl status proimage_daemon
I get:
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.
I've looked at journalctl using:
journalctl -u proimage_daemon.service
and it gives me the same the following:
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.
I've looked at a dozen posts about this problem. They all say status=200/CHDIR indicates a problem with the working directory.
In my case, the working directory definitely exists and it is owned by root. I've set the permissions to 777 recursively on this directory. I've tried lots of different things with the service file, all to no avail.
Does anyone have a suggestion as to what may be my problem?
Best Answer
Per the systemd exec documentation, setting
RootDirectory
is akin to a chroot. In combination with settingWorkingDirectory
, it means that systemd is chrooting your app to/proimage
and then attempting within that directory tocd /proimage
, which would translate to/proimage/proimage
.If you don't need to chroot the process, eliminate the
RootDirectory
directive. If you intend to chroot the process, eliminate theWorkingDirectory
directive.