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