Description:
Linux distributions started moving to use systemd as a default init system, for example Fedora has already done it for over a year. Since systemd tries to start services parallel, it's not easy to ensure that mysql daemon is started before another service, which requires it. Currently, we have to use an arbitrary script, that checks if the daemon is ready.
However, systemd has a feature to notify daemon about a service status, which would help in this scenario a lot and packagers wouldn't need any additional scripts to test daemon status. MySQL daemon can simple send a message to systemd daemon, that startup actions have been done successfully and we are ready to accept connections.
Using this feature is really straightforward and doesn't make any issues if a user uses alternative init system. To be concrete, only one function call and some configuration checking is needed.
Please, consider adopting the following patch.
How to repeat:
See the patch.
Suggested fix:
diff -up mysql-5.5.24/configure.cmake.notify mysql-5.5.24/configure.cmake
--- mysql-5.5.24/configure.cmake.notify 2012-07-04 12:24:40.927124701 +0200
+++ mysql-5.5.24/configure.cmake 2012-07-04 12:28:24.665302589 +0200
@@ -257,6 +257,7 @@ CHECK_INCLUDE_FILES ("stdlib.h;sys/un.h"
CHECK_INCLUDE_FILES (vis.h HAVE_VIS_H)
CHECK_INCLUDE_FILES (wchar.h HAVE_WCHAR_H)
CHECK_INCLUDE_FILES (wctype.h HAVE_WCTYPE_H)
+CHECK_INCLUDE_FILES (systemd/sd-daemon.h HAVE_SYSTEMD_SD_DAEMON_H)
IF(HAVE_SYS_STREAM_H)
# Needs sys/stream.h on Solaris
diff -up mysql-5.5.24/sql/CMakeLists.txt.notify mysql-5.5.24/sql/CMakeLists.txt
--- mysql-5.5.24/sql/CMakeLists.txt.notify 2012-07-04 12:47:37.994826990 +0200
+++ mysql-5.5.24/sql/CMakeLists.txt 2012-07-04 12:50:33.988626765 +0200
@@ -157,6 +157,11 @@ IF(INTERFACE_LIBS)
"${INTERFACE_LIBS}")
ENDIF()
+# Used for notify systemd's feature
+IF(HAVE_SYSTEMD_SD_DAEMON_H)
+ TARGET_LINK_LIBRARIES(mysqld systemd-daemon)
+ENDIF()
+
# On Solaris, some extra effort is required in order to get dtrace probes
# from static libraries
DTRACE_INSTRUMENT_STATIC_LIBS(mysqld
diff -up mysql-5.5.24/sql/mysqld.cc.notify mysql-5.5.24/sql/mysqld.cc
--- mysql-5.5.24/sql/mysqld.cc.notify 2012-07-04 12:23:05.336331753 +0200
+++ mysql-5.5.24/sql/mysqld.cc 2012-07-04 12:32:04.768529924 +0200
@@ -96,6 +96,10 @@
#include <poll.h>
#endif
+#ifdef HAVE_SYSTEMD_SD_DAEMON_H
+#include <systemd/sd-daemon.h>
+#endif
+
#define mysqld_charset &my_charset_latin1
/* We have HAVE_purify below as this speeds up the shutdown of MySQL */
@@ -5163,6 +5167,11 @@ void handle_connections_sockets()
#endif
#endif
+#ifdef HAVE_SYSTEMD_SD_DAEMON_H
+ sd_notify(0, "READY=1\n"
+ "STATUS=Processing requests...");
+#endif
+
DBUG_PRINT("general",("Waiting for connections."));
MAYBE_BROKEN_SYSCALL;
while (!abort_loop)