使用Upstart运行nodejs app

时间:2015-09-15 20:39:38

标签: node.js shell ubuntu 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启动服务器时,它运行正常。此刻我不知道是什么导致了这个问题。希望有人可以帮助我。

问候西蒙

1 个答案:

答案 0 :(得分:1)

<google-maps-api>表示该文件不存在或权限无法被用户Cannot find module '/Aurora-Messenger/app.js'读取。如果文件确实存在,那么问题似乎可能是www-data目录上的权限。我不希望用户/root有权访问用户www-data的主目录。