Linux scheduled monitoring and maintenance services
Taking the encryption and decryption service as an example, I provide the encryption and decryption service. Others call my service. Because Linux machines are remote, I don't know where the machines are in a specific environment, I don't know if the machine is restarted. I need to maintain the stability of my services. What should I do?
Two things need to be done
1. scheduled task, executed once per minute
---------------------------------------------------------- Command ----------------------------------------------------------
Crontab-e
* ****/Mnt/disk/xxx/encrypt-decrypt-service-moniter.sh
Bytes --------------------------------------------------------------------------------------------------------------------
Note: It must be reloaded. Otherwise, the latest task may not be executed.
Sudo service cron reload (ubuntu)
/Sbin/service crond reload (redhat, centos)
2. Task content
Determine whether the service is running. if the service is not running, start the task. Note: The script must use the full path; otherwise, problems may occur.
------------------------------------------------------------ Code ----------------------------------------------------------
#! /Bin/sh
# Monitor whether the service is running normally. if the service is not running properly, enable the service.
Flag = $ (jps-l | grep "encrypt-decrypt ")
If [-n "$ flag"]; then
Echo "service is good, don't warry"
Else
Date + % Y % m % d "" % H: % M: % S>/mnt/disk/mashangrong/restart. log
Echo "service is restart by encrypt-decrypt-service-moniter.sh">/mnt/disk/mashangrong/restart. log
Setsid java-jar/mnt/disk/mashangrong/encrypt-decrypt-1.0.0_v1026.jar-Xmx4096m-Xms4096m-XX: NewRatio = 1-XX: Export vorratio = 8
Fi
Bytes --------------------------------------------------------------------------------------------------------------------