简体   繁体   中英

Running nodejs app using Upstart

I want to start my written Node.js App automatically through Upstart. For this purpose I created the following 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

When I start the server directly through nodejs app.js it works fine. 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 . If the file does exist, then it seems likely that the problem would be permissions on the /root directory. I wouldn't expect user www-data to have access to the home directory for user root .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM