Bug #9114 mysqld_safe should react on signals (patch)
Submitted: 11 Mar 2005 0:22 Modified: 23 Jul 2006 11:34
Reporter: Christian Hammers (Silver Quality Contributor) (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: General Severity:S4 (Feature request)
Version:all OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution

[11 Mar 2005 0:22] Christian Hammers
Description:
A kill -15 or kill -9 to mysqld_safe is currently ignored. But it would be so simple to
enable it as Erich Schubert <erich@debian.org> just proved me. Just change the traps
to:
  trap '/usr/bin/mysqladmin --defaults-extra-file=/etc/mysql/debian.cnf refresh' 1 # HUP
  ...
and add "& wait" to the daemon line.

Of course the exact file locations vary. Here debian.cnf contains the name and password
for a special user that has the shutdown right.

See: http://bugs.debian.org/208364

How to repeat:
-

Suggested fix:
 
 #
+# From now on, we catch signals to do a proper shutdown of mysqld
+# when signalled to do so.
+#
+trap '/usr/bin/mysqladmin --defaults-extra-file=/etc/mysql/debian.cnf refresh' 1 # HUP
+trap '/usr/bin/mysqladmin --defaults-extra-file=/etc/mysql/debian.cnf shutdown' 2 3 15 # INT QUIT and TERM
+
+#
 # Uncomment the following lines if you want all tables to be automatically
 # checked and repaired during startup. You should add sensible key_buffer
 # and sort_buffer values to my.cnf to improve check performance or require
@@ -299,9 +304,9 @@
   rm -f $safe_mysql_unix_port $pid_file	# Some extra safety
   if test -z "$args"
   then
-    $NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-locking 2>&1 | $ERR_LOGGER -t mysqld
+    $NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-locking 2>&1 | $ERR_LOGGER -t mysqld & wait
   else
-    eval "$NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-locking $args 2>&1 | $ERR_LOGGER -t mysqld"
+    eval "$NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-locking $args 2>&1 | $ERR_LOGGER -t mysqld & wait"
   fi
   if test ! -f $pid_file		# This is removed if normal shutdown
   then