Last active
February 20, 2024 12:03
-
-
Save renatoargh/f84d1c3884d6c59a3a1b to your computer and use it in GitHub Desktop.
Revisions
-
renatoargh renamed this gist
Feb 18, 2015 . 1 changed file with 9 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,22 @@ # Restarting Your Node.js App at Reboot Cronjob can prevent your application and your users from unexpected downtimes. Create a file called starter.sh in your application's home folder and copy the following code: ```bash #!/bin/sh if [ $(ps -e -o uid,cmd | grep $UID | grep node | grep -v grep | wc -l | tr -s "\n") -eq 0 ] then export PATH=/usr/local/bin:$PATH forever start --sourceDir /path/to/your/node/app main.js >> /path/to/log.txt 2>&1 fi ``` Where main.js should be replaced with your application's main script. Don't forget to make `starter.sh` executable with `chmod +x starter.sh` This useful snippet has been taken from here @@ -21,7 +25,10 @@ To start this script at each reboot you need to edit the crontab with this comma crontab -e and append the following code to this file ```bash @reboot /path/to/starter.sh ``` Now set the absolute path to your starter.sh file. Tip: Navigate where your starter.sh file is located and print the current directory with pwd. -
renatoargh created this gist
Nov 27, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ Restarting Your Node.js App at Reboot Cronjob can prevent your application and your users from unexpected downtimes. Create a file called starter.sh in your application's home folder and copy the following code: #!/bin/sh if [ $(ps -e -o uid,cmd | grep $UID | grep node | grep -v grep | wc -l | tr -s "\n") -eq 0 ] then export PATH=/usr/local/bin:$PATH forever start --sourceDir /path/to/your/node/app main.js >> /path/to/log.txt 2>&1 fi where main.js should be replaced with your application's main script. This useful snippet has been taken from here To start this script at each reboot you need to edit the crontab with this command: crontab -e and append the following code to this file @reboot /path/to/starter.sh Now set the absolute path to your starter.sh file. Tip: Navigate where your starter.sh file is located and print the current directory with pwd. Repeat the steps above for each of your domains/services. ///backed up form https://www.digitalocean.com/community/tutorials/how-to-host-multiple-node-js-applications-on-a-single-vps-with-nginx-forever-and-crontab