Linux Daemon Shell Script __linux

Source: Internet
Author: User

http://blog.csdn.net/special23/article/details/52690057


Service-side programs generally need long-term background stable operation, in addition to ensuring the robustness of the program itself, but also need to use some daemons.


Now share a simple shell script in the way:

#! /bin/sh
#进程名字可修改
pro_name=rails
cmd= "nohup bundle exec Rails Server Webrick-p3000-b 0.0.0.0-e-production & Gt;/dev/null 2>&1-d & "While
true: do
     #用ps获取 $PRO number of _name processes
     num= ' ps aux | grep-w ${pro_name} | gre p-v grep |wc-l '
     #echo $NUM
     #少于1, restart process
     if ["${num}"-lt "1"];then
         echo "${pro_name} was killed"
         $CM D
    #大于1, kill all Processes, reboot
    elif ["${num}"-gt "1"];then
        echo "More than 1 ${pro_name},killall ${pro_name}"
        Killall-9 $PRO _name
        $CMD
     fi
     #kill僵尸进程
     num_stat= ' ps aux | grep-w ${pro_name} | grep T | grep-v grep | Wc-l '
     if ["${num_stat}"-gt "0"];then
         killall-9 ${pro_name}
         $CMD
    fi sleep
     5s
done

Exit 0

Script Saved as xxx.sh

Set script execution permissions chmod 777 xxx.sh

Console execution:./xxx.sh This ensures that there is always a XXXX program running.

Need to keep running in the background: nohup ./xxx.sh &

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.