Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save defmech/0e57857d356b7df7227d to your computer and use it in GitHub Desktop.
Save defmech/0e57857d356b7df7227d to your computer and use it in GitHub Desktop.
How to restart a node script in forever after reboot
First create a shell script like this one (I called mine start-APPNAME.sh):
#!/bin/sh
if [ $(ps aux | grep $USER | grep APPNAME.js | grep -v grep | wc -l | tr -s "\n") -eq 0 ]
then
export NODE_ENV=production
export PATH=/usr/local/bin:$PATH
forever start ~/example/APPNAME.js > /dev/null
fi
Then make the script executable:
chmod 700 start-APPNAME.sh
Now make cron run the script when the system is rebooted. Add this to your crontab (via crontab –e):
@reboot ~/start-APPNAME.sh >> cron.log 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment