%PDF- %PDF-
Direktori : /var/spool/ |
Current File : //var/spool/killLockedSql.sh |
#!/bin/bash # $1 : name of the file to check # $1 : name of the script to check checkActiveOnce(){ count=$(ps -ef | fgrep $1 | fgrep -v grep | wc -l) if test "$count" -gt 2 ; then echo "Multiple instance of $1" exit 2 fi } # $1 : max query time, after this value, the request will be killed # $2 : state of the query to grep for to avoid killing other requests checkLockedSqlRequests(){ oldIFS=$IFS IFS=$'\n' mysqladmin processlist | tr -s ' ' | head -n -1 | tail -n +4 | fgrep -v root | fgrep $2 |while read line ; do time=$(echo "$line" | cut -d ' ' -f 12) test "$time" == "" && continue echo "$time" | grep -ev '^[0-9]+$' && continue if test "$time" -gt $1 ; then pid=$(echo $line | cut -d ' ' -f 2) echo "Killing red $pid because req time = $time" mysqladmin kill $pid fi done } checkMysqlDumpActive(){ count=$(ps -ef | fgrep mysqldump | fgrep -v grep | wc -l) if test "$count" -eq 0 ; then return 1 else return 0 fi } checkActiveOnce `basename $0` watchdog=0 while true ; do if test "$watchdog" -gt 10 ; then echo "Watchdog > 60" exit 3 fi if ! checkMysqlDumpActive ; then echo "No mysqldump process active, incrementing watchdog : $watchdog" watchdog=$(($watchdog + 1)) sleep 1 continue fi watchdog=0 checkLockedSqlRequests 15 lock sleep 1 done