Simple Solution for linux server process monitoring and automatic restart, linux Server Process Monitoring
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 1fi
My 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.
LINUX Process Monitoring Protection
Several methods,
1. The simplest is to write a script, such
#! /Bin/sh
While true
Do
./1234 xx bb
Done
If you run this script, you don't have to worry about a problem after 1234 exits.
2. Using the above method, you may ask what to do if the script itself is killed ...... You can use scheduled tasks. For example, you can use crontab to check whether the 1234 process is still running every minute.
For example, the following script can check whether 1234 exists. If it does not exist, 1234 is automatically started.
#! /Bin/sh
Ps-A | awk '{print $4}' | grep-q '^ 1234 $'
If [$? -Ne 0]; then
/PATH/TO/1234 xx bb
Fi
Assume this script is called a. sh.
Then, use crontab-e to add a scheduled task.
* ***/Path/to/a. sh
You can.
Linux monitoring process program
Taking firefox monitoring as an Example
#! /Bin/bash
# This is a monitor script
While:
Do
If [-n 'ps ax | grep firefox | grep-v grep']
Then
Sleep 60
Else
Firefox
Fi
Done