Simple Solution for linux server process monitoring and Automatic Restart

Source: Internet
Author: User

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 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.

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.