--- /Users/apple/bk/mysql-5.0/scripts/mysqld_safe.sh 2008-02-01 11:59:27.000000000 +0300 +++ /Users/apple/bk/mysql-5.0/scripts/mysqld_safe_patched.sh 2008-02-01 12:10:11.000000000 +0300 @@ -12,6 +12,12 @@ KILL_MYSQLD=1; MYSQLD= +DIE_ON_REPEATABLE_CRASH=0; +RETRIES=10; +TIMEOUT=60; +RUN_ON_DEATH= +CRASHES=0; +RESTART_TIME=`date "+%s"` trap '' 1 2 3 15 # we shouldn't let anyone kill us @@ -39,6 +45,10 @@ --mysqld-version=VERSION Use "mysqld-VERSION" as mysqld --nice=NICE Set the scheduling priority of mysqld --skip-kill-mysqld Don't try to kill stray mysqld processes + --die-on-repeatable-crash Die in case of repeatable mysqld crashes + --retries[=10] Retries before die + --timeout[=60] Timeout between retries (in seconds) + --run-on-death=COMMAND Run COMMAND on death All other options are passed to the mysqld program. @@ -94,6 +104,10 @@ --help) usage ;; + --die-on-repeatable-crash*) DIE_ON_REPEATABLE_CRASH=1; ;; + --retries=*) RETRIES=`echo "$arg" | sed -e "s;--retries=;;"` ;; + --timeout=*) TIMEOUT=`echo "$arg" | sed -e "s;--timeout=;;"` ;; + --run-on-death=*) RUN_ON_DEATH=`echo "$arg" | sed -e "s;--run-on-death=;;"` ;; *) if test -n "$pick_args" then @@ -422,6 +436,19 @@ I=`expr $I + 1` done fi + if [[ $DIE_ON_REPEATABLE_CRASH ]] + then + if (( $TIMEOUT < (( - $RESTART_TIME + (RESTART_TIME=`date "+%s"`) )) )) + then + CRASHES=0; + fi + (( CRASHES++ )) + if (( $RETRIES < $CRASHES )) + then + exec $RUN_ON_DEATH + exit 0; + fi + fi echo "`date +'%y%m%d %H:%M:%S'` mysqld restarted" | tee -a $err_log done