diff --git a/support-files/mysql.server.sh b/support-files/mysql.server.sh index eeeab2a..5e4feb9 100644 --- a/support-files/mysql.server.sh +++ b/support-files/mysql.server.sh @@ -225,6 +225,31 @@ wait_for_pid () { fi } +clean_up_stale_pid_files(){ + + # Clean up any stale pid files in $datadir + if [ -d "$datadir" ] + then + + PID_FILE_PATT="$datadir/*.pid" + PID_FILE_LIST=`ls -1 $PID_FILE_PATT 2>/dev/null` + + for item in $PID_FILE_LIST; + do + # Clean up empty pid file + [ ! -s $item ] && rm -f $item && continue + + # Clean up invalid/stale pid file + pidnum=$(cat $item); + process_found=$(pstree -p $pidnum 2> /dev/null) + [ -z "$process_found" ] && rm -f $item + done + fi + + return 0 +} + + # Get arguments from the my.cnf file, # the only group, which is read from now on is [mysqld] if test -x ./bin/my_print_defaults @@ -323,6 +348,10 @@ case "$mode" in ;; 'stop') + + # Clean up any stale pid files in $datadir + clean_up_stale_pid_files + # Stop daemon. We use a signal here to avoid having to know the # root password.