Reputation: 183
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
Upvotes: 0
Views: 172
Reputation: 70075
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
.
Upvotes: 1