I am trying to start a nodejs application with forever
(forever
simply restarts the program if it crashes), but forever
itself is not auto started on boot. So I am using upstart to initialize forever
.
I have tried hundreds of ways to achieve this (many trial and error attempts), but nothing really seems to work for me. So my scenarios is:
- I am running an Amazon Linux Instance
- The app works great if running from command line (forever is working and upstart also)
- I am testing with
sudo start prv
Here is the script I have so far (prv.conf, at /etc/init/prv.conf
):
author "Renato Gama"
description "PRV"
start on runlevel [235]
stop on shutdown
respawn
export HOME="/home/ec2-user/prv/app"
exec su -c "/usr/bin/forever start -l forever.log -o /home/ec2-user/prv/logs/out.log -e /home/ec2-user/prv/logs/err.log --append /home/ec2-user/prv/app.js" root | logger -t PRV
IN FACT, from command line I can start the app by typing the following (and this works as expected):
cd /home/ec2-user/prv
sudo su -p (altough I am not using any specific env variable)
forever start -l f.log -o out.log -e err.log --append app.js
PS1 .: I haven't even tested on real boot as it doesn't even work with sudo start prv
PS2 .: If I visit the log it doesn't tell to much (exited normally). Part of the log is in this gist
PS3 .: After executing sudo start prv
I got this
[ec2-user@ip-10-252-146-14 ~]$ sudo start prv
prv start/running, process 11477
But when I try to check if forever is running my proccess, it says:
[ec2-user@ip-10-252-146-14 ~]$ sudo forever list
info: No forever processes running
PS4.: My app binds to port 80
thats why I need a privileged user to run this.
EDIT: I am almost sure the problem is that I am getting EACCESS error on port 80
Best Answer
As shown in init(5), the export line is invalid (Upstart syntax is not shell). You need to specify:
Please see:
Also,
Finally,
Look in file
/var/log/upstart/yourjob.log
for job output.