Shell script checks the program. If it fails, restart the program.

Source: Internet
Author: User

The script is as follows:

#! /Bin/sh # Name of the process to be checked progress_name = "heihu_server" # ------------------------------- # function: checkprogress # function: Check whether a process exists # parameter: $1 --- Name of the process to be checked # Return Value: If 0 exists, otherwise 1 is returned. # ------------------------------------- checkprogress () {# Check whether the input parameter is valid if ["$1" = ""]; then return 1 fi # $ process_num get the number of specified process names, if the value is 1, 0 is returned, indicating normal. If the value is not 1, 1 is returned, indicating that an error exists, process_num = 'ps-Ef | grep "$1" | grep-V "grep" | WC-l' if [$ process_num-EQ 1] needs to be restarted; Then return 0 else return 1 fi} # Check whether the test instance already exists while [1]; do checkprogress "$ progress_name" RET =$? If [$ ret-EQ 1]; then Echo "The Progress: $ progress_name is dead, I will start it right now! "# Killall-9 $ progress_name exec./$ progress_name & fi sleep 1 echo" sleep .. "done

 

Shell script checks the program. If it fails, restart the program.

Related Article

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.