Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Mar 2008 04:35:04 GMT
From:      Christopher Sean Hilton <chris@vindaloo.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   ports/122063: Mysql-server rc.d script finishes before mysqld has established listening socket.
Message-ID:  <200803250435.m2P4Z4jZ002149@www.freebsd.org>
Resent-Message-ID: <200803250440.m2P4e3kn088477@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         122063
>Category:       ports
>Synopsis:       Mysql-server rc.d script finishes before mysqld has established listening socket.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Mar 25 04:40:03 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     Christopher Sean Hilton
>Release:        6.1-STABLE
>Organization:
>Environment:
FreeBSD corellia.vindaloo.com 6.1-RELEASE FreeBSD 6.1-RELEASE #0: Thu Jun  1 22:42:32 EDT 2006     chris@corellia2:/usr/src/sys/i386/compile/CORELLIA  i386
>Description:
The rc.d script shipped with the port of mysql server exits immediately after mysqld starts. This normally wouldn't be a problem but the mysql daemon exits about a second before it has established it's unix domain listening socket: "/tmp/mysql". The problem here is that the rc startup system can queue the next daemon to start before "/tmp/mysql" is available. If the next daemon needs mysql it will fail and exit. On my system rcorder starts mysql-server and then immediately follows up with jabberd. Since mysql doesn't appear ready for about a  second jabberd fails and exits. 

I've attached a patch which waits for up to 15 seconds for the /tmp/mysql socket to appear in the filesystem and exits as soon as it's available. This allows the next daemon in line to startup properly if it needs mysql. Note that I have had this problem with postfix up until I removed my mail information from mysql. 


>How-To-Repeat:
Build a system that uses mysql and jabber or postfix. Ensure that jabberd starts after mysql by hacking /usr/local/etc/rc.d/jabberd's ## REQUIRES line. Assuming you're not on some hot rod of a machine check your logs for jabberd2's failure line in the service manager.
>Fix:
This may not adhere to the strictest rules of the rcorder system but my solution is to hack the provider's (mysql-server) startup script. The goal was to prevent the script from exiting until either the listening socket is established or a 15 second timeout has passed.

A better solution would be for mysqld to establish the listening socket first (even if it ignores incoming connections for a little bit) but that's much higher effort.

Patch attached with submission follows:

--- mysql-server.sh.in	2008-03-25 00:10:14.000000000 -0400
+++ mysql-server.sh.in.orig	2008-03-25 00:02:58.000000000 -0400
@@ -18,8 +18,6 @@
 #			Base database directory.
 # mysql_args (str):	Custom additional arguments to be passed
 #			to mysqld_safe (default empty).
-# mysql_conn_socket (str): Defaults to "/tmp/mysql.sock"
-#                          The unix domain socket the daemon listens on.
 #
 
 . %%RC_SUBR%%
@@ -32,17 +30,15 @@
 : ${mysql_enable="NO"}
 : ${mysql_limits="NO"}
 : ${mysql_dbdir="/var/db/mysql"}
-: ${mysql_conn_socket="/tmp/mysql.sock"}
 : ${mysql_args=""}
 
 mysql_user="mysql"
 mysql_limits_args="-e -U ${mysql_user}"
 pidfile="${mysql_dbdir}/`/bin/hostname`.pid"
 command="%%PREFIX%%/bin/mysqld_safe"
-command_args="--defaults-extra-file=${mysql_dbdir}/my.cnf --user=${mysql_user} --datadir=${mysql_dbdir} --pid-file=${pidfile} ${mysql_args}"
+command_args="--defaults-extra-file=${mysql_dbdir}/my.cnf --user=${mysql_user} --datadir=${mysql_dbdir} --pid-file=${pidfile} ${mysql_args} > /dev/null &"
 procname="%%PREFIX%%/libexec/mysqld"
 start_precmd="${name}_prestart"
-start_cmd="${name}_start"
 mysql_install_db="%%PREFIX%%/bin/mysql_install_db"
 mysql_install_db_args="--ldata=${mysql_dbdir}"
 
@@ -64,19 +60,4 @@
 	fi
 }
 
-mysql_start()
-{
-	local timeout=15
-
-	echo "Starting ${name}"
-
-	${command} ${command_args} < /dev/null > /dev/null 2>&1 &
-	while [ ! -S "${mysql_conn_socket}" -a ${timeout} -gt 0 ]; do
-		timeout=$(( timeout - 1 ))
-		sleep 1
-	done
-
-	return 0
-}
-
 run_rc_command "$1"


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200803250435.m2P4Z4jZ002149>