Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在计算机启动时启动节点服务器_Node.js_Ubuntu 16.04_Upstart - Fatal编程技术网

Node.js 在计算机启动时启动节点服务器

Node.js 在计算机启动时启动节点服务器,node.js,ubuntu-16.04,upstart,Node.js,Ubuntu 16.04,Upstart,我试图在使用upstart启动机器(ubuntu 16.04)时使用nodeserv.conf文件中的以下代码启动node.js服务器: #!upstart description "Node.js server" author "Sushant Kumar" start on started mountall stop on shutdown respawn respawn limit 99 5 script export APP_HOME = "/home/ubuntu/cha

我试图在使用upstart启动机器(ubuntu 16.04)时使用nodeserv.conf文件中的以下代码启动node.js服务器:

#!upstart
description "Node.js server"
author "Sushant Kumar"

start on started mountall
stop on shutdown

respawn
respawn limit 99 5

script
    export APP_HOME = "/home/ubuntu/chatbot_server"
    export HOME = "/home/ubuntu"
    cd $APP_HOME
    exec sudo -u ubuntu /usr/local/nodejs/bin/node $HOME/chatbot_server/server.js >> /var/log/chatbotserv.log 2>&1
end script

post-start script
    echo "Node Started"
end script
,但我运行命令

# start nodeserv
我得到以下错误:
>启动:作业启动失败
。 谁能帮我一下我哪里出了问题


编辑:此服务器托管在AWS EC2实例上(如果有帮助,我认为这与此无关,但只是以防万一)。

您可以通过将应用程序作为服务运行来实现这一点。可以使用以确保给定脚本连续运行。首先,您需要永远安装。然后转到项目目录并安装永久监视器。现在你可以启动你的应用程序了

npm install forever -g
cd /path/to/your/project
npm install forever-monitor
forever start app.js
现在,您需要使用将节点脚本构建为服务。首先,安装永久服务,然后将应用安装为服务

npm install -g forever-service
forever-service install test
如果要处理脚本,可以在脚本中替换此代码

export HOME="/root"
exec /usr/local/nodejs/bin/node /home/ubuntu/chatbot_server/server.js >> /var/log/node.log 2>&1
看一看

PM2是一个非常强大的Node.js流程管理器

安装应用程序后,您可以使用以下工具轻松地将其设置为启动:

sudo systemctl start pm2-yourusername

我不知道pm2,但我使用了永久服务,但它无法成功。我不想再使用任何模块/包,只想知道为什么这个脚本不能按预期工作。