Last active
August 29, 2015 14:04
-
-
Save defmech/0e57857d356b7df7227d to your computer and use it in GitHub Desktop.
How to restart a node script in forever after reboot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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