Simple solution for Linux server process monitoring and automatic restart

Source: Internet
Author: User

Reprint please indicate the source: The Curtain Roll westerly column (Http://blog.csdn.net/ljxfblog)

Starting this week, the novice tour to delete files sealed test stage, the first two days performance is OK, today after the update several times the outage behavior, compared to affect the player's test and experience, our server management system has not been perfected, in order to prevent downtime in the evening to cause loss, first with a simple solution temporarily replaced.

The principle of implementation is to use the crontab mechanism provided by Linux, to periodically query the existence of the server process, if the outage is processed by our pre-set script.

First we have to add a new task to crontab.

# CRONTAB-E: Into the editing state, is actually using VI editing.

*/1 * * * * sh/root/monitor.sh

I'm just simply setting up to call a shell script monitor.sh per minute. Here can be configured more powerful, you can go to search the crontab tutorial, online There are many such tutorials.

It is important to note that many of the tutorials are configured to use /root/monitor.shdirectly when I set the command, I found that this configuration will not execute the shell script, before adding SH can be executed.

Then we started writing monitor.sh this shell script.

#! /bin/sh    proc_name= "worldframe_d"        #进程名  proc_num ()                      #查询进程数量 {    num= ' ps-ef | grep $proc _name | grep-v grep | Wc-l '    return $num}proc_num  number=$?                       #获取进程数量if [$number-eq 0]            #如果进程数量为0then                            #重新启动服务器, or extend other content.    cd/longwen/server/sbin/linux;/worldframe_d-c 1fi  
I this script, simply detects the existence of the process, does not exist to automatically restart the server.

In fact, it can also be extended, such as the log file processing and restart time, such as records and so on.

It is important to note that in Windows edit SH file to pay attention to the format problem (CR/LR), otherwise prone to sh execution error bug.

OK, test it, I test ok here, record, hoping to help other students encounter similar problems.

Simple solution for Linux server process monitoring and automatic restart

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.