Skip to content

Instantly share code, notes, and snippets.

@hubertursua
Last active December 7, 2018 17:53
Show Gist options
  • Save hubertursua/003eaf2e06924a0389fe to your computer and use it in GitHub Desktop.
Save hubertursua/003eaf2e06924a0389fe to your computer and use it in GitHub Desktop.
NodeJS, Forever, and Upstart (Ubuntu)
#!upstart
start on filesystem and started networking
stop on shutdown
expect fork
setuid ubuntu
env HOME="/home/ubuntu"
env NODE_ENV="production"
env MIN_UPTIME="5000"
env SPIN_SLEEP_TIME="2000"
chdir /home/ubuntu/myapp
env APP_EXEC="bin/www"
env UID="myapp"
script
exec forever --uid="$UID" -a --minUptime=$MIN_UPTIME --spinSleepTime=$SPIN_SLEEP_TIME start $APP_EXEC
end script
pre-stop script
exec forever stop "$UID"
end script
@hubertursua
Copy link
Author

Place in /etc/init and make sure it is executable.

To start/stop, use sudo start name_of_file_without_conf and sudo stop name_of_file_without_conf

@Granjow
Copy link

Granjow commented Oct 2, 2015

For anybody using this script, the quotation marks in "$UID" are quite mandatory because otherwise forever will treat it as file name and not as UID. Just so you don’t make the same mistake.

@divyanshu-better-butter
Copy link

Does this script automatically respawn forever ?

@fouad-j
Copy link

fouad-j commented Nov 28, 2016

thanks for this interesting code but using UID is deprecated referring to documentation https://github.com/foreverjs/forever
for other solution check this thread http://stackoverflow.com/questions/13385029/automatically-start-forever-node-on-system-restart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment