1. My colleague ran a php crawl, which would lead to a very high sleep value, which is about several thousand levels. mysql would then be down.
A crontab is written.
# Crontab-e
[Php]
**/1 ***/sh/detect_php.sh
**/1 ***/sh/detect_php.sh
Detech_php content
[Php]
#! /Bin/bash
Host_dir = 'CD/Sh'
Proc_name = "mysql"
Bug_time = 'date-R'
Pid = 0
Proc_num ()
{
Num = 'ps-ef | grep $ proc_name | grep-v grep | wc-l'
Return $ num
}
Proc_id ()
{
Pid = 'ps-ef | grep $ proc_name | grep-v grep | awk '{print $2 }''
}
Proc_num
Number = $?
If [$ number-eq 0]
Then
./Restart_php_mysql.sh
Proc_id
Echo "Kill the php and new mysql pid is :$ {pid }:: {bug_time}"> php_mysql.log 2> & 1
Else
Proc_id
Echo "The mysql is working, $ {bug_time}"> php_mysql.log 2> & 1
Echo "it's OK! "
Fi
#! /Bin/bash
Host_dir = 'CD/Sh'
Proc_name = "mysql"
Bug_time = 'date-R'
Pid = 0
Proc_num ()
{
Num = 'ps-ef | grep $ proc_name | grep-v grep | wc-l'
Return $ num
}
Proc_id ()
{
Pid = 'ps-ef | grep $ proc_name | grep-v grep | awk '{print $2 }''
}
Proc_num
Number = $?
If [$ number-eq 0]
Then
./Restart_php_mysql.sh
Proc_id
Echo "Kill the php and new mysql pid is :$ {pid }:: {bug_time}"> php_mysql.log 2> & 1
Else
Proc_id
Echo "The mysql is working, $ {bug_time}"> php_mysql.log 2> & 1
Echo "it's OK! "
Fi
The script explains that this script is very simple. It is used to determine whether the mysql process is 0. If it is 0, kill php, restart mysql, and write a log.
Restart_php_mysql.sh content
[Php]
#! /Bin/sh
Killall-9 php
Service mysql restart
#! /Bin/sh
Killall-9 php
Service mysql restart
Pkill will cause the script to be terminated directly after killing the process. Therefore, pkill is not used here.