Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to set up linux server process monitoring and automatic restart

Shulou Source: shulou.com Published: 2022-06-01 07:38:38 11月25日 Update

This article focuses on "how to set up linux server process monitoring and automatic restart", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to set up linux server process monitoring and automatic restart.

First, we need to add a new task to crontab.

# crontab-e: when you enter the editing state, you actually use vi to edit.

* / 1 * sh / root/monitor.sh

I'm simply setting up to call one shell script monitor.sh per minute. Here can be configured more powerful, you can search for crontab tutorials, there are many such tutorials on the Internet.

It should be noted here that many tutorials use / root/monitor.sh directly when configuring command. When I set it up, I found that this configuration will not execute the shell script, which can be done with sh before.

Then we started writing 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=$?

# get the number of processes

If [$number-eq 0]

# if the number of processes is 0then

# restart the server, or expand something else.

Cd / longwen/server/sbin/linux;. / WorldFrame_d-c 1fi

My script simply detects the existence of the process and automatically restarts the server if it does not exist.

It can also be extended here, such as the processing of log files and the recording of restart time, and so on.

It should be noted that when editing sh files in windows, you should pay attention to the format (CR/LR), otherwise it is prone to sh execution errors of BUG.

At this point, I believe you have a deeper understanding of "how to set up linux server process monitoring and automatic restart". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Processes servers services scripts monitoring content tutorials configuration just quantity files time learning query practical powerful deeper tasks interests practicality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple macOS Shulou Technology vpn Microsoft