[英]Running nodejs app using Upstart
I want to start my written Node.js App automatically through Upstart. 我想通过Upstart自动启动编写的Node.js应用程序。 For this purpose I created the following auroraserver.conf:
为此,我创建了以下auroraserver.conf:
#!upstart
description "Aurora Server"
author "Simon"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
# Automatically Respawn:
respawn # restart when job dies
respawn limit 10 5 # give up restart after 99 respawns in 5 seconds
script
export HOME="/root"
exec sudo -u www-data NODE_ENV="production" /usr/bin/nodejs /root/Aurora-Messenger/app.js >> /var/log/auroraserver.log 2>&1
echo "Forwarding traffic from port 89 to 5000" >> /var/log/auroraserver.log
exec iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 5000
end script
post-start script
# Date format same as (new Date()).toISOString() for consistency
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] Server was started" >> /var/log/auroraserver.log
end script
auroraserver.log: auroraserver.log:
Error: Cannot find module '/Aurora-Messenger/app.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
When I start the server directly through nodejs app.js
it works fine. 当我直接通过
nodejs app.js
启动服务器时,它工作正常。 At this moment I have no idea what could lead to this problem. 目前,我不知道什么会导致这个问题。 Hope someone can help me.
希望可以有人帮帮我。
Greetings Simon 问候西蒙
Cannot find module '/Aurora-Messenger/app.js'
indicates that the file does not exist or the permissions are such that it cannot be read by user www-data
. Cannot find module '/Aurora-Messenger/app.js'
表示该文件不存在或权限使得用户www-data
无法读取该文件。 If the file does exist, then it seems likely that the problem would be permissions on the /root
directory. 如果该文件确实存在,则问题可能出在
/root
目录上。 I wouldn't expect user www-data
to have access to the home directory for user root
. 我不希望用户
www-data
可以访问root
用户的主目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.