Bug #65809 RFE: send a notify message to systemd daemon
Submitted: 4 Jul 2012 12:02 Modified: 18 Feb 2015 11:45
Reporter: Honza Horak (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Installing Severity:S3 (Non-critical)
Version:5.5.24 OS:Linux
Assigned to: CPU Architecture:Any
Tags: Contribution

[4 Jul 2012 12:02] Honza Horak
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)
[4 Jul 2012 12:45] Valeriy Kravchuk
Thank you for the feature request and patch contributed.
[21 Feb 2014 8:40] Honza Horak
Cross-linking: https://mariadb.atlassian.net/browse/MDEV-5713
[18 Feb 2015 11:45] Ståle Deraas
Posted by developer:
 
Implemented in WL#7895 in 5.7.6. The contribution is therefore rejected.