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:
Category:MySQL Server: Installing Severity:S3 (Non-critical)
Version:5.5.24 OS:Linux
Assigned to: CPU Architecture:Any
Tags: Contribution
Triage: Needs Triage: D5 (Feature request)

[4 Jul 2012 12:02] Honza Horak
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"
   # 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)
+# Used for notify systemd's feature
+  TARGET_LINK_LIBRARIES(mysqld systemd-daemon)
 # On Solaris, some extra effort is required in order to get dtrace probes
 # from static libraries
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>
+#include <systemd/sd-daemon.h>
 #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()
+  sd_notify(0, "READY=1\n"
+               "STATUS=Processing requests...");
   DBUG_PRINT("general",("Waiting for connections."));
   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.