Purpose: Under Linux, the server program may be dumped for various reasons, which will affect user use. Here we provide a simple process monitoring and restart function. Implementation principle: The script is called by the scheduled task crontab. The script uses ps to check whether the process exists. If it does not exist, it restarts and writes a log. Crontab modification # crontab -e */5 * * * * /mnt/bindmonitor.sh Implementation of /mnt/bindmonitor.sh #!/bin/sh host_dir=`echo ~` # Current user root directory proc_name="/home/wkubuntu/named/sbin/named" # Process name file_name="/mnt/bindmonitor.log" # Log file pid=0 proc_num() # Calculate the number of processes { num=`ps -ef | grep $proc_name | grep -v grep | wc -l` return $num } proc_id() # process number { pid=`ps -ef | grep $proc_name | grep -v grep | awk '{print $2}'` } proc_num number=$? if [ $number -eq 0 ] # Check if the process exists then /home/wkubuntu/named/sbin/named -c /home/wkubuntu/named/etc/named.conf -n 1 & # Command to restart the process, please modify proc_id accordingly # Get the new process ID echo ${pid}, `date` >> $file_name # Record the new process ID and restart time to file Deleting process tests a. #killall -15 named b. After 5 minutes, run cat /mnt/bindmonitor.log to see if there are any new records. The process number should correspond to the process number in # ps -ef |grep named. Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. You may also be interested in:
|
<<: Analysis of pitfalls in rounding operation of ROUND function in MySQL
>>: Vue Element front-end application development conventional Element interface components
The database I use is MySQL database version 5.7 ...
Development Background: Recently, I am working on...
1. Uninstalling MySQL 5.7 1.1查看yum是否安裝過mysql cd y...
Regarding how to create this thin-line table, a s...
Table of contents Why is IN slow? Which is faster...
environment: 1 CentOS Linux release 7.5.1804 (Cor...
cause The way to import external files into a min...
Elastic stack, commonly known as ELK stack, is a ...
Given an array [1,8,5,4,3,9,2], write an algorith...
Table of contents 1. Concept 1.1 Definition 1.2 D...
The first solution is to push the image to a publ...
Table of contents Introduction Step 1 Step 2: Cre...
In this article, we’ll explore how async/await is...
Without further ado, I'll go straight to the ...
Preface Bootstrap, the most popular front-end dev...