Because of the recently written node. JS program Because of some bugs, there will be some automatic exit problems, so it needs to be found in time when it exits, and restart
So looked up some information, wrote a bash program, the function is very simple, is every 3s to determine whether the node program at 6000 port is running, if not found 6000 port, then the command to execute the startup program, has been used for a period of time, feel good, simple and small, Safe and reliable, record for later use.
#!/bin/Bashbasedir='/server' while true; DoPro_now= ' netstat-tunlp|grep "6000"|WC-L2>/dev/NULL` if[$PRO _now-eq0]; ThenCD $BASEDIR node./bin/www >/tmp/run_node.log2>&1&Else Echo "' Date ' 6000 is listening ..." fi Sleep 3 Done
Basedir is the project directory, the program is very simple, flexible can "guard" a lot of programs
Start, you can use the Nohup,node program may be due to the bug exit, but start this with nohup but bash will not have any problems
Nohup./runing. SH
Isn't it convenient?
A minimalist Daemon bash script