Simple Solution for linux server process monitoring and Automatic Restart
Reprinted please indicate the source: curtain roll west wind column (http://blog.csdn.net/ljxfblog)
Starting from this week, the newbie game was in the file deletion and sealing test phase. The last two days showed good performance. After the update today, several downtime events occurred, which affects players' testing and experience, our server management system is not yet complete. To prevent losses caused by downtime at night, we should temporarily replace it with a simple solution.
The implementation principle is mainly to use the crontab mechanism provided by linux to regularly query whether the server process exists. If the server process goes down, process the preset script.
First, we need to add a new task to crontab.
# Crontab-e: Enter the editing status, which is actually edited using vi.
*/1 *** sh/root/monitor. sh
Here I just set to call a shell script monitor. sh every minute. The configuration here is more powerful. You can search for the crontab tutorial. There are many such tutorials on the Internet.
Note that the/root/monitor command is directly used in many tutorials. sh. When I set it, I found that the configuration will not execute the shell script, and it will be executed after sh is added.
Then we start to write the shell script "monitor. sh.
#! /Bin/sh proc_name = "WorldFrame_d" # process name proc_num () # query the number of processes {num = 'ps-ef | grep $ proc_name | grep-v grep | wc-l' return $ num} proc_num number = $? # Obtain the number of processes if [$ number-eq 0] # if the number of processes is 0 then # restart the server or expand other content. Cd/longwen/server/sbin/linux;./WorldFrame_d-c 1fiMy script simply checks whether a process exists and automatically restarts the server if it does not exist.
This can also be expanded, such as the log file processing and restart time records.
Note that you must pay attention to the format (CR/LR) when editing sh files in windows; otherwise, the sh execution error may occur.
Now, let's test it. I will test it here and record it. I hope it will help other students who encounter similar problems.