简体   繁体   中英

Systemd node app failing to start

I have a node app, that I'm trying to add as a service, the app works fine if I go to the directory where it's installed and do node start.js however when I do systemctl start app it just hangs for a few mins then journalctl -u darknet shows:

Dec 24 01:46:33 Skynet systemd[1]: Started darknet.
Dec 24 01:46:33 Skynet systemd[1]: Starting darknet...
Dec 24 01:46:34 Skynet darknet[32246]: module.js:434
Dec 24 01:46:34 Skynet darknet[32246]: return process.dlopen(module, path._makeLong(filename));
Dec 24 01:46:34 Skynet darknet[32246]: ^
Dec 24 01:46:34 Skynet darknet[32246]: Error: Module version mismatch. Expected 46, got 51.
Dec 24 01:46:34 Skynet darknet[32246]: at Error (native)
Dec 24 01:46:34 Skynet darknet[32246]: at Object.Module._extensions..node (module.js:434:18)
Dec 24 01:46:34 Skynet darknet[32246]: at Module.load (module.js:343:32)
Dec 24 01:46:34 Skynet darknet[32246]: at Function.Module._load (module.js:300:12)
Dec 24 01:46:34 Skynet darknet[32246]: at Module.require (module.js:353:17)
Dec 24 01:46:34 Skynet systemd[1]: darknet.service: main process exited, code=exited, status=1/FAILURE
Dec 24 01:46:34 Skynet systemd[1]: Unit darknet.service entered failed state.
Dec 24 01:46:34 Skynet systemd[1]: darknet.service failed.

This is my .service file:

[Unit]
Description=darknet
After=network.target

[Service]
ExecStart=/usr/bin/node /home/botty/Darknet/start.js
Restart=always
RestartSec=180
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=darknet
User=botty
Group=botty
Environment=NODE_ENV=production
WorkingDirectory=/home/botty/Darknet

[Install]
WantedBy=multi-user.target

I tried running the process both as regular user and root and it works fine .. but no matter what I try it gives errors if started with systemd.

I had this problem. I wasn't using the same node version in systemd

$ which node
/usr/local/bin/node

Replacing /usr/bin/node with /usr/local/bin/node in ExecStart fixed it for me.

Contrary to a popular misconception, systemd is very different from traditional Unix concept of init scripts. It is explained in much more detail here and here . I have noticed that a lot of people here are asking about problems with running Node with systemd and they rarely get any solutions. My recommendation would be to use traditional SysV init scripts or Upstart that also works with no surprises whenever you see that you cannot do something with systemd. I have never seen situations where a Node application couldn't be easily run with Upstart or SysV init scripts but I've seen problems with systemd. I've heard that it is especially problematic with clustering and other more complicated deployment scenarios. Just follow the Unix philosophy and use simple tools that do one thing and do it well. Init scripts are not that complicated.

See also:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM