#!/bin/bash #shell自检启动守护程序 #有时候服务进程会挂掉, can run a daemon script, detect running status, start, email 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&nbsP;5 done
This article is from the "Chen Nan Run" blog, please be sure to keep this source http://chennanrun.blog.51cto.com/4583928/1622621
Simple nginx,mysql,http Daemon Boot program