Systemd节点应用无法启动 [英] Systemd node app failing to start

查看:241
本文介绍了Systemd节点应用无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个节点应用程序,我想将其添加为服务,如果我进入安装目录并执行node start.js,则该应用程序运行良好,但是当我执行systemctl start app时,它挂了一个几分钟,然后journalctl -u darknet显示:

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.

这是我的.service文件:

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

我尝试以普通用户和root身份运行该进程,并且工作正常..但是无论我尝试什么,如果从systemd开始,它都会出错.

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.

推荐答案

与流行的误解相反,systemd与传统的Unix初始化脚本概念大不相同.在此处进行了详细说明此处.我已经注意到,这里的很多人都在问关于使用systemd运行Node的问题,他们很少得到任何解决方案.我的建议是使用传统的SysV初始化脚本或Upstart,只要您发现无法使用systemd做某事,它们也就毫不奇怪了.我从未见过无法使用Upstart或SysV初始化脚本轻松运行Node应用程序的情况,但是我见过systemd的问题.我听说集群和其他更复杂的部署方案尤其有问题.只需遵循Unix的哲学,并使用简单的工具就可以完成一件事情,并且做得很好.初始化脚本并不那么复杂.

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.

另请参阅:

这篇关于Systemd节点应用无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆