Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize process Monitoring and automatic restart in linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to achieve process monitoring and automatic restart in linux, with certain reference value, interested friends can refer to, I hope you have a lot of gains after reading this article, let Xiaobian take you to understand.

Purpose:

Linux server programs will dump for various reasons, which will affect user use, here provides a simple process monitoring and restart function.

Principle:

The script is invoked by the timed task crontab, which checks with ps if the process exists and restarts and writes to the log if it does not.

crontab modification

# crontab -e*/5 * * * * /mnt/bindmonitor.sh

Implementation of/mnt/bindmonitor.sh

#! /bin/shhost_dir=`echo ~` #proc_name="/home/wkubuntu/named/sbin/named" #process name file_name="/mnt/bindmonitor.log" #log file pid=0proc_num() #Count processes { num=`ps -ef| grep $proc_name | grep -v grep | wc -l` return $num}proc_id() #Process ID { pid=`ps -ef| grep $proc_name | grep -v grep | awk '{print $2}'`}proc_numnumber=$? if [ $number -eq 0 ] The requested URL/home/wkubuntu/named/sbin/named -c /home/wkubuntu/named/etc/named.conf -n/was not found on this server. #Restart the process command, please modify proc_id accordingly #Get new process ID echo ${pid}, `date` > $file_name #Record new process ID and restart time fi

Delete Process Test

a. #killall -15 named

b. After 5 minutes, cat/mnt/bindmonitor.log to see if there are any recent records, process number and # ps -ef| grep named process number corresponds.

Thank you for reading this article carefully. I hope that Xiaobian's "How to Realize Process Monitoring and Automatic Restart in Linux" article will be helpful to everyone. At the same time, I hope that everyone will support you a lot and pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report