-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Mdev 5536 Add systemd notify and socket activation capabilities to 10.1 branch #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f95754b
e6e7542
f2b9a82
9b249bf
f7abb1d
c3c7772
b463902
8460f60
f49e0e9
d841842
2fd9694
17e3cd9
c93a5c4
f8614d5
348ba1a
76a797c
c865ba4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| INCLUDE(FindPkgConfig) | ||
| # http://www.cmake.org/cmake/help/v3.0/module/FindPkgConfig.html | ||
|
|
||
| MACRO(CHECK_SYSTEMD) | ||
| IF(UNIX) | ||
| SET(WITH_SYSTEMD "auto" CACHE STRING "Compile with systemd socket activation and notification") | ||
| IF(WITH_SYSTEMD STREQUAL "yes" OR WITH_SYSTEMD STREQUAL "auto") | ||
| IF(PKG_CONFIG_FOUND) | ||
| IF(WITH_SYSTEMD STREQUAL "yes") | ||
| pkg_check_modules(LIBSYSTEMD REQUIRED libsystemd) | ||
| ELSE() | ||
| pkg_check_modules(LIBSYSTEMD libsystemd) | ||
| ENDIF() | ||
| IF(HAVE_DLOPEN) | ||
| SET(LIBSYSTEMD ${LIBSYSTEMD_LIBRARIES}) | ||
| #SET(CMAKE_REQUIRED_FLAGS ${LIBSYSTEMD_CFLAGS}) | ||
| SET(MYSQLD_LINK_FLAGS "${MYSQLD_LINK_FLAGS} ${LIBSYSTEMD_LDFLAGS}") | ||
| ELSE() | ||
| SET(LIBSYSTEMD ${LIBSYSTEMD_STATIC_LIBRARIES}) | ||
| #SET(CMAKE_REQUIRED_FLAGS ${LIBSYSTEMD_STATIC_CFLAGS}) | ||
| SET(MYSQLD_LINK_FLAGS "${MYSQLD_LINK_FLAGS} ${LIBSYSTEMD_STATIC_LDFLAGS}") | ||
| ENDIF() | ||
| ELSE() | ||
| SET(LIBSYSTEMD systemd) | ||
| ENDIF() | ||
| SET(CMAKE_REQUIRED_LIBRARIES ${LIBSYSTEMD}) | ||
| CHECK_C_SOURCE_COMPILES( | ||
| " | ||
| #include <systemd/sd-daemon.h> | ||
| int main() | ||
| { | ||
| 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 AND HAVE_SYSTEMD_SD_DAEMON_H AND HAVE_SYSTEMD_SD_LISTEN_FDS | ||
| AND HAVE_SYSTEMD_SD_NOTIFY AND HAVE_SYSTEMD_SD_NOTIFYF) | ||
| ADD_DEFINITIONS(-DHAVE_SYSTEMD) | ||
| MESSAGE(STATUS "Systemd features enabled") | ||
| ELSE() | ||
| UNSET(LIBSYSTEMD) | ||
| UNSET(HAVE_SYSTEMD_SD_DAEMON_H) | ||
| UNSET(HAVE_SYSTEMD_SD_LISTEN_FDS) | ||
| UNSET(HAVE_SYSTEMD_SD_NOTIFY) | ||
| UNSET(HAVE_SYSTEMD_SD_NOTIFYF) | ||
| MESSAGE(STATUS "Systemd features not enabled") | ||
| IF(WITH_SYSTEMD STREQUAL "yes") | ||
| MESSAGE(FATAL_ERROR "Requested WITH_SYSTEMD=YES however no dependencies installed/found") | ||
| ENDIF() | ||
| ENDIF() | ||
| ENDIF() | ||
| ENDIF() | ||
| ENDMACRO() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -260,6 +260,19 @@ 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 | ||
| # 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be only called in case of "configure"?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is. Scroll up to line 247.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I missed this somehow. :( |
||
|
|
||
| db_stop # in case invoke failes | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,6 +180,10 @@ install: build | |
| install -m 0644 $(builddir)/Docs/INFO_SRC $(TMP)/usr/share/doc/mariadb-server-10.1/INFO_SRC | ||
| install -m 0644 $(builddir)/Docs/INFO_BIN $(TMP)/usr/share/doc/mariadb-server-10.1/INFO_BIN | ||
|
|
||
| # systemd helpers | ||
| install -m 0755 scripts/mariadb-socket-convert $(TMP)/usr/bin/ | ||
| install -m 0755 scripts/mariadb-service-convert $(TMP)/usr/bin/ | ||
|
|
||
| # mariadb-test | ||
| mv $(TMP)/usr/mysql-test $(TMP)/usr/share/mysql | ||
|
|
||
|
|
@@ -216,7 +220,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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this change (and many other changes) will break packaging on older supported systems with no systemd. But I have no reasonable alternative on my mind, so probably let's do it now and fix later.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its the approach suggested by the debian packaging guide. I assume handling of non-systemd is wrapped under dh_systemd_start somehow. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
|
|
||
| #ifndef MY_SYSTEMD_INCLUDED | ||
| #define MY_SYSTEMD_INCLUDED | ||
|
|
||
| #ifdef HAVE_SYSTEMD | ||
| #include <systemd/sd-daemon.h> | ||
|
|
||
| #else | ||
|
|
||
| #define sd_listen_fds(X) (0) | ||
|
|
||
| #define sd_notify(X, Y) | ||
| #define sd_notifyf(E, F, ...) | ||
|
|
||
| #endif | ||
|
|
||
| #endif /* MY_SYSTEMD_INCLUDED */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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}' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You emit ExecStart only if numa-interleave is set. Does that mean "if numa-interleave is not set use default ExecStart specified by mariadb.service"?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||
| echo | ||
| fi | ||
|
|
||
| [ -n "${CRASH_SCRIPT}" ] && echo FailureAction=${CRASH_SCRIPT} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if you could add copyright header to this file. And also to my_systemd.h.