Node.js 脚本无法以 systemctl 启动 [英] Node.js script failed to start with systemctl

查看:43
本文介绍了Node.js 脚本无法以 systemctl 启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 systemctl 从远程机器上自动运行我的 node.js 脚本.

I need to run my node.js script automatically from my remote machine with systemctl.

我已经制作了一个 .service 文件并将其放入 /etc/systemd/system/.这是 .service 文件:

I already made a .service file and put that into /etc/systemd/system/. Here's the .service file:

[Unit]
Description=laporan

[Service]
ExecStart=/var/www/laporan/nodeserver/server.js
Restart=always
User=nobody
Group=root
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/var/www/laporan/nodeserver

[Install]
WantedBy=multi-user.target

但是每次尝试启动服务时,都会返回如下错误(systemctl status laporan的输出):

But every time I try to start the service, it returns an error as follows (output of systemctl status laporan):

● laporan.service - laporan
   Loaded: loaded (/etc/systemd/system/laporan.service; enabled)
   Active: failed (Result: start-limit) since Mon 2016-09-12 09:15:06 WITA; 11min ago
  Process: 121690 ExecStart=/var/www/laporan/nodeserver/server.js (code=exited, status=203/EXEC)
 Main PID: 121690 (code=exited, status=203/EXEC)

Sep 12 09:15:05 kominfomdc systemd[1]: Unit laporan.service entered failed state.
Sep 12 09:15:06 kominfomdc systemd[1]: laporan.service start request repeated too quickly, refusing to start.
Sep 12 09:15:06 kominfomdc systemd[1]: Failed to start laporan.
Sep 12 09:15:06 kominfomdc systemd[1]: Unit laporan.service entered failed state.

这个错误到底是关于什么的?我错过了什么吗?

What exactly is this error about? Am I missing something?

推荐答案

我不认为这就是你启动节点应用程序的方式.您只是在此处指定 JavaScript 文件:

I don't think that's how you start a node app. You are just specifying the JavaScript file here:

ExecStart=/var/www/laporan/nodeserver/server.js

如果节点在路径中,您还需要指定节点可执行文件,如下所示.

You also need to specify the node executable, something like the following, if node is in the path.

ExecStart= node /var/www/laporan/nodeserver/server.js

如果节点不在可执行路径上,则必须提供它:

If node isn't on the executable path, you must provide it:

ExecStart=/usr/local/bin/node /var/www/laporan/nodeserver/server.js

这篇关于Node.js 脚本无法以 systemctl 启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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