From 02b645796972b5b1aff0eef0ca343ef3e78528ca Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 12 Mar 2015 07:21:51 +1100 Subject: [PATCH 01/32] Add base SYSTEMD library to cmake Add systemd detection (autoenabled) and configuration option. Enable systemd for debian and ubuntu --- config.h.cmake | 1 + configure.cmake | 25 +++++++++++++++++++++++++ debian/dist/Debian/control | 4 ++-- debian/dist/Ubuntu/control | 3 ++- sql/CMakeLists.txt | 9 ++++++++- 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/config.h.cmake b/config.h.cmake index 6a0527719f9cf..a269a65cddf78 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -118,6 +118,7 @@ #cmakedefine HAVE_LIBCRYPT 1 #cmakedefine HAVE_LIBMTMALLOC 1 #cmakedefine HAVE_LIBWRAP 1 +#cmakedefine HAVE_SYSTEMD 1 /* Does "struct timespec" have a "sec" and "nsec" field? */ #cmakedefine HAVE_TIMESPEC_TS_SEC 1 diff --git a/configure.cmake b/configure.cmake index 215b0dc32b4b6..98686182a6af9 100644 --- a/configure.cmake +++ b/configure.cmake @@ -161,6 +161,22 @@ IF(UNIX) SET(LIBWRAP "wrap") ENDIF() ENDIF() + + OPTION(WITH_SYSTEMD "Compile with systemd notification on ready" ON) + IF(WITH_SYSTEMD) + SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} systemd-daemon) + CHECK_C_SOURCE_COMPILES( + " + #include + int main() + { + sd_listen_fds(0); + }" + HAVE_SYSTEMD) + IF(HAVE_SYSTEMD) + SET(LIBSYSTEMD "systemd-daemon") + ENDIF() + ENDIF() ENDIF() # @@ -251,6 +267,9 @@ CHECK_INCLUDE_FILES (wchar.h HAVE_WCHAR_H) CHECK_INCLUDE_FILES (wctype.h HAVE_WCTYPE_H) CHECK_INCLUDE_FILES (sys/sockio.h HAVE_SYS_SOCKIO_H) CHECK_INCLUDE_FILES (sys/utsname.h HAVE_SYS_UTSNAME_H) +IF(WITH_SYSTEMD) +CHECK_INCLUDE_FILES (systemd/sd-daemon.h HAVE_SYSTEMD_SD_DAEMON_H) +ENDIF() IF(BFD_H_EXISTS) IF(NOT_FOR_DISTRIBUTION) @@ -458,6 +477,12 @@ IF(HAVE_SYS_EVENT_H) CHECK_FUNCTION_EXISTS (kqueue HAVE_KQUEUE) ENDIF() +IF(WITH_SYSTEMD) +CHECK_FUNCTION_EXISTS (sd_listen_fds HAVE_SYSTEMD_SD_DAEMON_H) +CHECK_FUNCTION_EXISTS (sd_notify HAVE_SYSTEMD_SD_DAEMON_H) +CHECK_FUNCTION_EXISTS (sd_notifyf HAVE_SYSTEMD_SD_DAEMON_H) +ENDIF() + #-------------------------------------------------------------------- # Support for WL#2373 (Use cycle counter for timing) #-------------------------------------------------------------------- diff --git a/debian/dist/Debian/control b/debian/dist/Debian/control index ffede25ccc400..45a35fe0ddd57 100644 --- a/debian/dist/Debian/control +++ b/debian/dist/Debian/control @@ -4,7 +4,7 @@ Priority: optional Maintainer: MariaDB Developers XSBC-Original-Maintainer: Maria Developers Uploaders: MariaDB Developers -Build-Depends: libtool (>= 1.4.2-7), procps | hurd, debhelper, file (>= 3.28), libncurses5-dev (>= 5.0-6), perl (>= 5.6.0), libwrap0-dev (>= 7.6-8.3), zlib1g-dev (>= 1:1.1.3-5), ${LIBREADLINE_DEV}, libssl-dev, libpam0g-dev, psmisc, po-debconf, chrpath, automake1.9, doxygen, texlive-latex-base, ghostscript | gs-gpl, dpatch, gawk, bison, lsb-release, hardening-wrapper, ${CMAKE_DEP}libaio-dev, libjemalloc-dev (>= 3.0.0) +Build-Depends: libtool (>= 1.4.2-7), procps | hurd, debhelper, file (>= 3.28), libncurses5-dev (>= 5.0-6), perl (>= 5.6.0), libwrap0-dev (>= 7.6-8.3), zlib1g-dev (>= 1:1.1.3-5), ${LIBREADLINE_DEV}, libssl-dev, libpam0g-dev, psmisc, po-debconf, chrpath, automake1.9, doxygen, texlive-latex-base, ghostscript | gs-gpl, dpatch, gawk, bison, lsb-release, hardening-wrapper, ${CMAKE_DEP}libaio-dev, libjemalloc-dev (>= 3.0.0), libsystemd-daemon-dev, dh-systemd Standards-Version: 3.8.3 Homepage: http://mariadb.org/ Vcs-Browser: http://bazaar.launchpad.net/~maria-captains/maria/10.0/files @@ -147,7 +147,7 @@ Description: MariaDB database client binaries Package: mariadb-server-core-10.0 Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, libmariadbclient18 (>= ${binary:Version}) +Depends: ${shlibs:Depends}, ${misc:Depends}, libmariadbclient18 (>= ${binary:Version}), libsystemd-daemon0 Provides: mysql-server-core, mysql-server-core-5.1, mysql-server-core-5.5 Conflicts: mariadb-server-5.1 (<< 5.1.60), mariadb-server-5.2 (<< 5.2.10), diff --git a/debian/dist/Ubuntu/control b/debian/dist/Ubuntu/control index 02ace29b67bdf..65d390797d5d5 100644 --- a/debian/dist/Ubuntu/control +++ b/debian/dist/Ubuntu/control @@ -4,7 +4,7 @@ Priority: optional Maintainer: MariaDB Developers XSBC-Original-Maintainer: Maria Developers Uploaders: MariaDB Developers -Build-Depends: libtool (>= 1.4.2-7), procps | hurd, debhelper, file (>= 3.28), libncurses5-dev (>= 5.0-6), perl (>= 5.6.0), libwrap0-dev (>= 7.6-8.3), zlib1g-dev (>= 1:1.1.3-5), ${LIBREADLINE_DEV}, libssl-dev, libpam0g-dev, psmisc, po-debconf, chrpath, automake1.9, doxygen, texlive-latex-base, ghostscript | gs-gpl, dpatch, gawk, bison, lsb-release, hardening-wrapper, ${CMAKE_DEP}libaio-dev, libjemalloc-dev (>= 3.0.0) +Build-Depends: libtool (>= 1.4.2-7), procps | hurd, debhelper, file (>= 3.28), libncurses5-dev (>= 5.0-6), perl (>= 5.6.0), libwrap0-dev (>= 7.6-8.3), zlib1g-dev (>= 1:1.1.3-5), ${LIBREADLINE_DEV}, libssl-dev, libpam0g-dev, psmisc, po-debconf, chrpath, automake1.9, doxygen, texlive-latex-base, ghostscript | gs-gpl, dpatch, gawk, bison, lsb-release, hardening-wrapper, ${CMAKE_DEP}libaio-dev, libjemalloc-dev (>= 3.0.0), libsystemd-daemon-dev, dh-systemd Standards-Version: 3.8.2 Homepage: http://mariadb.org/ Vcs-Browser: http://bazaar.launchpad.net/~maria-captains/maria/10.0/files @@ -148,6 +148,7 @@ Description: MariaDB database client binaries Package: mariadb-server-core-10.0 Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, libmariadbclient18 (>= ${binary:Version}) + libsystemd-daemon0 Provides: mysql-server-core, mysql-server-core-5.1, mysql-server-core-5.5 Conflicts: mysql-server-5.0, mysql-server-core-5.0, mysql-server-core-5.1, mysql-server-core-5.5, diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index fba1a68fa46ab..da965e5bbe9c3 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -120,7 +120,7 @@ DTRACE_INSTRUMENT(sql) TARGET_LINK_LIBRARIES(sql ${MYSQLD_STATIC_PLUGIN_LIBS} mysys mysys_ssl dbug strings vio pcre ${LIBJEMALLOC} ${LIBWRAP} ${LIBCRYPT} ${LIBDL} ${CMAKE_THREAD_LIBS_INIT} - ${SSL_LIBRARIES}) + ${LIBSYSTEMD} ${SSL_LIBRARIES}) IF(WIN32) SET(MYSQLD_SOURCE main.cc nt_servc.cc nt_servc.h message.rc) @@ -180,6 +180,13 @@ IF(INTERFACE_LIBS) "${INTERFACE_LIBS}") ENDIF() +IF(WITH_SYSTEMD) +# Used for notify systemd's feature +IF(HAVE_SYSTEMD_SD_DAEMON_H) + TARGET_LINK_LIBRARIES(mysqld systemd-daemon) +ENDIF() +ENDIF() + # On Solaris, some extra effort is required in order to get dtrace probes # from static libraries DTRACE_INSTRUMENT_STATIC_LIBS(mysqld From 63d2b930abc74513bd021703ab506aa3b1dcd7b4 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 12 Mar 2015 07:26:04 +1100 Subject: [PATCH 02/32] extend psi adding mysql_socket_fd function mysql_socket_fd mirrors the functionality of mysql_socket_socket. Needed for systemd socket activation. --- include/mysql/psi/mysql_socket.h | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/mysql/psi/mysql_socket.h b/include/mysql/psi/mysql_socket.h index e1d56539f853c..ea44d49ea8773 100644 --- a/include/mysql/psi/mysql_socket.h +++ b/include/mysql/psi/mysql_socket.h @@ -281,6 +281,22 @@ inline_mysql_socket_set_state(MYSQL_SOCKET socket, enum PSI_socket_state state) } #endif /* HAVE_PSI_SOCKET_INTERFACE */ +/** + @def mysql_socket_fd(K, F) + Create a socket. + @c mysql_socket_socket is a replacement for @c socket. + @param K PSI_socket_key for this instrumented socket + @param F File descriptor +*/ + +#ifdef HAVE_PSI_SOCKET_INTERFACE + #define mysql_socket_fd(K, F) \ + inline_mysql_socket_fd(K, F) +#else + #define mysql_socket_fd(K, F) \ + inline_mysql_socket_fd(F) +#endif + /** @def mysql_socket_socket(K, D, T, P) Create a socket. @@ -542,6 +558,28 @@ static inline void inline_mysql_socket_register( } #endif +/** mysql_socket_fd */ + +static inline MYSQL_SOCKET +inline_mysql_socket_fd +( +#ifdef HAVE_PSI_SOCKET_INTERFACE + PSI_socket_key key, +#endif + int fd) +{ + MYSQL_SOCKET mysql_socket= MYSQL_INVALID_SOCKET; + mysql_socket.fd= fd; +#ifdef HAVE_PSI_SOCKET_INTERFACE + if (likely(mysql_socket.fd != INVALID_SOCKET)) + { + mysql_socket.m_psi= PSI_SOCKET_CALL(init_socket) + (key, (const my_socket*)&mysql_socket.fd, NULL, 0); + } +#endif + return mysql_socket; +} + /** mysql_socket_socket */ static inline MYSQL_SOCKET From ebb3153e496e1e5ec516a08559384aa949b76dff Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 12 Mar 2015 07:45:55 +1100 Subject: [PATCH 03/32] MDEV-5536 add systemd socket activation This adds systemd socket activation functionality to MariaDB where the system libraries exist for it. When started from init scripts mysqld functions the same as it does before this patch. When systemd socket activation starts mysqld, systemd does the listening and leaves these listening file descriptors open. Assisted by sd_listen_fds, the sockets are populated into arrays. Configuration options ignored by mysqld when instigated from systemd socket activation include: * bind-address * port * extra-port * socket * skip-networking * max-connections Systemd socket activation definations (e.g. support-files/mariadb.socket) provide an arbitary number of sockets for MariaDB to listen on. 10 was chosen as an arbitary number bigger than the currently supported 2 TCP ports and one unix socket for the maximium number supported. The support-files/mariadb-socket-convert script can be used to convert my.cnf files and extract the needed config files to create a mariadb.socket file. The functionalty provided by extra_port isn't supported on MariaDB under socket activation as all sockets are treated equal. support-files/mariadb.service provides a systemd service file. This replaces mysqld_safe. Inside this file there are examples on how to replace specific mysqld_safe variables. --- debian/dist/Debian/rules | 2 + debian/dist/Ubuntu/rules | 2 + sql/mysqld.cc | 266 ++++++++++++++++++++++++--- sql/share/errmsg-utf8.txt | 2 + support-files/mariadb-socket-convert | 150 +++++++++++++++ support-files/mariadb-systemd-start | 44 +++++ support-files/mariadb.service | 104 +++++++++++ support-files/mariadb.socket | 41 +++++ 8 files changed, 590 insertions(+), 21 deletions(-) create mode 100644 support-files/mariadb-socket-convert create mode 100644 support-files/mariadb-systemd-start create mode 100644 support-files/mariadb.service create mode 100644 support-files/mariadb.socket diff --git a/debian/dist/Debian/rules b/debian/dist/Debian/rules index 2122a3c815455..5dba5d1c79302 100755 --- a/debian/dist/Debian/rules +++ b/debian/dist/Debian/rules @@ -216,7 +216,9 @@ binary-indep: build install dh_installexamples -i dh_installmenu -i dh_installlogrotate -i + dh_systemd_enable -i support-files/mariadb.service support-files/mariadb.socket dh_installinit -i + dh_systemd_start -i --restart-after-upgrade mariadb.socket dh_installcron -i dh_installman -i dh_installinfo -i diff --git a/debian/dist/Ubuntu/rules b/debian/dist/Ubuntu/rules index 8d993124b56c8..6cd2a15b90ac3 100755 --- a/debian/dist/Ubuntu/rules +++ b/debian/dist/Ubuntu/rules @@ -221,7 +221,9 @@ binary-indep: build install dh_installexamples -i dh_installmenu -i dh_installlogrotate -i + dh_systemd_enable -i support-files/mariadb.service support-files/mariadb.socket dh_installinit -i + dh_systemd_start -i --restart-after-upgrade mariadb.socket dh_installcron -i dh_installman -i dh_installinfo -i diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 7138027ff0a77..6b26846072090 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -105,6 +105,24 @@ #include #endif +#ifdef HAVE_SYSTEMD +#include +#include +union sockaddr_union { + struct sockaddr sa; + struct sockaddr_in in; + struct sockaddr_in6 in6; +#ifdef HAVE_SYS_UN_H + struct sockaddr_un un; +#endif + struct sockaddr_storage ss; +}; +#define MAX_LISTEN_SOCKETS 10 +static int systemd_listen_cnt=0; +#else /* HAVE_SYSTEMD */ +#define MAX_LISTEN_SOCKETS 3 +#endif + #define mysqld_charset &my_charset_latin1 /* We have HAVE_valgrind below as this speeds up the shutdown of MySQL */ @@ -1840,6 +1858,9 @@ static void __cdecl kill_server(int sig_ptr) else sql_print_error(ER_DEFAULT(ER_GOT_SIGNAL),my_progname,sig); /* purecov: inspected */ +#ifdef HAVE_SYSTEMD + sd_notify(0, "STOPPING=1"); +#endif #ifdef HAVE_SMEM /* Send event to smem_event_connect_request for aborting @@ -2517,8 +2538,13 @@ static void network_init(void) struct sockaddr_un UNIXaddr; int arg; #endif + int systemd_n = 0; DBUG_ENTER("network_init"); +#ifdef HAVE_SYSTEMD + systemd_n = sd_listen_fds(0); + DBUG_PRINT("general",("Systemd listen_fds is %d",systemd_n)); +#endif if (MYSQL_CALLBACK_ELSE(thread_scheduler, init, (), 0)) unireg_abort(1); /* purecov: inspected */ @@ -2532,7 +2558,7 @@ static void network_init(void) if (!opt_disable_networking) DBUG_ASSERT(report_port != 0); #endif - if (!opt_disable_networking && !opt_bootstrap) + if (!opt_disable_networking && !opt_bootstrap && systemd_n==0) { if (mysqld_port) base_ip_sock= activate_tcp_port(mysqld_port); @@ -2592,7 +2618,7 @@ static void network_init(void) /* ** Create the UNIX socket */ - if (mysqld_unix_port[0] && !opt_bootstrap) + if (mysqld_unix_port[0] && !opt_bootstrap && systemd_n==0) { DBUG_PRINT("general",("UNIX Socket is %s",mysqld_unix_port)); @@ -6058,6 +6084,14 @@ inline void kill_broken_server() #ifndef EMBEDDED_LIBRARY +#ifdef HAVE_SYSTEMD +static MYSQL_SOCKET systemd_sock[MAX_LISTEN_SOCKETS]; +static PSI_socket_key all_systemd_key[MAX_LISTEN_SOCKETS]; +#ifdef HAVE_PSI_SOCKET_INTERFACE +static PSI_socket_info all_systemd_sockets[MAX_LISTEN_SOCKETS+1]; +#endif +#endif + void handle_connections_sockets() { MYSQL_SOCKET sock= mysql_socket_invalid(); @@ -6071,38 +6105,198 @@ void handle_connections_sockets() int flags=0,retval; st_vio *vio_tmp; bool is_unix_sock; -#ifdef HAVE_POLL +#ifdef HAVE_SYSTEMD + int systemd_n, systemd_fd; + union sockaddr_union socketpeer; + socklen_t socketpeer_len; + char const *family; +#ifndef HAVE_POLL + int pfs_flags[MAX_LISTEN_SOCKETS]; + // systemd wants these too + MYSQL_SOCKET pfs_fds[MAX_LISTEN_SOCKETS]; // used for non-polling interfaces +#endif +#endif // HAVE_SYSTEMD int socket_count= 0; - struct pollfd fds[3]; // for ip_sock, unix_sock and extra_ip_sock - MYSQL_SOCKET pfs_fds[3]; // for performance schema -#define setup_fds(X) \ + short fd_type[MAX_LISTEN_SOCKETS]; +#ifdef HAVE_POLL + struct pollfd fds[MAX_LISTEN_SOCKETS]; // for ip_sock, extra_ip_sock and unix_sock (could be any order for systemd) + MYSQL_SOCKET pfs_fds[MAX_LISTEN_SOCKETS]; // for performance schema +#define setup_fds(X,T) \ mysql_socket_set_thread_owner(X); \ pfs_fds[socket_count]= (X); \ fds[socket_count].fd= mysql_socket_getfd(X); \ fds[socket_count].events= POLLIN; \ + fd_type[socket_count]= T; \ socket_count++ #else -#define setup_fds(X) FD_SET(mysql_socket_getfd(X),&clientFDs) +#ifdef HAVE_SYSTEMD +#define setup_fds(X,T) FD_SET(mysql_socket_getfd(X),&clientFDs); \ + pfs_fds[socket_count]= (X); \ + fd_type[socket_count]= T; \ + socket_count++ +#else +#define setup_fds(X,T) FD_SET(mysql_socket_getfd(X),&clientFDs); \ + fd_type[socket_count]= T; \ + socket_count++ +#endif // HAVE_SYSTEMD fd_set readFDs,clientFDs; FD_ZERO(&clientFDs); #endif DBUG_ENTER("handle_connections_sockets"); - if (mysql_socket_getfd(base_ip_sock) != INVALID_SOCKET) +#ifdef HAVE_SYSTEMD + systemd_n = sd_listen_fds(1); + if (systemd_n < 0) { - setup_fds(base_ip_sock); - ip_flags = fcntl(mysql_socket_getfd(base_ip_sock), F_GETFL, 0); + my_error(ER_SYSTEMD_LISTEN_FDS, MYF(0), 0, -systemd_n); } - if (mysql_socket_getfd(extra_ip_sock) != INVALID_SOCKET) + else + if (systemd_n > 0) { - setup_fds(extra_ip_sock); - extra_ip_flags = fcntl(mysql_socket_getfd(extra_ip_sock), F_GETFL, 0); + systemd_fd = SD_LISTEN_FDS_START; + while (systemd_n-- && systemd_listen_cnt < MAX_LISTEN_SOCKETS) + { + /* grab socket info */ + socketpeer_len = sizeof(socketpeer); + if (getsockname(systemd_fd, (struct sockaddr *) &socketpeer, + &socketpeer_len) < 0) + { + sql_print_error("getsockname for fd %d failed (errno= %d).", + systemd_fd, errno); + sd_notifyf(0, "ERRNO=%d", errno); + systemd_fd++; + continue; + } + if (socketpeer_len >=sizeof(socketpeer)) + { + sql_print_error("getsockname for fd %d unsufficient space", systemd_fd); + sd_notifyf(0, "ERRNO=%d", EINVAL); + systemd_fd++; + continue; + } + + /* Get listening sockets from systemd library calls + and set them up the same as other sockets. */ +#ifdef HAVE_SYS_UN_H + if (socketpeer.ss.ss_family == AF_UNIX) + { + sql_print_information("Listening on systemd unix socket for %s.", + socketpeer.un.sun_path); + family= "systemd_unix_socket"; + } + else +#endif + if (socketpeer.ss.ss_family == AF_INET || + socketpeer.ss.ss_family == AF_INET6) + { + sql_print_information("Listening on systemd family %s port %d.", + socketpeer.ss.ss_family == AF_INET ? "IPv4" : "IPv6", + ntohs(socketpeer.ss.ss_family == AF_INET ? + socketpeer.in.sin_port : socketpeer.in6.sin6_port)); + family= socketpeer.ss.ss_family == AF_INET ? "systemd_IPv4" : + "systemd_IPv6"; + } + else + { + sql_print_error("Unrecognised socket family: %d.", + socketpeer.ss.ss_family); + systemd_fd++; + continue; + } + systemd_sock[systemd_listen_cnt]= mysql_socket_fd(all_systemd_key[systemd_listen_cnt], systemd_fd); + mysql_socket_set_thread_owner(systemd_sock[systemd_listen_cnt]); +#ifndef HAVE_POLL + pfs_flags[socket_count]= +#endif + fcntl(systemd_fd, F_GETFL, 0); +#ifdef HAVE_PSI_SOCKET_INTERFACE + all_systemd_sockets[systemd_listen_cnt]= (PSI_socket_info) { &all_systemd_key[systemd_listen_cnt], family, PSI_FLAG_GLOBAL }; +#endif + setup_fds(systemd_sock[systemd_listen_cnt], socketpeer.ss.ss_family); + systemd_fd++; + systemd_listen_cnt++; + } +#ifdef HAVE_PSI_SOCKET_INTERFACE + all_systemd_sockets[systemd_listen_cnt]= (PSI_socket_info) { &key_socket_client_connection, "client_connection", 0}; + mysql_socket_register("sql", all_systemd_sockets, systemd_listen_cnt + 1); +#endif + /* print out unused ones */ + while (systemd_n-- > 0) + { + socketpeer_len = sizeof(socketpeer); + if (getsockname(systemd_fd, (struct sockaddr *) &socketpeer, + &socketpeer_len) < 0) + { + sql_print_error("getsockname for fd %d failed (errno= %d).", + systemd_fd, errno); + sd_notifyf(0, "ERRNO=%d", errno); + systemd_fd++; + continue; + } + if (socketpeer_len >=sizeof(socketpeer)) + { + sql_print_error("getsockname for fd %d unsufficient space", systemd_fd); + sd_notifyf(0, "ERRNO=%d", EINVAL); + systemd_fd++; + continue; + } +#ifdef HAVE_SYS_UN_H + if (socketpeer.ss.ss_family == AF_UNIX) + { + sql_print_error("Exceeded %d sockets NOT listening on systemd unix socket for %s.", + MAX_LISTEN_SOCKETS, socketpeer.un.sun_path); + } + else +#endif + if (socketpeer.ss.ss_family == AF_INET || + socketpeer.ss.ss_family == AF_INET6) + { + sql_print_error("Exceeded %d sockets NOT listening on systemd family %s port %d.", + MAX_LISTEN_SOCKETS, + socketpeer.ss.ss_family == AF_INET ? "IPv4" : "IPv6", + ntohs(socketpeer.ss.ss_family == AF_INET ? + socketpeer.in.sin_port : socketpeer.in6.sin6_port)); + } + systemd_fd++; + } } + else + { +#endif /* HAVE_SYSTEMD */ + if (mysql_socket_getfd(base_ip_sock) != INVALID_SOCKET) + { + setup_fds(base_ip_sock, AF_INET); + ip_flags = fcntl(mysql_socket_getfd(base_ip_sock), F_GETFL, 0); + } + if (mysql_socket_getfd(extra_ip_sock) != INVALID_SOCKET) + { + setup_fds(extra_ip_sock, AF_INET); + extra_ip_flags = fcntl(mysql_socket_getfd(extra_ip_sock), F_GETFL, 0); + } #ifdef HAVE_SYS_UN_H - setup_fds(unix_sock); - socket_flags=fcntl(mysql_socket_getfd(unix_sock), F_GETFL, 0); + setup_fds(unix_sock, AF_UNIX); + socket_flags=fcntl(mysql_socket_getfd(unix_sock), F_GETFL, 0); +#endif + +#ifdef HAVE_SYSTEMD + } + +#ifdef HAVE_POLL + if (systemd_listen_cnt == 0) + { + sd_notify(0, "STATUS=No listening sockets"); + abort_loop=1; + } + else + { #endif + sd_notify(0, "READY=1\n" + "STATUS=Taking your SQL requests now..."); +#ifdef HAVE_POLL + } +#endif /* HAVE_POLL */ +#endif /* HAVE_SYSTEMD */ DBUG_PRINT("general",("Waiting for connections.")); MAYBE_BROKEN_SYSCALL; @@ -6146,6 +6340,7 @@ void handle_connections_sockets() { sock= pfs_fds[i]; flags= fcntl(mysql_socket_getfd(sock), F_GETFL, 0); + is_unix_sock= fd_type[i] == AF_UNIX; break; } } @@ -6154,18 +6349,39 @@ void handle_connections_sockets() { sock= base_ip_sock; flags= ip_flags; + is_unix_sock= FALSE; } else if (FD_ISSET(mysql_socket_getfd(extra_ip_sock),&readFDs)) { sock= extra_ip_sock; flags= extra_ip_flags; + is_unix_sock= FALSE; } +#ifdef HAVE_SYS_UN_H else + if (FD_ISSET(mysql_socket_getfd(unix_sock),&readFDs)) { sock = unix_sock; flags= socket_flags; + is_unix_sock= TRUE; + } +#endif +#ifdef HAVE_SYSTEMD + else + { + for (int i= 0; i < socket_count; ++i) + { + if (FD_ISSET(mysql_socket_getfd(pfs_fds[i]),&readFDs)) + { + sock= pfs_fds[i]; + flags= pfs_flags[i]; + is_unix_sock= fd_type[i] == AF_UNIX; + break; + } + } } +#endif // HAVE_SYSTEMD #endif // HAVE_POLL #if !defined(NO_FCNTL_NONBLOCK) @@ -6277,9 +6493,6 @@ void handle_connections_sockets() /* Set to get io buffers to be part of THD */ set_current_thd(thd); - is_unix_sock= (mysql_socket_getfd(sock) == - mysql_socket_getfd(unix_sock)); - if (!(vio_tmp= mysql_socket_vio_new(new_sock, is_unix_sock ? VIO_TYPE_SOCKET : VIO_TYPE_TCPIP, @@ -6316,6 +6529,9 @@ void handle_connections_sockets() create_new_thread(thd); set_current_thd(0); } +#ifdef HAVE_SYSTEMD + sd_notify(0, "STOPPING=1"); +#endif DBUG_VOID_RETURN; } @@ -9665,9 +9881,17 @@ void init_server_psi_keys(void) count= array_elements(all_server_stages); mysql_stage_register(category, all_server_stages, count); - - count= array_elements(all_server_sockets); - mysql_socket_register(category, all_server_sockets, count); +#ifdef HAVE_PSI_SOCKET_INTERFACE +#ifdef HAVE_SYSTEMD + if (systemd_listen_cnt == 0) + { +#endif + count= array_elements(all_server_sockets); + mysql_socket_register(category, all_server_sockets, count); +#ifdef HAVE_SYSTEMD + } +#endif +#endif #ifdef HAVE_PSI_STATEMENT_INTERFACE init_sql_statement_info(); diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 4980ba06604f5..aa62bdbbe2286 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -7111,3 +7111,5 @@ ER_SLAVE_SKIP_NOT_IN_GTID eng "When using GTID, @@sql_slave_skip_counter can not be used. Instead, setting @@gtid_slave_pos explicitly can be used to skip to after a given GTID position." ER_TABLE_DEFINITION_TOO_BIG eng "The definition for table %`s is too big" +ER_SYSTEMD_LISTEN_FDS + eng "Systemd error for configured ListenStream" diff --git a/support-files/mariadb-socket-convert b/support-files/mariadb-socket-convert new file mode 100644 index 0000000000000..7e62391aa8891 --- /dev/null +++ b/support-files/mariadb-socket-convert @@ -0,0 +1,150 @@ +#! /bin/bash +# +# Used to generate a mariadb.socket file based on the curent mysql/maridb settings +# +# This is to assist distro maintainers in migrating to systemd socket activation from +# a user system with networking settings somewhere in the my.cnf files. +# +# Redirect output to user directory like /etc/systemd/system/mariadb.socket.d/migrated-from-my.cnf-settings.conf + + +print_ports() +{ +if [ -n "${port}" ]; then + echo "ListenStream=${bind}${port}" +fi +if [ -n "${extraport}" ]; then + echo "ListenStream=${bind}${extraport}" +fi +} + +bindaddress= +port= +extraport= +backlog= +maxconnections= +skip_networking= +socket= + +coproc mysqldefaults { /usr/bin/my_print_defaults --mysqld ; } +while read var; do + key=${var%%=*} + val=${var#*=} + case "${key}" in + --bind-address) + bindaddress=$val + ;; + --bind_address) + bindaddress=$val + ;; + --port) + port=$val + ;; + --extra-port) + extraport=$val + ;; + --extra_port) + extraport=$val + ;; + --backlog) + backlog=$val + ;; + --max-connections) + maxconnections=$val + ;; + --max_connections) + maxconnections=$val + ;; + --skip-networking) + if [ -z "${val}" ]; then + skipnetworking=1 + else + skipnetworking=$val + fi + ;; + --skip_networking) + if [ -z "${val}" ]; then + skipnetworking=1 + else + skipnetworking=$val + fi + ;; + --socket) + socket=$val + ;; + esac +done < /dev/fd/${mysqldefaults[0]} + +echo '[Socket]' + +if [ -n "${backlog}" ]; then + echo "Backlog=${backlog}" +elif [ -n "${maxconnections}" ]; then + if [ $maxconnections -gt 150 ]; then + echo "Backlog=150" + else + echo "Backlog=${maxconnections}" + fi +fi + +if [ -n "${port}" -o \ + -n "${extraport}" -o \ + "${skipnetworking}" = '0' -o \ + -n "${bindaddress}" -o \ + -n "${socket}" ]; then + # we've set unix or inet sockets to non default + # reset the ListenStream list to empty + echo "ListenStream=" + # if port isn't set it really needs to be to + # fill out the details + [ -z "${port}" ] && port=3306 + # socket has a default value so ensure that is set + [ -z "${socket}" ] && socket=/var/lib/mysql/mysql.sock +else + exit 0 +fi + +if [ -n "${socket}" ]; then + echo "ListenStream=${socket}" +fi + +if [ -n "${skipnetworking}" ]; then + [ "${skipnetworking}" = '0' ] && exit 0 +fi + +if [ -n "${bindaddress}" ]; then + if [ "${bindaddress}" = "*" ]; then + # old wildcard + bind= + print_ports + elif [[ "${bindaddress}" =~ [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} ]]; then + # roughly IPv4 + bind=${bindaddress}: + print_ports + elif [[ "${bindaddress}" =~ ([0-9a-fA-F]{0,4}::?){1,7}[0-9a-fA-F]{0,4} ]]; then + # roughly IPv6 + bind=[${bindaddress}]: + print_ports + else + # hostname + # Systemd.sockets don't support it so look it up + coproc hosts { host ${bindaddress}; } + while read var; do + if [[ "${var}" = *IPv6\ address* ]]; then + bind=[${var##* }]: + print_ports + break + else + bind=${var##* }: + print_ports + fi + done < /dev/fd/${hosts[0]} + fi +else + bind='' + print_ports +fi + + +exit 0 + diff --git a/support-files/mariadb-systemd-start b/support-files/mariadb-systemd-start new file mode 100644 index 0000000000000..08f0c87007e0b --- /dev/null +++ b/support-files/mariadb-systemd-start @@ -0,0 +1,44 @@ +#! /bin/bash +# +# Scripts to run by MySQL systemd service +# +# +# try to run mysql_install_db and fix perms and SELinux contexts + +install_db () { + # Note: something different than datadir=/var/lib/mysql requires SELinux policy changes (in enforcing mode) + datadir=/var/lib/mysql + log=/var/log/mysqld.log + coproc mysqldefaults { /usr/bin/my_print_defaults --mysqld ; } + while read var; do + key=${var%%=*} + if [ "${key}" = '--datadir' ]; then + datadir=${var#*=} + fi + if [ "${key}" = '--log-error' ] || [ "${key}" = '--log_error' ]; then + log=${var#*=} + fi + done < /dev/fd/${mysqldefaults[0]} + + # Restore log, dir, perms and SELinux contexts + [ -d "$datadir" ] || install -d -m 0755 -omysql -gmysql "$datadir" || exit 1 + [ -e $log ] || touch $log + chmod 0640 $log + chown mysql:mysql $log || exit 1 + if [ -x /usr/sbin/restorecon ]; then + /usr/sbin/restorecon "$datadir" + /usr/sbin/restorecon $log + fi + + # If special mysql dir is in place, skip db install + [ -d "$datadir/mysql" ] && exit 0 + + # Create initial db + /usr/bin/mysql_install_db --rpm --datadir="$datadir" --user=mysql + exit 0 +} + +install_db + +exit 0 + diff --git a/support-files/mariadb.service b/support-files/mariadb.service new file mode 100644 index 0000000000000..09e321f6d7f03 --- /dev/null +++ b/support-files/mariadb.service @@ -0,0 +1,104 @@ +# +# /etc/systemd/system/mariadb.service +# + +[Unit] +Description=MariaDB database server +After=network.target +After=syslog.target +Requires=%p.socket + +[Install] +WantedBy=multi-user.target +Alias=mysql.service +Alias=mysqld.service + + +[Service] + +############################################################################## +## Core requirements +## + +Type=Notify + +# Setting this to true can break replication and the Type=Notify settings +PrivateNetwork=false + +############################################################################## +## Package maintainers +## + +User=mysql + +# Execute pre and post scripts as root +PermissionsStartOnly=true + +# Needed to create system tables etc. +ExecStartPre=/usr/bin/mariadb-systemd-start + +# Start main service +# skip-networking as its socket activation based +ExecStart=/usr/sbin/mysqld $OPTIONS + +KillMode=process +KillSignal=SIGTERM +# Don't want to see an automated SIGKILL ever +SendSIGKILL=no + +RestartPreventExitStatus=1 +Restart=on-fail +RestartSec=5s + +PrivateTmp=true +PrivateDevices=true + +UMask=077 +WorkingDirectory=/ +# To avoid mysql reading /root/.my.cnf which according to debian init script is +# problematic +Environment="HOME=" + +############################################################################## +## USERs can override +## +## +## by creating a file in /etc/systemd/system/mariadb.server.d/MY_SPECIAL.conf + +# Useful options not previously available in [mysqld_safe] + +OOMScoreAdjust=-600 + +BlockIOWeight=1000 + +## +## Options previously available to be set via [mysqld_safe] +## that now needs to be set by systemd config files as mysqld_safe +## isn't executed. +## + +# Number of files limit. previously [mysqld_safe] open-file-limit +LimitNOFILE=16364 + +# Maximium core size. previously [mysqld_safe] core-file-size +# LimitCore= + +# Nice priority. previously [mysqld_safe] nice +# Nice=-5 + +# Timezone. previously [mysqld_safe] timezone +# Environment="TZ=UTC" + +# Library substitutions. previously [mysqld_safe] malloc-lib with explict paths +# (in LD_LIBRARY_PATH) and library name (in LD_PRELOAD). +# Environment="LD_LIBRARY_PATH=/path1 /path2" "LD_PRELOAD= + +# Flush caches. previously [mysqld_safe] flush-caches=1 +# ExecStartPre=sync +# ExecStartPre=sysctl -q -w vm.drop_caches=3 + +# numa-interleave=1 equalivant +# Change ExecStart=numactl --interleave=all /usr/sbin/mysqld...... + +# crash-script equalivent +# FailureAction= diff --git a/support-files/mariadb.socket b/support-files/mariadb.socket new file mode 100644 index 0000000000000..5b71ca562f99d --- /dev/null +++ b/support-files/mariadb.socket @@ -0,0 +1,41 @@ +[Unit] +Description=MySQL/MariaDB Sockets + +[Install] +WantedBy=sockets.target +Alias=mysql.socket +Alias=mysqld.socket + +[Socket] +############################################################################## +## Core requirements +## + +KeepAlive=true + +# +# NonBlocking=true and NoDelay=true (if NonBlocking=true is unavailable) are +# already set by MariaDB + +############################################################################## +## DISTRIBUTION maintainers +## + +SocketUser=mysql +SocketMode=777 + +############################################################################## +## +## USERs can override +## +## See man systemd.socket.5 for meanings +## +## Override by creating a file in /etc/systemd/system/mariadb.socket.d/MY_SPECIAL.conf +## see man systemd.unit.5 + +ListenStream=/var/lib/mysql/mysql.sock +ListenStream=[::1]:3306 +ListenStream=127.0.0.1:3306 +BindToDevice= + +Backlog=150 From 3c9c925f9245f5f88feb68e2a893544b1778d0b0 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 12 Mar 2015 08:08:25 +1100 Subject: [PATCH 04/32] systemd notification messages for innodb status Add systemd notification for long and intrustive innodb events to report to systemd status monitoring' --- storage/innobase/buf/buf0dump.cc | 10 ++++++++++ storage/innobase/log/log0recv.cc | 30 ++++++++++++++++++++++++------ storage/xtradb/buf/buf0dump.cc | 10 ++++++++++ storage/xtradb/log/log0recv.cc | 30 ++++++++++++++++++++++++------ 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/storage/innobase/buf/buf0dump.cc b/storage/innobase/buf/buf0dump.cc index 467f817a2d1a7..50769e594b22a 100644 --- a/storage/innobase/buf/buf0dump.cc +++ b/storage/innobase/buf/buf0dump.cc @@ -27,6 +27,9 @@ Created April 08, 2011 Vasil Dimov #include /* va_* */ #include /* strerror() */ +#ifdef HAVE_SYSTEMD +#include +#endif #include "buf0buf.h" /* buf_pool_mutex_enter(), srv_buf_pool_instances */ #include "buf0dump.h" @@ -198,6 +201,10 @@ buf_dump( buf_dump_status(STATUS_NOTICE, "Dumping buffer pool(s) to %s", full_filename); +#ifdef HAVE_SYSTEMD + sd_notifyf(0, "STATUS=Dumping buffer pool(s) to %s", full_filename); +#endif + f = fopen(tmp_filename, "w"); if (f == NULL) { @@ -322,6 +329,9 @@ buf_dump( buf_dump_status(STATUS_NOTICE, "Buffer pool(s) dump completed at %s", now); +#ifdef HAVE_SYSTEMD + sd_notifyf(0, "STATUS=Buffer pool(s) dump completed at %s", full_filename); +#endif } /*****************************************************************//** diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index aa6c81483d719..6590b47e22d09 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -29,6 +29,10 @@ Created 9/20/1997 Heikki Tuuri #include // Solaris/x86 header file bug #include +#ifdef HAVE_SYSTEMD +#include +#endif + #include "log0recv.h" #ifdef UNIV_NONINL @@ -1849,6 +1853,7 @@ recv_apply_hashed_log_recs( recv_addr_t* recv_addr; ulint i; ibool has_printed = FALSE; + ulong progress; mtr_t mtr; loop: mutex_enter(&(recv_sys->mutex)); @@ -1918,14 +1923,17 @@ recv_apply_hashed_log_recs( } } + progress=(ulong) (i * 100) / hash_get_n_cells(recv_sys->addr_hash); if (has_printed - && (i * 100) / hash_get_n_cells(recv_sys->addr_hash) - != ((i + 1) * 100) - / hash_get_n_cells(recv_sys->addr_hash)) { + && progress != ((i + 1) * 100) + / hash_get_n_cells(recv_sys->addr_hash)) { + + fprintf(stderr, "%lu ", progress); +#ifdef HAVE_SYSTEMD + sd_notifyf(0, "STATUS=Applying batch of log records for Innodb: " + "Progress %lu", progress); +#endif - fprintf(stderr, "%lu ", (ulong) - ((i * 100) - / hash_get_n_cells(recv_sys->addr_hash))); } } @@ -1987,6 +1995,9 @@ recv_apply_hashed_log_recs( if (has_printed) { fprintf(stderr, "InnoDB: Apply batch completed\n"); +#ifdef HAVE_SYSTEMD + sd_notify(0, "STATUS=InnoDB: Apply batch completed"); +#endif } mutex_exit(&(recv_sys->mutex)); @@ -2134,8 +2145,15 @@ recv_apply_log_recs_for_backup(void) fprintf(stderr, "%lu ", (ulong) ((100 * i) / n_hash_cells)); fflush(stderr); +#ifdef HAVE_SYSTEMD + sd_notifyf(0, "STATUS=Applying batch of log records for backup Innodb: " + "Progress %lu", (ulong) (100 * i) / n_hash_cells); +#endif } } +#ifdef HAVE_SYSTEMD + sd_notify(0, "STATUS=InnoDB: Apply batch for backup completed"); +#endif recv_sys_empty_hash(); } diff --git a/storage/xtradb/buf/buf0dump.cc b/storage/xtradb/buf/buf0dump.cc index 090e8cac63be0..0c45bf92e8994 100644 --- a/storage/xtradb/buf/buf0dump.cc +++ b/storage/xtradb/buf/buf0dump.cc @@ -27,6 +27,9 @@ Created April 08, 2011 Vasil Dimov #include /* va_* */ #include /* strerror() */ +#ifdef HAVE_SYSTEMD +#include +#endif #include "buf0buf.h" /* srv_buf_pool_instances */ #include "buf0dump.h" @@ -198,6 +201,10 @@ buf_dump( buf_dump_status(STATUS_NOTICE, "Dumping buffer pool(s) to %s", full_filename); +#ifdef HAVE_SYSTEMD + sd_notifyf(0, "STATUS=Dumping buffer pool(s) to %s", full_filename); +#endif + f = fopen(tmp_filename, "w"); if (f == NULL) { @@ -322,6 +329,9 @@ buf_dump( buf_dump_status(STATUS_NOTICE, "Buffer pool(s) dump completed at %s", now); +#ifdef HAVE_SYSTEMD + sd_notifyf(0, "STATUS=Buffer pool(s) dump completed at %s", full_filename); +#endif } /*****************************************************************//** diff --git a/storage/xtradb/log/log0recv.cc b/storage/xtradb/log/log0recv.cc index f3c4887874d89..d74733eb3189d 100644 --- a/storage/xtradb/log/log0recv.cc +++ b/storage/xtradb/log/log0recv.cc @@ -29,6 +29,10 @@ Created 9/20/1997 Heikki Tuuri #include // Solaris/x86 header file bug #include +#ifdef HAVE_SYSTEMD +#include +#endif + #include "log0recv.h" #ifdef UNIV_NONINL @@ -1920,6 +1924,7 @@ recv_apply_hashed_log_recs( recv_addr_t* recv_addr; ulint i; ibool has_printed = FALSE; + ulong progress; mtr_t mtr; loop: mutex_enter(&(recv_sys->mutex)); @@ -1989,14 +1994,17 @@ recv_apply_hashed_log_recs( } } + progress=(ulong) (i * 100) / hash_get_n_cells(recv_sys->addr_hash); if (has_printed - && (i * 100) / hash_get_n_cells(recv_sys->addr_hash) - != ((i + 1) * 100) - / hash_get_n_cells(recv_sys->addr_hash)) { + && progress != ((i + 1) * 100) + / hash_get_n_cells(recv_sys->addr_hash)) { + + fprintf(stderr, "%lu ", progress); +#ifdef HAVE_SYSTEMD + sd_notifyf(0, "STATUS=Applying batch of log records for Innodb: " + "Progress %lu", progress); +#endif - fprintf(stderr, "%lu ", (ulong) - ((i * 100) - / hash_get_n_cells(recv_sys->addr_hash))); } } @@ -2058,6 +2066,9 @@ recv_apply_hashed_log_recs( if (has_printed) { fprintf(stderr, "InnoDB: Apply batch completed\n"); +#ifdef HAVE_SYSTEMD + sd_notify(0, "STATUS=InnoDB: Apply batch completed"); +#endif } mutex_exit(&(recv_sys->mutex)); @@ -2205,8 +2216,15 @@ recv_apply_log_recs_for_backup(void) fprintf(stderr, "%lu ", (ulong) ((100 * i) / n_hash_cells)); fflush(stderr); +#ifdef HAVE_SYSTEMD + sd_notifyf(0, "STATUS=Applying batch of log records for backup Innodb: " + "Progress %lu", (ulong) (100 * i) / n_hash_cells); +#endif } } +#ifdef HAVE_SYSTEMD + sd_notify(0, "STATUS=InnoDB: Apply batch for backup completed"); +#endif recv_sys_empty_hash(); } From 04f52db1895548bca41df9595c13add595aea528 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 12 Mar 2015 09:06:39 +1100 Subject: [PATCH 05/32] whitespace fix --- storage/innobase/log/log0recv.cc | 2 +- storage/xtradb/log/log0recv.cc | 2 +- support-files/mariadb-socket-convert | 6 +++--- support-files/mariadb-systemd-start | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index 6590b47e22d09..4ce7fe805ac20 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -1925,7 +1925,7 @@ recv_apply_hashed_log_recs( progress=(ulong) (i * 100) / hash_get_n_cells(recv_sys->addr_hash); if (has_printed - && progress != ((i + 1) * 100) + && progress != ((i + 1) * 100) / hash_get_n_cells(recv_sys->addr_hash)) { fprintf(stderr, "%lu ", progress); diff --git a/storage/xtradb/log/log0recv.cc b/storage/xtradb/log/log0recv.cc index d74733eb3189d..cd5d964059f2e 100644 --- a/storage/xtradb/log/log0recv.cc +++ b/storage/xtradb/log/log0recv.cc @@ -1996,7 +1996,7 @@ recv_apply_hashed_log_recs( progress=(ulong) (i * 100) / hash_get_n_cells(recv_sys->addr_hash); if (has_printed - && progress != ((i + 1) * 100) + && progress != ((i + 1) * 100) / hash_get_n_cells(recv_sys->addr_hash)) { fprintf(stderr, "%lu ", progress); diff --git a/support-files/mariadb-socket-convert b/support-files/mariadb-socket-convert index 7e62391aa8891..84193eefab630 100644 --- a/support-files/mariadb-socket-convert +++ b/support-files/mariadb-socket-convert @@ -1,8 +1,8 @@ -#! /bin/bash +#!/bin/bash # # Used to generate a mariadb.socket file based on the curent mysql/maridb settings # -# This is to assist distro maintainers in migrating to systemd socket activation from +# This is to assist distro maintainers in migrating to systemd socket activation from # a user system with networking settings somewhere in the my.cnf files. # # Redirect output to user directory like /etc/systemd/system/mariadb.socket.d/migrated-from-my.cnf-settings.conf @@ -95,7 +95,7 @@ if [ -n "${port}" -o \ # we've set unix or inet sockets to non default # reset the ListenStream list to empty echo "ListenStream=" - # if port isn't set it really needs to be to + # if port isn't set it really needs to be to # fill out the details [ -z "${port}" ] && port=3306 # socket has a default value so ensure that is set diff --git a/support-files/mariadb-systemd-start b/support-files/mariadb-systemd-start index 08f0c87007e0b..ce4d9ce91b2dc 100644 --- a/support-files/mariadb-systemd-start +++ b/support-files/mariadb-systemd-start @@ -1,11 +1,11 @@ -#! /bin/bash +#!/bin/bash # # Scripts to run by MySQL systemd service # # # try to run mysql_install_db and fix perms and SELinux contexts -install_db () { +install_db () { # Note: something different than datadir=/var/lib/mysql requires SELinux policy changes (in enforcing mode) datadir=/var/lib/mysql log=/var/log/mysqld.log @@ -30,7 +30,7 @@ install_db () { /usr/sbin/restorecon $log fi - # If special mysql dir is in place, skip db install + # If special mysql dir is in place, skip db install [ -d "$datadir/mysql" ] && exit 0 # Create initial db From 2f140dc3e3b5e3fc060fbaadfb96a11f62795146 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 12 Mar 2015 17:19:28 +1100 Subject: [PATCH 06/32] whitespace extra --- support-files/mariadb-socket-convert | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support-files/mariadb-socket-convert b/support-files/mariadb-socket-convert index 84193eefab630..6dbfa51de31aa 100644 --- a/support-files/mariadb-socket-convert +++ b/support-files/mariadb-socket-convert @@ -47,7 +47,7 @@ while read var; do extraport=$val ;; --backlog) - backlog=$val + backlog=$val ;; --max-connections) maxconnections=$val From 8c607c24fad43f81581c4327602b298262071a4d Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 12 Mar 2015 17:22:40 +1100 Subject: [PATCH 07/32] Extend ib_logf to use that for sd_notifyf To extend the number of status messages available to innodb moved the sd_notifyf into ib_logf. Suggested by Jan Lindstrom. --- storage/innobase/buf/buf0dump.cc | 10 ---------- storage/innobase/handler/ha_innodb.cc | 16 ++++++++++++++++ storage/xtradb/buf/buf0dump.cc | 10 ---------- storage/xtradb/handler/ha_innodb.cc | 17 +++++++++++++++++ 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/storage/innobase/buf/buf0dump.cc b/storage/innobase/buf/buf0dump.cc index 50769e594b22a..467f817a2d1a7 100644 --- a/storage/innobase/buf/buf0dump.cc +++ b/storage/innobase/buf/buf0dump.cc @@ -27,9 +27,6 @@ Created April 08, 2011 Vasil Dimov #include /* va_* */ #include /* strerror() */ -#ifdef HAVE_SYSTEMD -#include -#endif #include "buf0buf.h" /* buf_pool_mutex_enter(), srv_buf_pool_instances */ #include "buf0dump.h" @@ -201,10 +198,6 @@ buf_dump( buf_dump_status(STATUS_NOTICE, "Dumping buffer pool(s) to %s", full_filename); -#ifdef HAVE_SYSTEMD - sd_notifyf(0, "STATUS=Dumping buffer pool(s) to %s", full_filename); -#endif - f = fopen(tmp_filename, "w"); if (f == NULL) { @@ -329,9 +322,6 @@ buf_dump( buf_dump_status(STATUS_NOTICE, "Buffer pool(s) dump completed at %s", now); -#ifdef HAVE_SYSTEMD - sd_notifyf(0, "STATUS=Buffer pool(s) dump completed at %s", full_filename); -#endif } /*****************************************************************//** diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index fde94a15a2820..c8ed0aaa6bf69 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -48,6 +48,10 @@ this program; if not, write to the Free Software Foundation, Inc., #include #endif +#ifdef HAVE_SYSTEMD +#include +#endif + /** @file ha_innodb.cc */ /* Include necessary InnoDB headers */ @@ -17540,15 +17544,27 @@ ib_logf( switch(level) { case IB_LOG_LEVEL_INFO: sql_print_information("InnoDB: %s", str); +#ifdef HAVE_SYSTEMD + sd_notifyf(0, "STATUS=InnoDB: Info: %s", str); +#endif break; case IB_LOG_LEVEL_WARN: sql_print_warning("InnoDB: %s", str); +#ifdef HAVE_SYSTEMD + sd_notifyf(0, "STATUS=InnoDB: Warning: %s", str); +#endif break; case IB_LOG_LEVEL_ERROR: sql_print_error("InnoDB: %s", str); +#ifdef HAVE_SYSTEMD + sd_notifyf(0, "STATUS=InnoDB: Error: %s", str); +#endif break; case IB_LOG_LEVEL_FATAL: sql_print_error("InnoDB: %s", str); +#ifdef HAVE_SYSTEMD + sd_notifyf(0, "STATUS=InnoDB: Fatal: %s", str); +#endif break; } diff --git a/storage/xtradb/buf/buf0dump.cc b/storage/xtradb/buf/buf0dump.cc index 0c45bf92e8994..090e8cac63be0 100644 --- a/storage/xtradb/buf/buf0dump.cc +++ b/storage/xtradb/buf/buf0dump.cc @@ -27,9 +27,6 @@ Created April 08, 2011 Vasil Dimov #include /* va_* */ #include /* strerror() */ -#ifdef HAVE_SYSTEMD -#include -#endif #include "buf0buf.h" /* srv_buf_pool_instances */ #include "buf0dump.h" @@ -201,10 +198,6 @@ buf_dump( buf_dump_status(STATUS_NOTICE, "Dumping buffer pool(s) to %s", full_filename); -#ifdef HAVE_SYSTEMD - sd_notifyf(0, "STATUS=Dumping buffer pool(s) to %s", full_filename); -#endif - f = fopen(tmp_filename, "w"); if (f == NULL) { @@ -329,9 +322,6 @@ buf_dump( buf_dump_status(STATUS_NOTICE, "Buffer pool(s) dump completed at %s", now); -#ifdef HAVE_SYSTEMD - sd_notifyf(0, "STATUS=Buffer pool(s) dump completed at %s", full_filename); -#endif } /*****************************************************************//** diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index aaeebf91e24bc..0414be73a85f9 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -49,6 +49,11 @@ this program; if not, write to the Free Software Foundation, Inc., #ifdef _WIN32 #include #endif + +#ifdef HAVE_SYSTEMD +#include +#endif + /** @file ha_innodb.cc */ /* Include necessary InnoDB headers */ @@ -18804,15 +18809,27 @@ ib_logf( switch(level) { case IB_LOG_LEVEL_INFO: sql_print_information("InnoDB: %s", str); +#ifdef HAVE_SYSTEMD + sd_notifyf(0, "STATUS=InnoDB: Info: %s", str); +#endif break; case IB_LOG_LEVEL_WARN: sql_print_warning("InnoDB: %s", str); +#ifdef HAVE_SYSTEMD + sd_notifyf(0, "STATUS=InnoDB: Warning: %s", str); +#endif break; case IB_LOG_LEVEL_ERROR: sql_print_error("InnoDB: %s", str); +#ifdef HAVE_SYSTEMD + sd_notifyf(0, "STATUS=InnoDB: Error: %s", str); +#endif break; case IB_LOG_LEVEL_FATAL: sql_print_error("InnoDB: %s", str); +#ifdef HAVE_SYSTEMD + sd_notifyf(0, "STATUS=InnoDB: Fatal: %s", str); +#endif break; } From d0619cdbf3b35dd4dd941de643a674347f87d394 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 12 Mar 2015 18:01:09 +1100 Subject: [PATCH 08/32] buf_dump_status to use ib_logf --- storage/innobase/buf/buf0dump.cc | 3 +-- storage/xtradb/buf/buf0dump.cc | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/storage/innobase/buf/buf0dump.cc b/storage/innobase/buf/buf0dump.cc index 467f817a2d1a7..136e064cae175 100644 --- a/storage/innobase/buf/buf0dump.cc +++ b/storage/innobase/buf/buf0dump.cc @@ -125,9 +125,8 @@ buf_dump_status( if (severity == STATUS_NOTICE || severity == STATUS_ERR) { ut_print_timestamp(stderr); - fprintf(stderr, " InnoDB: %s\n", - export_vars.innodb_buffer_pool_dump_status); } + ib_logf(severity, export_vars.innodb_buffer_pool_dump_status); va_end(ap); } diff --git a/storage/xtradb/buf/buf0dump.cc b/storage/xtradb/buf/buf0dump.cc index 090e8cac63be0..28eed322ac595 100644 --- a/storage/xtradb/buf/buf0dump.cc +++ b/storage/xtradb/buf/buf0dump.cc @@ -125,9 +125,8 @@ buf_dump_status( if (severity == STATUS_NOTICE || severity == STATUS_ERR) { ut_print_timestamp(stderr); - fprintf(stderr, " InnoDB: %s\n", - export_vars.innodb_buffer_pool_dump_status); } + ib_logf(severity, export_vars.innodb_buffer_pool_dump_status); va_end(ap); } From db1910a09d33ad4e8233fc79fdc7d782650a1000 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 12 Mar 2015 18:19:21 +1100 Subject: [PATCH 09/32] cast enum status_severity to ib_log_level_t --- storage/innobase/buf/buf0dump.cc | 2 +- storage/xtradb/buf/buf0dump.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/storage/innobase/buf/buf0dump.cc b/storage/innobase/buf/buf0dump.cc index 136e064cae175..053aafceb79bd 100644 --- a/storage/innobase/buf/buf0dump.cc +++ b/storage/innobase/buf/buf0dump.cc @@ -126,7 +126,7 @@ buf_dump_status( if (severity == STATUS_NOTICE || severity == STATUS_ERR) { ut_print_timestamp(stderr); } - ib_logf(severity, export_vars.innodb_buffer_pool_dump_status); + ib_logf((ib_log_level_t) severity, export_vars.innodb_buffer_pool_dump_status); va_end(ap); } diff --git a/storage/xtradb/buf/buf0dump.cc b/storage/xtradb/buf/buf0dump.cc index 28eed322ac595..856e53815290b 100644 --- a/storage/xtradb/buf/buf0dump.cc +++ b/storage/xtradb/buf/buf0dump.cc @@ -126,7 +126,7 @@ buf_dump_status( if (severity == STATUS_NOTICE || severity == STATUS_ERR) { ut_print_timestamp(stderr); } - ib_logf(severity, export_vars.innodb_buffer_pool_dump_status); + ib_logf((ib_log_level_t) severity, export_vars.innodb_buffer_pool_dump_status); va_end(ap); } From 44d739c914e997867ecb095d3c2ca48f0e0c3bb6 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 13 Mar 2015 00:18:01 +1100 Subject: [PATCH 10/32] mariadb-socket-convert script improvements handing missing /usr/bin/host executable Default to *:ports if can't resolve bindaddress Comment why we put and empty ListenStream= line --- support-files/mariadb-socket-convert | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) mode change 100644 => 100755 support-files/mariadb-socket-convert diff --git a/support-files/mariadb-socket-convert b/support-files/mariadb-socket-convert old mode 100644 new mode 100755 index 6dbfa51de31aa..9c15db4890bbc --- a/support-files/mariadb-socket-convert +++ b/support-files/mariadb-socket-convert @@ -93,8 +93,9 @@ if [ -n "${port}" -o \ -n "${bindaddress}" -o \ -n "${socket}" ]; then # we've set unix or inet sockets to non default - # reset the ListenStream list to empty + echo "# reset the ListenStream list to empty" echo "ListenStream=" + echo # if port isn't set it really needs to be to # fill out the details [ -z "${port}" ] && port=3306 @@ -125,7 +126,7 @@ if [ -n "${bindaddress}" ]; then # roughly IPv6 bind=[${bindaddress}]: print_ports - else + elif [ -x /usr/bin/host ]; then # hostname # Systemd.sockets don't support it so look it up coproc hosts { host ${bindaddress}; } @@ -139,6 +140,10 @@ if [ -n "${bindaddress}" ]; then print_ports fi done < /dev/fd/${hosts[0]} + else + echo "Warning: bindaddress=${bindaddress} was a hostname we couldn't resolve. using all interfaces" >&2 + bind= + print_ports fi else bind='' From eab04816ec34f84feafbc25636dcb2d483dbdd69 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 13 Mar 2015 00:21:31 +1100 Subject: [PATCH 11/32] debian/ubuntu packaging of socket activation helpers --- debian/dist/Debian/mariadb-server-10.0.files.in | 2 ++ debian/dist/Debian/mariadb-server-10.0.postinst | 6 ++++++ debian/dist/Debian/rules | 4 ++++ debian/dist/Ubuntu/mariadb-server-10.0.files.in | 2 ++ debian/dist/Ubuntu/mariadb-server-10.0.postinst | 6 ++++++ debian/dist/Ubuntu/rules | 4 ++++ 6 files changed, 24 insertions(+) diff --git a/debian/dist/Debian/mariadb-server-10.0.files.in b/debian/dist/Debian/mariadb-server-10.0.files.in index 88516bb6089b1..2201e120b8d02 100644 --- a/debian/dist/Debian/mariadb-server-10.0.files.in +++ b/debian/dist/Debian/mariadb-server-10.0.files.in @@ -43,6 +43,8 @@ usr/bin/perror usr/bin/replace usr/bin/resolve_stack_dump usr/bin/resolveip +usr/bin/mariadb-socket-convert +usr/bin/mariadb-systemd-start usr/share/doc/mariadb-server-10.0/mysqld.sym.gz usr/share/doc/mariadb-server-10.0/INFO_SRC usr/share/doc/mariadb-server-10.0/INFO_BIN diff --git a/debian/dist/Debian/mariadb-server-10.0.postinst b/debian/dist/Debian/mariadb-server-10.0.postinst index 19594fb910eb2..d392bec9971af 100644 --- a/debian/dist/Debian/mariadb-server-10.0.postinst +++ b/debian/dist/Debian/mariadb-server-10.0.postinst @@ -260,6 +260,12 @@ if [ "$1" = "configure" ]; then db_go fi + # create a systemd socket activation file based on current settings + systemd_sockconf=/etc/systemd/system/mariadb.socket.d/migrated-from-my.cnf-settings.conf + if [ -x /usr/bin/mariadb-socket-convert -a ! -f "${systemd_sockconf}" ]; then + mkdir -p /etc/systemd/system/mariadb.socket.d + /usr/bin/mariadb-socket-convert > "${systemd_sockconf}" + fi fi db_stop # in case invoke failes diff --git a/debian/dist/Debian/rules b/debian/dist/Debian/rules index 5dba5d1c79302..3edf15d21ccda 100755 --- a/debian/dist/Debian/rules +++ b/debian/dist/Debian/rules @@ -180,6 +180,10 @@ install: build install -m 0644 $(builddir)/Docs/INFO_SRC $(TMP)/usr/share/doc/mariadb-server-10.0/INFO_SRC install -m 0644 $(builddir)/Docs/INFO_BIN $(TMP)/usr/share/doc/mariadb-server-10.0/INFO_BIN + # systemd helpers + install -m 0755 support-files/mariadb-socket-convert $(TMP)/usr/bin/ + install -m 0755 support-files/mariadb-systemd-start $(TMP)/usr/bin/ + # mariadb-test mv $(TMP)/usr/mysql-test $(TMP)/usr/share/mysql diff --git a/debian/dist/Ubuntu/mariadb-server-10.0.files.in b/debian/dist/Ubuntu/mariadb-server-10.0.files.in index 849a763dccd17..82d9414aaabb6 100644 --- a/debian/dist/Ubuntu/mariadb-server-10.0.files.in +++ b/debian/dist/Ubuntu/mariadb-server-10.0.files.in @@ -45,6 +45,8 @@ usr/bin/perror usr/bin/replace usr/bin/resolve_stack_dump usr/bin/resolveip +usr/bin/mariadb-socket-convert +usr/bin/mariadb-systemd-start usr/share/doc/mariadb-server-10.0/mysqld.sym.gz usr/share/doc/mariadb-server-10.0/INFO_SRC usr/share/doc/mariadb-server-10.0/INFO_BIN diff --git a/debian/dist/Ubuntu/mariadb-server-10.0.postinst b/debian/dist/Ubuntu/mariadb-server-10.0.postinst index 1acfbc8097041..e8e0470c3b2a1 100644 --- a/debian/dist/Ubuntu/mariadb-server-10.0.postinst +++ b/debian/dist/Ubuntu/mariadb-server-10.0.postinst @@ -276,6 +276,12 @@ if [ "$1" = "configure" ]; then db_go fi + # create a systemd socket activation file based on current settings + systemd_sockconf=/etc/systemd/system/mariadb.socket.d/migrated-from-my.cnf-settings.conf + if [ -x /usr/bin/mariadb-socket-convert -a ! -f "${systemd_sockconf}" ]; then + mkdir -p /etc/systemd/system/mariadb.socket.d + /usr/bin/mariadb-socket-convert > "${systemd_sockconf}" + fi fi db_stop # in case invoke failes diff --git a/debian/dist/Ubuntu/rules b/debian/dist/Ubuntu/rules index 6cd2a15b90ac3..e2cdd3ae7cd67 100755 --- a/debian/dist/Ubuntu/rules +++ b/debian/dist/Ubuntu/rules @@ -180,6 +180,10 @@ install: build install -m 0644 $(builddir)/Docs/INFO_SRC $(TMP)/usr/share/doc/mariadb-server-10.0/INFO_SRC install -m 0644 $(builddir)/Docs/INFO_BIN $(TMP)/usr/share/doc/mariadb-server-10.0/INFO_BIN + # systemd helpers + install -m 0755 support-files/mariadb-socket-convert $(TMP)/usr/bin/ + install -m 0755 support-files/mariadb-systemd-start $(TMP)/usr/bin/ + # mariadb-test mv $(TMP)/usr/mysql-test $(TMP)/usr/share/mysql From 24c534449c1db1922cab2bb199ed391789f25378 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 15 Mar 2015 16:51:57 +1100 Subject: [PATCH 12/32] Fix for running mysqld not under socket activation but with systemd Only give "STATUS=No listening sockets" when there are no systemd sockets activated and systemd sockets where provided. --- sql/mysqld.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 6b26846072090..49bba24d1722a 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -6283,7 +6283,7 @@ void handle_connections_sockets() } #ifdef HAVE_POLL - if (systemd_listen_cnt == 0) + if (systemd_listen_cnt == 0 && systemd_n>0) { sd_notify(0, "STATUS=No listening sockets"); abort_loop=1; From f7aad0b1156ce32995175fb7bb21b3fa00ab4fbd Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 15 Mar 2015 16:58:38 +1100 Subject: [PATCH 13/32] remove additional timestamp from buf_dump_status result of set global innodb_buffer_pool_dump_now=ON; before: 2015-03-15 16:46:34 7fba7effd700150315 16:46:34 [Warning] InnoDB: Dumping buffer pool(s) to .//ib_buffer_pool 150315 16:46:34 [Note] InnoDB: Dumping buffer pool 1/1, page 1/154 150315 16:46:34 [Note] InnoDB: Dumping buffer pool 1/1, page 129/154 2015-03-15 16:46:34 7fba7effd700150315 16:46:34 [Warning] InnoDB: Buffer pool(s) dump completed at 150315 16:46:34 after: 150315 16:57:45 [Warning] InnoDB: Dumping buffer pool(s) to .//ib_buffer_pool 150315 16:57:45 [Note] InnoDB: Dumping buffer pool 1/1, page 1/154 150315 16:57:45 [Note] InnoDB: Dumping buffer pool 1/1, page 129/154 150315 16:57:45 [Warning] InnoDB: Buffer pool(s) dump completed at 150315 16:57:45 --- storage/innobase/buf/buf0dump.cc | 3 --- storage/xtradb/buf/buf0dump.cc | 3 --- 2 files changed, 6 deletions(-) diff --git a/storage/innobase/buf/buf0dump.cc b/storage/innobase/buf/buf0dump.cc index 053aafceb79bd..dbfd449c0bd52 100644 --- a/storage/innobase/buf/buf0dump.cc +++ b/storage/innobase/buf/buf0dump.cc @@ -123,9 +123,6 @@ buf_dump_status( sizeof(export_vars.innodb_buffer_pool_dump_status), fmt, ap); - if (severity == STATUS_NOTICE || severity == STATUS_ERR) { - ut_print_timestamp(stderr); - } ib_logf((ib_log_level_t) severity, export_vars.innodb_buffer_pool_dump_status); va_end(ap); diff --git a/storage/xtradb/buf/buf0dump.cc b/storage/xtradb/buf/buf0dump.cc index 856e53815290b..16708d3b5c59f 100644 --- a/storage/xtradb/buf/buf0dump.cc +++ b/storage/xtradb/buf/buf0dump.cc @@ -123,9 +123,6 @@ buf_dump_status( sizeof(export_vars.innodb_buffer_pool_dump_status), fmt, ap); - if (severity == STATUS_NOTICE || severity == STATUS_ERR) { - ut_print_timestamp(stderr); - } ib_logf((ib_log_level_t) severity, export_vars.innodb_buffer_pool_dump_status); va_end(ap); From bdb1870a398f83e7830382038c37dfa712971720 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sat, 20 Jun 2015 13:52:59 +1000 Subject: [PATCH 14/32] consolidate cmake defs for systemd --- configure.cmake | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/configure.cmake b/configure.cmake index 4bfe948d36dca..4c20197efab2e 100644 --- a/configure.cmake +++ b/configure.cmake @@ -162,7 +162,7 @@ IF(UNIX) ENDIF() ENDIF() - OPTION(WITH_SYSTEMD "Compile with systemd notification on ready" ON) + OPTION(WITH_SYSTEMD "Compile with systemd notification on ready" AUTO) IF(WITH_SYSTEMD) SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} systemd-daemon) CHECK_C_SOURCE_COMPILES( @@ -173,8 +173,17 @@ IF(UNIX) sd_listen_fds(0); }" HAVE_SYSTEMD) + CHECK_INCLUDE_FILES (systemd/sd-daemon.h HAVE_SYSTEMD_SD_DAEMON_H) + CHECK_FUNCTION_EXISTS (sd_listen_fds HAVE_SYSTEMD_SD_LISTEN_FDS) + CHECK_FUNCTION_EXISTS (sd_notify HAVE_SYSTEMD_SD_NOTIFY) + CHECK_FUNCTION_EXISTS (sd_notifyf HAVE_SYSTEMD_SD_NOTIFYF) IF(HAVE_SYSTEMD) SET(LIBSYSTEMD "systemd-daemon") + MESSAGE(STATUS "Systemd features enabled") + ELSE() + IF(WITH_SYSTEMD STREQUAL "YES") + MESSAGE(STATUS "Requested WITH_SYSTEMD=YES however no dependencies installed/found") + ENDIF() ENDIF() ENDIF() ENDIF() @@ -266,9 +275,6 @@ CHECK_INCLUDE_FILES (wchar.h HAVE_WCHAR_H) CHECK_INCLUDE_FILES (wctype.h HAVE_WCTYPE_H) CHECK_INCLUDE_FILES (sys/sockio.h HAVE_SYS_SOCKIO_H) CHECK_INCLUDE_FILES (sys/utsname.h HAVE_SYS_UTSNAME_H) -IF(WITH_SYSTEMD) -CHECK_INCLUDE_FILES (systemd/sd-daemon.h HAVE_SYSTEMD_SD_DAEMON_H) -ENDIF() IF(BFD_H_EXISTS) IF(NOT_FOR_DISTRIBUTION) @@ -476,12 +482,6 @@ IF(HAVE_SYS_EVENT_H) CHECK_FUNCTION_EXISTS (kqueue HAVE_KQUEUE) ENDIF() -IF(WITH_SYSTEMD) -CHECK_FUNCTION_EXISTS (sd_listen_fds HAVE_SYSTEMD_SD_DAEMON_H) -CHECK_FUNCTION_EXISTS (sd_notify HAVE_SYSTEMD_SD_DAEMON_H) -CHECK_FUNCTION_EXISTS (sd_notifyf HAVE_SYSTEMD_SD_DAEMON_H) -ENDIF() - #-------------------------------------------------------------------- # Support for WL#2373 (Use cycle counter for timing) #-------------------------------------------------------------------- From a73d3e2cc0f5f1d934f80165674c42b65ddea2b4 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sat, 20 Jun 2015 14:10:48 +1000 Subject: [PATCH 15/32] added postinst for systemd service/socket for mysql --- support-files/mysql.spec.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/support-files/mysql.spec.sh b/support-files/mysql.spec.sh index aaeed444e2f9f..3656714e24285 100644 --- a/support-files/mysql.spec.sh +++ b/support-files/mysql.spec.sh @@ -930,14 +930,25 @@ if [ -x sbin/restorecon ] ; then sbin/restorecon -R var/lib/mysql fi +# create a systemd socket activation file based on current settings +systemd_sockconf=etc/systemd/system/mariadb.socket.d/migrated-from-my.cnf-settings.conf +if [ -x usr/bin/mariadb-socket-convert -a ! -f "${systemd_sockconf}" ]; then + mkdir -p etc/systemd/system/mariadb.socket.d + usr/bin/mariadb-socket-convert > "${systemd_sockconf}" +fi +systemd_conf=etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf +if [ -x usr/bin/mariadb-service-convert -a ! -f "${systemd_conf}" ]; then + mkdir -p etc/systemd/system/mariadb.service.d + usr/bin/mariadb-service-convert > "${systemd_conf}" +fi + # Was the server running before the upgrade? If so, restart the new one. if [ "$SERVER_TO_START" = "true" ] ; then # Restart in the same way that mysqld will be started normally. - if [ -x %{_sysconfdir}/init.d/mysql ] ; then - %{_sysconfdir}/init.d/mysql start - echo "Giving mysqld 5 seconds to start" - sleep 5 - fi + systemctl start mariadb.socket + systemctl start mariadb.service + echo "Giving mysqld 5 seconds to start" + sleep 5 fi # Collect an upgrade history ... From 58e46901245116b0827cbf61e890ec6d7eb1d3bd Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sat, 20 Jun 2015 14:19:04 +1000 Subject: [PATCH 16/32] typo in mysql_socket_fd docstring --- include/mysql/psi/mysql_socket.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mysql/psi/mysql_socket.h b/include/mysql/psi/mysql_socket.h index ea44d49ea8773..d193823b94e3c 100644 --- a/include/mysql/psi/mysql_socket.h +++ b/include/mysql/psi/mysql_socket.h @@ -284,7 +284,7 @@ inline_mysql_socket_set_state(MYSQL_SOCKET socket, enum PSI_socket_state state) /** @def mysql_socket_fd(K, F) Create a socket. - @c mysql_socket_socket is a replacement for @c socket. + @c mysql_socket_fd is a replacement for @c socket. @param K PSI_socket_key for this instrumented socket @param F File descriptor */ From b481e4fa38011055f4a1236857ca98f448080b4e Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sat, 20 Jun 2015 15:51:29 +1000 Subject: [PATCH 17/32] WITH_SYSTEMD cmake option - correct tristate value --- configure.cmake | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/configure.cmake b/configure.cmake index 4c20197efab2e..4dd39da0badc6 100644 --- a/configure.cmake +++ b/configure.cmake @@ -162,8 +162,8 @@ IF(UNIX) ENDIF() ENDIF() - OPTION(WITH_SYSTEMD "Compile with systemd notification on ready" AUTO) - IF(WITH_SYSTEMD) + SET(WITH_SYSTEMD "auto" CACHE STRING "Compile with systemd notification on ready") + IF(NOT ${WITH_SYSTEMD} MATCHES "[Nn][Oo]") SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} systemd-daemon) CHECK_C_SOURCE_COMPILES( " @@ -177,12 +177,14 @@ IF(UNIX) CHECK_FUNCTION_EXISTS (sd_listen_fds HAVE_SYSTEMD_SD_LISTEN_FDS) CHECK_FUNCTION_EXISTS (sd_notify HAVE_SYSTEMD_SD_NOTIFY) CHECK_FUNCTION_EXISTS (sd_notifyf HAVE_SYSTEMD_SD_NOTIFYF) - IF(HAVE_SYSTEMD) + IF(HAVE_SYSTEMD AND HAVE_SYSTEMD_SD_DAEMON_H AND HAVE_SYSTEMD_SD_LISTEN_FDS + AND HAVE_SYSTEMD_SD_NOTIFY AND HAVE_SYSTEMD_SD_NOTIFYF) SET(LIBSYSTEMD "systemd-daemon") MESSAGE(STATUS "Systemd features enabled") ELSE() - IF(WITH_SYSTEMD STREQUAL "YES") - MESSAGE(STATUS "Requested WITH_SYSTEMD=YES however no dependencies installed/found") + MESSAGE(STATUS "Systemd features not enabled") + IF(${WITH_SYSTEMD} MATCHES "[Yy][Ee][Ss]") + MESSAGE(FATAL_ERROR "Requested WITH_SYSTEMD=YES however no dependencies installed/found") ENDIF() ENDIF() ENDIF() From 9ab56fafce7a0d8bfbaa3ec8ec802608860c4b56 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sat, 20 Jun 2015 16:30:27 +1000 Subject: [PATCH 18/32] systemd-daemon linking in sql/CMakeLists.txt not required --- sql/CMakeLists.txt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 9c74e4619f3d7..b2ea8c4f64136 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -201,13 +201,6 @@ IF(INTERFACE_LIBS) "${INTERFACE_LIBS}") ENDIF() -IF(WITH_SYSTEMD) -# Used for notify systemd's feature -IF(HAVE_SYSTEMD_SD_DAEMON_H) - TARGET_LINK_LIBRARIES(mysqld systemd-daemon) -ENDIF() -ENDIF() - # On Solaris, some extra effort is required in order to get dtrace probes # from static libraries DTRACE_INSTRUMENT_STATIC_LIBS(mysqld From 91b0bc8dc8ad90db446b71d4b322a36f300dbcd1 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sat, 20 Jun 2015 17:08:59 +1000 Subject: [PATCH 19/32] add #define for sd_listen_fds. Support use of extra_port with socket activation --- extra/comp_err.c | 2 +- sql/mysqld.cc | 34 +++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/extra/comp_err.c b/extra/comp_err.c index 3fc4b05fa61f0..450b619f1d0b9 100644 --- a/extra/comp_err.c +++ b/extra/comp_err.c @@ -553,7 +553,7 @@ static int parse_input_file(const char *file_name, struct errors **top_error, tail_error= ¤t_error->next_error; continue; } - if (*str == '#' || *str == '\n') + if (*str == '#' || *str == '\n' || *str == '\r') continue; /* skip comment or empty lines */ fprintf(stderr, "Wrong input file format. Stop!\nLine: %s\n", str); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index b2f17eab8e067..7c430c4c03821 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -121,6 +121,7 @@ union sockaddr_union { static int systemd_listen_cnt=0; #else /* HAVE_SYSTEMD */ #define MAX_LISTEN_SOCKETS 3 +#define sd_listen_fds(X) 0 #endif #define mysqld_charset &my_charset_latin1 @@ -2544,10 +2545,8 @@ static void network_init(void) int systemd_n = 0; DBUG_ENTER("network_init"); -#ifdef HAVE_SYSTEMD systemd_n = sd_listen_fds(0); DBUG_PRINT("general",("Systemd listen_fds is %d",systemd_n)); -#endif if (MYSQL_CALLBACK_ELSE(thread_scheduler, init, (), 0)) unireg_abort(1); /* purecov: inspected */ @@ -6211,10 +6210,16 @@ void handle_connections_sockets() if (socketpeer.ss.ss_family == AF_INET || socketpeer.ss.ss_family == AF_INET6) { + int port= ntohs(socketpeer.ss.ss_family == AF_INET ? + socketpeer.in.sin_port : socketpeer.in6.sin6_port); + if (port != 0 && port == mysqld_extra_port) + { + /* extra_port was same as systemd socket so use it as such */ + extra_ip_sock= mysql_socket_fd(all_systemd_key[systemd_listen_cnt], systemd_fd); + mysqld_extra_port= 0; + } sql_print_information("Listening on systemd family %s port %d.", - socketpeer.ss.ss_family == AF_INET ? "IPv4" : "IPv6", - ntohs(socketpeer.ss.ss_family == AF_INET ? - socketpeer.in.sin_port : socketpeer.in6.sin6_port)); + socketpeer.ss.ss_family == AF_INET ? "IPv4" : "IPv6", port); family= socketpeer.ss.ss_family == AF_INET ? "systemd_IPv4" : "systemd_IPv6"; } @@ -6290,19 +6295,26 @@ void handle_connections_sockets() setup_fds(base_ip_sock, AF_INET); ip_flags = fcntl(mysql_socket_getfd(base_ip_sock), F_GETFL, 0); } - if (mysql_socket_getfd(extra_ip_sock) != INVALID_SOCKET) - { - setup_fds(extra_ip_sock, AF_INET); - extra_ip_flags = fcntl(mysql_socket_getfd(extra_ip_sock), F_GETFL, 0); - } #ifdef HAVE_SYS_UN_H setup_fds(unix_sock, AF_UNIX); socket_flags=fcntl(mysql_socket_getfd(unix_sock), F_GETFL, 0); #endif + } -#ifdef HAVE_SYSTEMD + /* here we active a extra port, even if socket activation was is used because the + extra port wasn't activated using socket activation */ + if (!opt_disable_networking && !opt_bootstrap && mysqld_extra_port!=0 && + mysql_socket_getfd(extra_ip_sock) != INVALID_SOCKET) + { + extra_ip_sock= activate_tcp_port(mysqld_extra_port); + } + if (mysql_socket_getfd(extra_ip_sock) != INVALID_SOCKET) + { + setup_fds(extra_ip_sock, AF_INET); + extra_ip_flags = fcntl(mysql_socket_getfd(extra_ip_sock), F_GETFL, 0); } +#ifdef HAVE_SYSTEMD #ifdef HAVE_POLL if (systemd_listen_cnt == 0 && systemd_n>0) { From 85b9e87c58e0461e0af95013679abbeb4ada4214 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sat, 20 Jun 2015 17:34:18 +1000 Subject: [PATCH 20/32] reduce #if{n,}def on HAVE_SYSTEMD --- sql/mysqld.cc | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 7c430c4c03821..bc9e46e424f8f 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -122,6 +122,8 @@ static int systemd_listen_cnt=0; #else /* HAVE_SYSTEMD */ #define MAX_LISTEN_SOCKETS 3 #define sd_listen_fds(X) 0 +#define sd_notify(X, Y, Z) +static int sd_notifyf(int unset_environment, const char *format, ...) {} #endif #define mysqld_charset &my_charset_latin1 @@ -1860,9 +1862,7 @@ static void __cdecl kill_server(int sig_ptr) else sql_print_error(ER_DEFAULT(ER_GOT_SIGNAL),my_progname,sig); /* purecov: inspected */ -#ifdef HAVE_SYSTEMD sd_notify(0, "STOPPING=1"); -#endif #ifdef HAVE_SMEM /* Send event to smem_event_connect_request for aborting @@ -6125,17 +6125,12 @@ void handle_connections_sockets() int flags=0,retval; st_vio *vio_tmp; bool is_unix_sock; + int systemd_n=0, systemd_fd; #ifdef HAVE_SYSTEMD - int systemd_n, systemd_fd; union sockaddr_union socketpeer; +#endif socklen_t socketpeer_len; char const *family; -#ifndef HAVE_POLL - int pfs_flags[MAX_LISTEN_SOCKETS]; - // systemd wants these too - MYSQL_SOCKET pfs_fds[MAX_LISTEN_SOCKETS]; // used for non-polling interfaces -#endif -#endif // HAVE_SYSTEMD int socket_count= 0; short fd_type[MAX_LISTEN_SOCKETS]; #ifdef HAVE_POLL @@ -6149,16 +6144,12 @@ void handle_connections_sockets() fd_type[socket_count]= T; \ socket_count++ #else -#ifdef HAVE_SYSTEMD + int pfs_flags[MAX_LISTEN_SOCKETS]; + MYSQL_SOCKET pfs_fds[MAX_LISTEN_SOCKETS]; // used for non-polling interfaces #define setup_fds(X,T) FD_SET(mysql_socket_getfd(X),&clientFDs); \ pfs_fds[socket_count]= (X); \ fd_type[socket_count]= T; \ socket_count++ -#else -#define setup_fds(X,T) FD_SET(mysql_socket_getfd(X),&clientFDs); \ - fd_type[socket_count]= T; \ - socket_count++ -#endif // HAVE_SYSTEMD fd_set readFDs,clientFDs; FD_ZERO(&clientFDs); #endif @@ -6210,7 +6201,7 @@ void handle_connections_sockets() if (socketpeer.ss.ss_family == AF_INET || socketpeer.ss.ss_family == AF_INET6) { - int port= ntohs(socketpeer.ss.ss_family == AF_INET ? + unsigned port= ntohs(socketpeer.ss.ss_family == AF_INET ? socketpeer.in.sin_port : socketpeer.in6.sin6_port); if (port != 0 && port == mysqld_extra_port) { @@ -6314,7 +6305,6 @@ void handle_connections_sockets() extra_ip_flags = fcntl(mysql_socket_getfd(extra_ip_sock), F_GETFL, 0); } -#ifdef HAVE_SYSTEMD #ifdef HAVE_POLL if (systemd_listen_cnt == 0 && systemd_n>0) { @@ -6329,7 +6319,6 @@ void handle_connections_sockets() #ifdef HAVE_POLL } #endif /* HAVE_POLL */ -#endif /* HAVE_SYSTEMD */ DBUG_PRINT("general",("Waiting for connections.")); MAYBE_BROKEN_SYSCALL; @@ -6562,9 +6551,7 @@ void handle_connections_sockets() create_new_thread(thd); set_current_thd(0); } -#ifdef HAVE_SYSTEMD sd_notify(0, "STOPPING=1"); -#endif DBUG_VOID_RETURN; } From 246362e53faaee2ca30e80c73e31ca0de174302d Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 21 Jun 2015 08:47:05 +1000 Subject: [PATCH 21/32] add abstraction for sd_notify{f,}. Remove info/warn innodb messages from systemd notify --- include/my_sdnotify.h | 15 +++++++++++++++ sql/mysqld.cc | 6 ++---- storage/innobase/handler/ha_innodb.cc | 14 +------------- storage/xtradb/handler/ha_innodb.cc | 14 +------------- 4 files changed, 19 insertions(+), 30 deletions(-) create mode 100644 include/my_sdnotify.h diff --git a/include/my_sdnotify.h b/include/my_sdnotify.h new file mode 100644 index 0000000000000..adb9aab0c77a2 --- /dev/null +++ b/include/my_sdnotify.h @@ -0,0 +1,15 @@ + +#ifndef _my_sdnotify_h +#define _my_sdnotify_h + +#ifdef HAVE_SYSTEMD +#include + +#else + +#define sd_notify(X, Y, Z) +static int sd_notifyf(int unset_environment, const char *format, ...) {} + +#endif + +#endif /* _my_sdnotify_h */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index bc9e46e424f8f..580f8e91843cb 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -105,8 +105,9 @@ #include #endif +#include + #ifdef HAVE_SYSTEMD -#include #include union sockaddr_union { struct sockaddr sa; @@ -121,9 +122,6 @@ union sockaddr_union { static int systemd_listen_cnt=0; #else /* HAVE_SYSTEMD */ #define MAX_LISTEN_SOCKETS 3 -#define sd_listen_fds(X) 0 -#define sd_notify(X, Y, Z) -static int sd_notifyf(int unset_environment, const char *format, ...) {} #endif #define mysqld_charset &my_charset_latin1 diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index fbe0a6c1f84d5..942ac56dce79e 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -48,9 +48,7 @@ this program; if not, write to the Free Software Foundation, Inc., #include #endif -#ifdef HAVE_SYSTEMD -#include -#endif +#include /** @file ha_innodb.cc */ @@ -17552,27 +17550,17 @@ ib_logf( switch(level) { case IB_LOG_LEVEL_INFO: sql_print_information("InnoDB: %s", str); -#ifdef HAVE_SYSTEMD - sd_notifyf(0, "STATUS=InnoDB: Info: %s", str); -#endif break; case IB_LOG_LEVEL_WARN: sql_print_warning("InnoDB: %s", str); -#ifdef HAVE_SYSTEMD - sd_notifyf(0, "STATUS=InnoDB: Warning: %s", str); -#endif break; case IB_LOG_LEVEL_ERROR: sql_print_error("InnoDB: %s", str); -#ifdef HAVE_SYSTEMD sd_notifyf(0, "STATUS=InnoDB: Error: %s", str); -#endif break; case IB_LOG_LEVEL_FATAL: sql_print_error("InnoDB: %s", str); -#ifdef HAVE_SYSTEMD sd_notifyf(0, "STATUS=InnoDB: Fatal: %s", str); -#endif break; } diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index e725c44b55a45..ee1e559aab411 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -50,9 +50,7 @@ this program; if not, write to the Free Software Foundation, Inc., #include #endif -#ifdef HAVE_SYSTEMD -#include -#endif +#include /** @file ha_innodb.cc */ @@ -18816,27 +18814,17 @@ ib_logf( switch(level) { case IB_LOG_LEVEL_INFO: sql_print_information("InnoDB: %s", str); -#ifdef HAVE_SYSTEMD - sd_notifyf(0, "STATUS=InnoDB: Info: %s", str); -#endif break; case IB_LOG_LEVEL_WARN: sql_print_warning("InnoDB: %s", str); -#ifdef HAVE_SYSTEMD - sd_notifyf(0, "STATUS=InnoDB: Warning: %s", str); -#endif break; case IB_LOG_LEVEL_ERROR: sql_print_error("InnoDB: %s", str); -#ifdef HAVE_SYSTEMD sd_notifyf(0, "STATUS=InnoDB: Error: %s", str); -#endif break; case IB_LOG_LEVEL_FATAL: sql_print_error("InnoDB: %s", str); -#ifdef HAVE_SYSTEMD sd_notifyf(0, "STATUS=InnoDB: Fatal: %s", str); -#endif break; } From 615c8049ece09e236a3b0790a918ebf700dce924 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 21 Jun 2015 08:51:14 +1000 Subject: [PATCH 22/32] simplification in mariadb-socket-convert --- support-files/mariadb-socket-convert | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/support-files/mariadb-socket-convert b/support-files/mariadb-socket-convert index 9c15db4890bbc..8c4fb4db76f25 100755 --- a/support-files/mariadb-socket-convert +++ b/support-files/mariadb-socket-convert @@ -40,10 +40,7 @@ while read var; do --port) port=$val ;; - --extra-port) - extraport=$val - ;; - --extra_port) + --extra[-_]port) extraport=$val ;; --backlog) From b499e198d569fa1f4cae348d33e463a23f5da2fc Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 21 Jun 2015 09:48:08 +1000 Subject: [PATCH 23/32] more md_sdnotify consistenty --- include/my_sdnotify.h | 2 ++ storage/innobase/log/log0recv.cc | 12 +----------- storage/xtradb/log/log0recv.cc | 12 +----------- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/include/my_sdnotify.h b/include/my_sdnotify.h index adb9aab0c77a2..3092b9d939fb3 100644 --- a/include/my_sdnotify.h +++ b/include/my_sdnotify.h @@ -7,6 +7,8 @@ #else +#define sd_listen_fds(X) 0 + #define sd_notify(X, Y, Z) static int sd_notifyf(int unset_environment, const char *format, ...) {} diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index 613425de8cc1c..2e9b36f8f4000 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -29,9 +29,7 @@ Created 9/20/1997 Heikki Tuuri #include // Solaris/x86 header file bug #include -#ifdef HAVE_SYSTEMD -#include -#endif +#include #include "log0recv.h" @@ -1929,10 +1927,8 @@ recv_apply_hashed_log_recs( / hash_get_n_cells(recv_sys->addr_hash)) { fprintf(stderr, "%lu ", progress); -#ifdef HAVE_SYSTEMD sd_notifyf(0, "STATUS=Applying batch of log records for Innodb: " "Progress %lu", progress); -#endif } } @@ -1995,9 +1991,7 @@ recv_apply_hashed_log_recs( if (has_printed) { fprintf(stderr, "InnoDB: Apply batch completed\n"); -#ifdef HAVE_SYSTEMD sd_notify(0, "STATUS=InnoDB: Apply batch completed"); -#endif } mutex_exit(&(recv_sys->mutex)); @@ -2145,15 +2139,11 @@ recv_apply_log_recs_for_backup(void) fprintf(stderr, "%lu ", (ulong) ((100 * i) / n_hash_cells)); fflush(stderr); -#ifdef HAVE_SYSTEMD sd_notifyf(0, "STATUS=Applying batch of log records for backup Innodb: " "Progress %lu", (ulong) (100 * i) / n_hash_cells); -#endif } } -#ifdef HAVE_SYSTEMD sd_notify(0, "STATUS=InnoDB: Apply batch for backup completed"); -#endif recv_sys_empty_hash(); } diff --git a/storage/xtradb/log/log0recv.cc b/storage/xtradb/log/log0recv.cc index d4dbf9a047517..35624f94d5701 100644 --- a/storage/xtradb/log/log0recv.cc +++ b/storage/xtradb/log/log0recv.cc @@ -29,9 +29,7 @@ Created 9/20/1997 Heikki Tuuri #include // Solaris/x86 header file bug #include -#ifdef HAVE_SYSTEMD -#include -#endif +#include #include "log0recv.h" @@ -2000,10 +1998,8 @@ recv_apply_hashed_log_recs( / hash_get_n_cells(recv_sys->addr_hash)) { fprintf(stderr, "%lu ", progress); -#ifdef HAVE_SYSTEMD sd_notifyf(0, "STATUS=Applying batch of log records for Innodb: " "Progress %lu", progress); -#endif } } @@ -2066,9 +2062,7 @@ recv_apply_hashed_log_recs( if (has_printed) { fprintf(stderr, "InnoDB: Apply batch completed\n"); -#ifdef HAVE_SYSTEMD sd_notify(0, "STATUS=InnoDB: Apply batch completed"); -#endif } mutex_exit(&(recv_sys->mutex)); @@ -2216,15 +2210,11 @@ recv_apply_log_recs_for_backup(void) fprintf(stderr, "%lu ", (ulong) ((100 * i) / n_hash_cells)); fflush(stderr); -#ifdef HAVE_SYSTEMD sd_notifyf(0, "STATUS=Applying batch of log records for backup Innodb: " "Progress %lu", (ulong) (100 * i) / n_hash_cells); -#endif } } -#ifdef HAVE_SYSTEMD sd_notify(0, "STATUS=InnoDB: Apply batch for backup completed"); -#endif recv_sys_empty_hash(); } From 2bfe61160e00200283cca72b5d40092906938282 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 21 Jun 2015 10:59:51 +1000 Subject: [PATCH 24/32] mariadb-socket-convert - warnings for DNS based conversion and defaults --- support-files/mariadb-socket-convert | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/support-files/mariadb-socket-convert b/support-files/mariadb-socket-convert index 8c4fb4db76f25..359e7f680a78a 100755 --- a/support-files/mariadb-socket-convert +++ b/support-files/mariadb-socket-convert @@ -10,12 +10,12 @@ print_ports() { -if [ -n "${port}" ]; then - echo "ListenStream=${bind}${port}" -fi -if [ -n "${extraport}" ]; then - echo "ListenStream=${bind}${extraport}" -fi + if [ -n "${port}" ]; then + echo "ListenStream=${bind}${port}" + fi + if [ -n "${extraport}" ]; then + echo "ListenStream=${bind}${extraport}" + fi } bindaddress= @@ -95,9 +95,15 @@ if [ -n "${port}" -o \ echo # if port isn't set it really needs to be to # fill out the details - [ -z "${port}" ] && port=3306 + if [ -z "${port}" ]; then + port=3306 + echo "Warning: using default port ${port}" >&2 + fi # socket has a default value so ensure that is set - [ -z "${socket}" ] && socket=/var/lib/mysql/mysql.sock + if [ -z "${socket}" ]; then + socket=/var/lib/mysql/mysql.sock + echo "Warning: using default socket ${socket}" >&2 + fi else exit 0 fi @@ -130,10 +136,12 @@ if [ -n "${bindaddress}" ]; then while read var; do if [[ "${var}" = *IPv6\ address* ]]; then bind=[${var##* }]: + echo "Warning: using IP ${bind} for hostname ${bindaddress} specified in bindaddress" >&2 print_ports break else bind=${var##* }: + echo "Warning: using IP ${bind} for hostname ${bindaddress} specified in bindaddress" >&2 print_ports fi done < /dev/fd/${hosts[0]} From 4e351f11ec39eb9ebbe5669661c329b6f5740e34 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 21 Jun 2015 11:52:51 +1000 Subject: [PATCH 25/32] mariadb-socket-convert - grab default port/socket from mysqld --verbose --help --- support-files/mariadb-socket-convert | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/support-files/mariadb-socket-convert b/support-files/mariadb-socket-convert index 359e7f680a78a..4f517153890d7 100755 --- a/support-files/mariadb-socket-convert +++ b/support-files/mariadb-socket-convert @@ -25,6 +25,8 @@ backlog= maxconnections= skip_networking= socket= +default_port=3306 +default_socket=/var/lib/mysql/mysql.sock coproc mysqldefaults { /usr/bin/my_print_defaults --mysqld ; } while read var; do @@ -93,16 +95,33 @@ if [ -n "${port}" -o \ echo "# reset the ListenStream list to empty" echo "ListenStream=" echo + coproc mysqld { /usr/sbin/mysqld --verbose --help; } + # skip preamble + preamble_finished=0 + while read var; do + if [[ $var =~ ^------- ]]; then + preamble_finished=1 + fi + [ $preamble_finished ] || continue + key=${var%% *} + val=${var##* } + case "${key}" in + socket) + default_socket=$val + ;; + port) + default_port=$val + ;; + esac + done < /dev/fd/${mysqld[0]} # if port isn't set it really needs to be to # fill out the details if [ -z "${port}" ]; then - port=3306 - echo "Warning: using default port ${port}" >&2 + port=${default_port} fi # socket has a default value so ensure that is set if [ -z "${socket}" ]; then - socket=/var/lib/mysql/mysql.sock - echo "Warning: using default socket ${socket}" >&2 + socket=${default_socket} fi else exit 0 From af012a50cbcd268e74805272457ca7b76a479cd3 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 21 Jun 2015 15:12:49 +1000 Subject: [PATCH 26/32] correct/document mariadb.service --- support-files/mariadb.service | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/support-files/mariadb.service b/support-files/mariadb.service index 09e321f6d7f03..34d13c753c5a0 100644 --- a/support-files/mariadb.service +++ b/support-files/mariadb.service @@ -38,7 +38,8 @@ PermissionsStartOnly=true ExecStartPre=/usr/bin/mariadb-systemd-start # Start main service -# skip-networking as its socket activation based +# OPTIONS here is for users to set in /etc/systemd/system/mariadb.service.d/MY_SPECIAL.conf +# Use the [service] section and Environment="OPTIONS=...". ExecStart=/usr/sbin/mysqld $OPTIONS KillMode=process @@ -46,31 +47,36 @@ KillSignal=SIGTERM # Don't want to see an automated SIGKILL ever SendSIGKILL=no +# Exit status 1 is a fatal config error. Restarting won't help. RestartPreventExitStatus=1 -Restart=on-fail +Restart=on-failure RestartSec=5s -PrivateTmp=true PrivateDevices=true UMask=077 WorkingDirectory=/ -# To avoid mysql reading /root/.my.cnf which according to debian init script is -# problematic -Environment="HOME=" ############################################################################## ## USERs can override ## ## -## by creating a file in /etc/systemd/system/mariadb.server.d/MY_SPECIAL.conf +## by creating a file in /etc/systemd/system/mariadb.service.d/MY_SPECIAL.conf +## and adding/setting the following will override this file's settings. # Useful options not previously available in [mysqld_safe] +# Kernels like killing mysqld when out of memory because its big. +# Lets temper that preference a little. OOMScoreAdjust=-600 +# Explicitly start with high IO priority BlockIOWeight=1000 +# If you don't use the /tmp directory for SELECT ... OUTFILE and +# LOAD DATA INFILE you can enable PrivateTmp=true for a little more security. +PrivateTmp=false + ## ## Options previously available to be set via [mysqld_safe] ## that now needs to be set by systemd config files as mysqld_safe From e65f3d692182ee5756074e8c9efd39ae14ef99b1 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 21 Jun 2015 15:29:47 +1000 Subject: [PATCH 27/32] created mariadb-service-convert for systemd migration. added --simulate option to scripts/mysqld_safe.sh --- .../dist/Debian/mariadb-server-10.0.files.in | 1 + .../dist/Debian/mariadb-server-10.0.postinst | 7 +++ debian/dist/Debian/rules | 1 - .../dist/Ubuntu/mariadb-server-10.0.files.in | 1 + .../dist/Ubuntu/mariadb-server-10.0.postinst | 6 ++ debian/dist/Ubuntu/rules | 1 - scripts/CMakeLists.txt | 2 + scripts/mariadb-service-convert | 63 +++++++++++++++++++ .../mariadb-socket-convert | 0 scripts/mysqld_safe.sh | 47 +++++++++----- 10 files changed, 113 insertions(+), 16 deletions(-) create mode 100755 scripts/mariadb-service-convert rename {support-files => scripts}/mariadb-socket-convert (100%) diff --git a/debian/dist/Debian/mariadb-server-10.0.files.in b/debian/dist/Debian/mariadb-server-10.0.files.in index 2201e120b8d02..9ba7c1fead2fb 100644 --- a/debian/dist/Debian/mariadb-server-10.0.files.in +++ b/debian/dist/Debian/mariadb-server-10.0.files.in @@ -44,6 +44,7 @@ usr/bin/replace usr/bin/resolve_stack_dump usr/bin/resolveip usr/bin/mariadb-socket-convert +usr/bin/mariadb-system-convert usr/bin/mariadb-systemd-start usr/share/doc/mariadb-server-10.0/mysqld.sym.gz usr/share/doc/mariadb-server-10.0/INFO_SRC diff --git a/debian/dist/Debian/mariadb-server-10.0.postinst b/debian/dist/Debian/mariadb-server-10.0.postinst index d392bec9971af..ff42c4059935a 100644 --- a/debian/dist/Debian/mariadb-server-10.0.postinst +++ b/debian/dist/Debian/mariadb-server-10.0.postinst @@ -266,6 +266,13 @@ if [ "$1" = "configure" ]; then mkdir -p /etc/systemd/system/mariadb.socket.d /usr/bin/mariadb-socket-convert > "${systemd_sockconf}" fi + # copy out any mysqld_safe settings + systemd_conf=/etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf + if [ -x /usr/bin/mariadb-service-convert -a ! -f "${systemd_conf}" ]; then + mkdir -p /etc/systemd/system/mariadb.service.d + /usr/bin/mariadb-service-convert > "${systemd_conf}" + fi + fi db_stop # in case invoke failes diff --git a/debian/dist/Debian/rules b/debian/dist/Debian/rules index 3edf15d21ccda..e0ff9c578416d 100755 --- a/debian/dist/Debian/rules +++ b/debian/dist/Debian/rules @@ -181,7 +181,6 @@ install: build install -m 0644 $(builddir)/Docs/INFO_BIN $(TMP)/usr/share/doc/mariadb-server-10.0/INFO_BIN # systemd helpers - install -m 0755 support-files/mariadb-socket-convert $(TMP)/usr/bin/ install -m 0755 support-files/mariadb-systemd-start $(TMP)/usr/bin/ # mariadb-test diff --git a/debian/dist/Ubuntu/mariadb-server-10.0.files.in b/debian/dist/Ubuntu/mariadb-server-10.0.files.in index 82d9414aaabb6..7d2d753b8327e 100644 --- a/debian/dist/Ubuntu/mariadb-server-10.0.files.in +++ b/debian/dist/Ubuntu/mariadb-server-10.0.files.in @@ -46,6 +46,7 @@ usr/bin/replace usr/bin/resolve_stack_dump usr/bin/resolveip usr/bin/mariadb-socket-convert +usr/bin/mariadb-system-convert usr/bin/mariadb-systemd-start usr/share/doc/mariadb-server-10.0/mysqld.sym.gz usr/share/doc/mariadb-server-10.0/INFO_SRC diff --git a/debian/dist/Ubuntu/mariadb-server-10.0.postinst b/debian/dist/Ubuntu/mariadb-server-10.0.postinst index e8e0470c3b2a1..a47be0e541401 100644 --- a/debian/dist/Ubuntu/mariadb-server-10.0.postinst +++ b/debian/dist/Ubuntu/mariadb-server-10.0.postinst @@ -282,6 +282,12 @@ if [ "$1" = "configure" ]; then mkdir -p /etc/systemd/system/mariadb.socket.d /usr/bin/mariadb-socket-convert > "${systemd_sockconf}" fi + # copy out any mysqld_safe settings + systemd_conf=/etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf + if [ -x /usr/bin/mariadb-service-convert -a ! -f "${systemd_conf}" ]; then + mkdir -p /etc/systemd/system/mariadb.service.d + /usr/bin/mariadb-service-convert > "${systemd_conf}" + fi fi db_stop # in case invoke failes diff --git a/debian/dist/Ubuntu/rules b/debian/dist/Ubuntu/rules index e2cdd3ae7cd67..831a32c090156 100755 --- a/debian/dist/Ubuntu/rules +++ b/debian/dist/Ubuntu/rules @@ -181,7 +181,6 @@ install: build install -m 0644 $(builddir)/Docs/INFO_BIN $(TMP)/usr/share/doc/mariadb-server-10.0/INFO_BIN # systemd helpers - install -m 0755 support-files/mariadb-socket-convert $(TMP)/usr/bin/ install -m 0755 support-files/mariadb-systemd-start $(TMP)/usr/bin/ # mariadb-test diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 79d87fcf6bec5..508bdd7b9eece 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -339,6 +339,8 @@ ELSE() mysqldumpslow mysqld_multi mysqld_safe + mariadb-service-convert + mariadb-socket-convert ) FOREACH(file ${BIN_SCRIPTS}) IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.sh) diff --git a/scripts/mariadb-service-convert b/scripts/mariadb-service-convert new file mode 100755 index 0000000000000..863bad5c2e815 --- /dev/null +++ b/scripts/mariadb-service-convert @@ -0,0 +1,63 @@ +#!/bin/bash +# +# Used to generate a mariadb.service file based on the curent mysql/maridb settings +# +# This is to assist distro maintainers in migrating to systemd service definations from +# a user mysqld_safe settings in the my.cnf files. +# +# Redirect output to user directory like /etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf + +tz_old=$TZ + +. /usr/bin/mysqld_safe --simulate + +echo "# converted using $0" +echo "#" +echo + +echo '[Service]' + +echo + + +if [[ ( "$user" != "root" && "$user" != "mysql" ) || "${SET_USER}" == 1 ]]; then + echo User=$user +fi + + +[ -n "${open_files}" ] && echo LimitNOFILE=$open_files +[ -n "${core_file_size}" ] && echo LimitCore=$core_file_size +[ "${niceness}" -gt 0 ] && echo Nice=$niceness +[ "${TZ}" != "${tz_old}" ] && echo Environment=\"TZ=${TZ}\" + +if [ -n "$mysqld_ld_preload" ]; then + new_text="$mysqld_ld_preload" + [ -n "$LD_PRELOAD" ] && new_text="$new_text $LD_PRELOAD" + echo Environment=\"LD_PRELOAD=`shell_quote_string "$new_text"`\" +fi + +if [ -n "$mysqld_ld_library_path" ]; then + new_text="$mysqld_ld_library_path" + [ -n "$LD_LIBRARY_PATH" ] && new_text="$new_text:$LD_LIBRARY_PATH" + echo Environment=\"LD_LIBRARY_PATH=`shell_quote_string "$new_text"`\" +fi + +if [ $want_syslog -eq 1 ]; then + echo StandardError=syslog + echo SyslogFacility=daemon + echo SyslogLevel=error + echo SyslogLevelPrefix=${syslog_tag_mysqld} +fi + +if [ "${flush_caches}" -gt 0 ]; then + echo ExecStartPre=sync + echo ExecStartPre=sysctl -q -w vm.drop_caches=3 +fi + +if [ "${numa_interleave}" -gt 0 ]; then + echo + echo ExecStart=numactl --interleave=all ${cmd} '${OPTIONS}' + echo +fi + +[ -n "${CRASH_SCRIPT}" ] && echo FailureAction=${CRASH_SCRIPT} diff --git a/support-files/mariadb-socket-convert b/scripts/mariadb-socket-convert similarity index 100% rename from support-files/mariadb-socket-convert rename to scripts/mariadb-socket-convert diff --git a/scripts/mysqld_safe.sh b/scripts/mysqld_safe.sh index fdb4464a98f3f..0c7839b2f2606 100644 --- a/scripts/mysqld_safe.sh +++ b/scripts/mysqld_safe.sh @@ -20,9 +20,11 @@ mysqld_ld_preload= mysqld_ld_library_path= flush_caches=0 numa_interleave=0 +simulate=0 # Initial logging status: error log is not open, and not using syslog logging=init +mysqld_safe_logging=init want_syslog=0 syslog_tag= user='@MYSQLD_USER@' @@ -79,6 +81,7 @@ Usage: $0 [OPTIONS] --malloc-lib=LIB Preload shared library LIB if available --mysqld=FILE Use the specified file as mysqld --mysqld-version=VERSION Use "mysqld-VERSION" as mysqld + --simulate Simulate the start to detect errors but don't start --nice=NICE Set the scheduling priority of mysqld --no-auto-restart Exit after starting mysqld --nowatch Exit after starting mysqld @@ -134,7 +137,7 @@ log_generic () { msg="`date +'%y%m%d %H:%M:%S'` mysqld_safe $*" echo "$msg" - case $logging in + case $mysqld_safe_logging in init) ;; # Just echo the message, don't save it anywhere file) echo "$msg" >> "$err_log" ;; syslog) logger -t "$syslog_tag_mysqld_safe" -p "$priority" "$*" ;; @@ -226,6 +229,7 @@ parse_arguments() { MYSQLD="mysqld" fi ;; + --simulate) simulate=1 ;; --nice=*) niceness="$val" ;; --nowatch|--no[-_]watch|--no[-_]auto[-_]restart) nowatch=1 ;; --open[-_]files[-_]limit=*) open_files="$val" ;; @@ -593,7 +597,11 @@ then fi # Log to err_log file - log_notice "Logging to '$err_log'." + if [ $simulate -eq 0 ] + then + log_notice "Logging to '$err_log'." + mysqld_safe_logging=file + fi logging=file if [ ! -f "$err_log" ]; then # if error log already exists, @@ -609,7 +617,11 @@ else syslog_tag_mysqld_safe="${syslog_tag_mysqld_safe}-$syslog_tag" syslog_tag_mysqld="${syslog_tag_mysqld}-$syslog_tag" fi - log_notice "Logging to syslog." + if [ $simulate -eq 0 ] + then + log_notice "Logging to syslog." + mysqld_safe_logging=syslog + fi logging=syslog fi @@ -621,7 +633,7 @@ then USER_OPTION="--user=$user" fi # Change the err log to the right user, if it is in use - if [ $want_syslog -eq 0 ]; then + if [ $simulate -eq 0 -a $want_syslog -eq 0 ]; then touch "$err_log" chown $user "$err_log" fi @@ -639,7 +651,7 @@ fi safe_mysql_unix_port=${mysql_unix_port:-${MYSQL_UNIX_PORT:-@MYSQL_UNIX_ADDR@}} # Make sure that directory for $safe_mysql_unix_port exists mysql_unix_port_dir=`dirname $safe_mysql_unix_port` -if [ ! -d $mysql_unix_port_dir ] +if [ $simulate -eq 0 -a ! -d $mysql_unix_port_dir ] then if ! `mkdir -p $mysql_unix_port_dir` then @@ -663,7 +675,7 @@ does not exist or is not executable. Please cd to the mysql installation directory and restart this script from there as follows: ./bin/mysqld_safe& See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information" - exit 1 + [ $simulate -eq 0 ] && exit 1 fi if test -z "$pid_file" @@ -748,7 +760,7 @@ fi # # If there exists an old pid file, check if the daemon is already running # Note: The switches to 'ps' may depend on your operating system -if test -f "$pid_file" +if test -f "$pid_file" && [ $simulate -eq 0 ] then PID=`cat "$pid_file"` if @CHECK_PID@ @@ -794,7 +806,7 @@ then log_error "sysctl command not found, required for --flush-caches" exit 1 # Purge page cache, dentries and inodes. - elif ! sysctl -q -w vm.drop_caches=3 + elif [ $simulate -eq 0 ] && ! sysctl -q -w vm.drop_caches=3 then log_error "sysctl failed, check the error message for details" exit 1 @@ -823,7 +835,12 @@ fi # ulimit -n 256 > /dev/null 2>&1 # Fix for BSD and FreeBSD systems #fi -cmd="`mysqld_ld_preload_text`$NOHUP_NICENESS" +if [ $simulate -eq 0 ] +then + cmd="`mysqld_ld_preload_text`$NOHUP_NICENESS" +else + cmd='' +fi # # Set mysqld's memory interleave policy. @@ -843,7 +860,7 @@ then fi # Launch mysqld with numactl. - cmd="$cmd numactl --interleave=all" + [ $simulate -eq 0 ] && cmd="$cmd numactl --interleave=all" elif test $numa_interleave -eq 1 then log_error "--numa-interleave is not supported on this platform" @@ -857,9 +874,9 @@ do done cmd="$cmd $args" # Avoid 'nohup: ignoring input' warning -test -n "$NOHUP_NICENESS" && cmd="$cmd < /dev/null" +[ -n "$NOHUP_NICENESS" -a $simulate -eq 0 ] && cmd="$cmd < /dev/null" -log_notice "Starting $MYSQLD daemon with databases from $DATADIR" +[ $simulate -eq 0 ] && log_notice "Starting $MYSQLD daemon with databases from $DATADIR" # variable to track the current number of "fast" (a.k.a. subsecond) restarts fast_restart=0 @@ -870,13 +887,15 @@ have_sleep=1 while true do + [ $simulate ] && break; + rm -f "$pid_file" # Some extra safety start_time=`date +%M%S` eval_log_error "$cmd" - if [ $want_syslog -eq 0 -a ! -f "$err_log" ]; then + if [ $simulate -eq 0 -a $want_syslog -eq 0 -a ! -f "$err_log" ]; then touch "$err_log" # hypothetical: log was renamed but not chown $user "$err_log" # flushed yet. we'd recreate it with chmod "$fmode" "$err_log" # wrong owner next time we log, so set @@ -952,5 +971,5 @@ do fi done -log_notice "mysqld from pid file $pid_file ended" +[ $simulate -eq 0 ] && log_notice "mysqld from pid file $pid_file ended" From 2a2c21b3718ce0943b3d5bf27da8d8ca5eea04bd Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 21 Jun 2015 15:33:05 +1000 Subject: [PATCH 28/32] remove accidely commited extra/comp_err.c CR/LF hack --- extra/comp_err.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/comp_err.c b/extra/comp_err.c index 450b619f1d0b9..3fc4b05fa61f0 100644 --- a/extra/comp_err.c +++ b/extra/comp_err.c @@ -553,7 +553,7 @@ static int parse_input_file(const char *file_name, struct errors **top_error, tail_error= ¤t_error->next_error; continue; } - if (*str == '#' || *str == '\n' || *str == '\r') + if (*str == '#' || *str == '\n') continue; /* skip comment or empty lines */ fprintf(stderr, "Wrong input file format. Stop!\nLine: %s\n", str); From 9b2a1a1f61d776f614458c44452197ee5793a157 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 21 Jun 2015 15:43:30 +1000 Subject: [PATCH 29/32] dont automaticly ExecStartPre=/usr/bin/mariadb-systemd-start (db install) - leave this to distro maintainers --- support-files/mariadb.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support-files/mariadb.service b/support-files/mariadb.service index 34d13c753c5a0..3a81cb3565241 100644 --- a/support-files/mariadb.service +++ b/support-files/mariadb.service @@ -35,7 +35,7 @@ User=mysql PermissionsStartOnly=true # Needed to create system tables etc. -ExecStartPre=/usr/bin/mariadb-systemd-start +# ExecStartPre=/usr/bin/mariadb-systemd-start # Start main service # OPTIONS here is for users to set in /etc/systemd/system/mariadb.service.d/MY_SPECIAL.conf From b7c1c8b56173733181b5b349574d9da94be7c9e8 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 21 Jun 2015 18:28:02 +1000 Subject: [PATCH 30/32] just use /usr/bin/mysql_install_db to create database. --- support-files/mariadb-systemd-start | 44 ----------------------------- support-files/mariadb.service | 2 +- 2 files changed, 1 insertion(+), 45 deletions(-) delete mode 100644 support-files/mariadb-systemd-start diff --git a/support-files/mariadb-systemd-start b/support-files/mariadb-systemd-start deleted file mode 100644 index ce4d9ce91b2dc..0000000000000 --- a/support-files/mariadb-systemd-start +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash -# -# Scripts to run by MySQL systemd service -# -# -# try to run mysql_install_db and fix perms and SELinux contexts - -install_db () { - # Note: something different than datadir=/var/lib/mysql requires SELinux policy changes (in enforcing mode) - datadir=/var/lib/mysql - log=/var/log/mysqld.log - coproc mysqldefaults { /usr/bin/my_print_defaults --mysqld ; } - while read var; do - key=${var%%=*} - if [ "${key}" = '--datadir' ]; then - datadir=${var#*=} - fi - if [ "${key}" = '--log-error' ] || [ "${key}" = '--log_error' ]; then - log=${var#*=} - fi - done < /dev/fd/${mysqldefaults[0]} - - # Restore log, dir, perms and SELinux contexts - [ -d "$datadir" ] || install -d -m 0755 -omysql -gmysql "$datadir" || exit 1 - [ -e $log ] || touch $log - chmod 0640 $log - chown mysql:mysql $log || exit 1 - if [ -x /usr/sbin/restorecon ]; then - /usr/sbin/restorecon "$datadir" - /usr/sbin/restorecon $log - fi - - # If special mysql dir is in place, skip db install - [ -d "$datadir/mysql" ] && exit 0 - - # Create initial db - /usr/bin/mysql_install_db --rpm --datadir="$datadir" --user=mysql - exit 0 -} - -install_db - -exit 0 - diff --git a/support-files/mariadb.service b/support-files/mariadb.service index 3a81cb3565241..390f821b7e8bb 100644 --- a/support-files/mariadb.service +++ b/support-files/mariadb.service @@ -35,7 +35,7 @@ User=mysql PermissionsStartOnly=true # Needed to create system tables etc. -# ExecStartPre=/usr/bin/mariadb-systemd-start +# ExecStartPre=/usr/bin/mysql_install_db # Start main service # OPTIONS here is for users to set in /etc/systemd/system/mariadb.service.d/MY_SPECIAL.conf From 1466c200c1bfb20a35c30a6ec2a373608cddfd28 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 21 Jun 2015 21:28:11 +1000 Subject: [PATCH 31/32] remove WorkingDir from mariadb.service --- support-files/mariadb.service | 1 - 1 file changed, 1 deletion(-) diff --git a/support-files/mariadb.service b/support-files/mariadb.service index 390f821b7e8bb..f85b4709f59fd 100644 --- a/support-files/mariadb.service +++ b/support-files/mariadb.service @@ -55,7 +55,6 @@ RestartSec=5s PrivateDevices=true UMask=077 -WorkingDirectory=/ ############################################################################## ## USERs can override From 9fb0b9125965e48333d9a6f87c6bde4f1ece219e Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 21 Jun 2015 21:37:40 +1000 Subject: [PATCH 32/32] doc mariadb@.service before i forget --- support-files/mariadb.service | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/support-files/mariadb.service b/support-files/mariadb.service index f85b4709f59fd..7cf5efca8bc13 100644 --- a/support-files/mariadb.service +++ b/support-files/mariadb.service @@ -7,6 +7,9 @@ Description=MariaDB database server After=network.target After=syslog.target Requires=%p.socket +# OPTINSTANCE ConditionPathExists=/etc/mysql/my%I.cnf +# OPTINSTANCE - install as mariadb@.service and install as mariadb@xxx.service where %I becomes xxx +# from https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/dev-db/mysql-init-scripts/files/mysqld_at.service?view=markup [Install] WantedBy=multi-user.target @@ -41,6 +44,7 @@ PermissionsStartOnly=true # OPTIONS here is for users to set in /etc/systemd/system/mariadb.service.d/MY_SPECIAL.conf # Use the [service] section and Environment="OPTIONS=...". ExecStart=/usr/sbin/mysqld $OPTIONS +# OPTINSTANCE --defaults-file=/etc/mysql/my%I.cnf KillMode=process KillSignal=SIGTERM