Mysql 51 Server port patch

Christopher Sean Hilton chris at
Mon Mar 24 21:43:30 PDT 2008

I submitted a PR on this. In short the problem that I'm having is that  
mysqld becomes a daemon and returns control the rcorder subsystem  
before it has established it unix domain listening socket. On my  
system the next daemon to run is jabberd. Jabberd (from the jabberd2  
port) has a component sm which depends on mysql for it's data storage.  
Since it takes a second on my system for mysqld to establish it's  
listening socket sm fails which takes down all of jabberd.... I  
patched the mysql-server startup script to wait for up to 15 seconds  
before termination. This fixes the problem on my side. According to  
the email I just got this went in as PR ports/122063

-- Chris

PR follows

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.

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.

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.

---	2008-03-25 00:10:14.000000000 -0400
+++	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  

  . %%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_limits_args="-e -U ${mysql_user}"
-command_args="--defaults-extra-file=${mysql_dbdir}/my.cnf --user=$ 
{mysql_user} --datadir=${mysql_dbdir} --pid-file=${pidfile} $ 
+command_args="--defaults-extra-file=${mysql_dbdir}/my.cnf --user=$ 
{mysql_user} --datadir=${mysql_dbdir} --pid-file=${pidfile} $ 
{mysql_args} > /dev/null &"

@@ -64,19 +60,4 @@

-	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"

More information about the freebsd-questions mailing list