A minimalist Daemon bash script

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.