运行 使用 Upstart 的 nodejs 应用程序
Running nodejs app using Upstart
我想通过 Upstart 自动启动我编写的 Node.js 应用程序。为此,我创建了以下 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:
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
当我直接通过 nodejs app.js
启动服务器时,它工作正常。目前我不知道是什么导致了这个问题。希望有人能帮助我。
问候西蒙
Cannot find module '/Aurora-Messenger/app.js'
表示该文件不存在或权限为用户www-data
无法读取。如果该文件确实存在,那么问题很可能出在 /root
目录的权限上。我不希望用户 www-data
能够访问用户 root
.
的主目录
我想通过 Upstart 自动启动我编写的 Node.js 应用程序。为此,我创建了以下 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:
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
当我直接通过 nodejs app.js
启动服务器时,它工作正常。目前我不知道是什么导致了这个问题。希望有人能帮助我。
问候西蒙
Cannot find module '/Aurora-Messenger/app.js'
表示该文件不存在或权限为用户www-data
无法读取。如果该文件确实存在,那么问题很可能出在 /root
目录的权限上。我不希望用户 www-data
能够访问用户 root
.