#!/bin/bash #shell自检启动守护程序 #有时候服务进程会挂掉,可以运行个守护脚本,检测运行状态,启动,发邮件 checkMysql=`pgrep mysql` checkNginx=`pgrep nginx` checkHttpd=`pgrep httpd` while : do date=$(date +"%Y-%m-%d %H:%M:%S") if [ -n "$checkMysql" ]; then echo ‘mysql normal‘ >/dev/null 2>&1 else /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf echo ‘checked error: mysqld at ‘ $date >> /root/server_error.log #send mail fi if [ -n "$checkNginx" ]; then echo ‘nginx normal‘ >/dev/null 2>&1 else /usr/local/nginx/sbin/nginx echo ‘checked error: nginx at ‘ $date >> /root/server_error.log #send mail fi if [ -n "$checkHttpd" ]; then echo ‘httpd normal‘ >/dev/null 2>&1 else /usr/local/apache/bin/apachectl start echo ‘checked error: httpd at ‘ $date >> /root/server_error.log #send mail fi #休眠 sleep 5 done
时间: 2024-11-05 17:20:57