Skip to content

Commit 20c2ae3

Browse files
grooverdansvoj
authored andcommitted
MDEV-427/MDEV-5713 Add systemd script with notify functionality
1 parent 92271c7 commit 20c2ae3

23 files changed

+551
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ support-files/config.huge.ini
197197
support-files/config.medium.ini
198198
support-files/config.small.ini
199199
support-files/mariadb.pc
200+
support-files/mariadb@.service
200201
support-files/my-huge.cnf
201202
support-files/my-innodb-heavy-4G.cnf
202203
support-files/my-large.cnf

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ INCLUDE(pcre)
151151
INCLUDE(ctest)
152152
INCLUDE(plugin)
153153
INCLUDE(install_macros)
154+
INCLUDE(systemd)
154155
INCLUDE(mysql_add_executable)
155156

156157
# Handle options
@@ -328,6 +329,8 @@ CHECK_JEMALLOC()
328329

329330
CHECK_PCRE()
330331

332+
CHECK_SYSTEMD()
333+
331334
IF(CMAKE_CROSSCOMPILING)
332335
SET(IMPORT_EXECUTABLES "IMPORTFILE-NOTFOUND" CACHE FILEPATH "Path to import_executables.cmake from a native build")
333336
INCLUDE(${IMPORT_EXECUTABLES})

cmake/systemd.cmake

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright (c) 2015, Daniel Black. All rights reserved.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; version 2 of the License.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15+
16+
INCLUDE(FindPkgConfig)
17+
# http://www.cmake.org/cmake/help/v3.0/module/FindPkgConfig.html
18+
19+
MACRO(CHECK_SYSTEMD)
20+
IF(UNIX)
21+
SET(WITH_SYSTEMD "auto" CACHE STRING "Compile with systemd socket activation and notification")
22+
IF(WITH_SYSTEMD STREQUAL "yes" OR WITH_SYSTEMD STREQUAL "auto")
23+
IF(PKG_CONFIG_FOUND)
24+
IF(WITH_SYSTEMD STREQUAL "yes")
25+
pkg_check_modules(LIBSYSTEMD REQUIRED libsystemd)
26+
ELSE()
27+
pkg_check_modules(LIBSYSTEMD libsystemd)
28+
ENDIF()
29+
IF(HAVE_DLOPEN)
30+
SET(LIBSYSTEMD ${LIBSYSTEMD_LIBRARIES})
31+
#SET(CMAKE_REQUIRED_FLAGS ${LIBSYSTEMD_CFLAGS})
32+
SET(MYSQLD_LINK_FLAGS "${MYSQLD_LINK_FLAGS} ${LIBSYSTEMD_LDFLAGS}")
33+
ELSE()
34+
SET(LIBSYSTEMD ${LIBSYSTEMD_STATIC_LIBRARIES})
35+
#SET(CMAKE_REQUIRED_FLAGS ${LIBSYSTEMD_STATIC_CFLAGS})
36+
SET(MYSQLD_LINK_FLAGS "${MYSQLD_LINK_FLAGS} ${LIBSYSTEMD_STATIC_LDFLAGS}")
37+
ENDIF()
38+
ELSE()
39+
SET(LIBSYSTEMD systemd)
40+
ENDIF()
41+
SET(CMAKE_REQUIRED_LIBRARIES ${LIBSYSTEMD})
42+
CHECK_C_SOURCE_COMPILES(
43+
"
44+
#include <systemd/sd-daemon.h>
45+
int main()
46+
{
47+
sd_listen_fds(0);
48+
}"
49+
HAVE_SYSTEMD)
50+
CHECK_INCLUDE_FILES(systemd/sd-daemon.h HAVE_SYSTEMD_SD_DAEMON_H)
51+
CHECK_FUNCTION_EXISTS(sd_listen_fds HAVE_SYSTEMD_SD_LISTEN_FDS)
52+
CHECK_FUNCTION_EXISTS(sd_notify HAVE_SYSTEMD_SD_NOTIFY)
53+
CHECK_FUNCTION_EXISTS(sd_notifyf HAVE_SYSTEMD_SD_NOTIFYF)
54+
IF(HAVE_SYSTEMD AND HAVE_SYSTEMD_SD_DAEMON_H AND HAVE_SYSTEMD_SD_LISTEN_FDS
55+
AND HAVE_SYSTEMD_SD_NOTIFY AND HAVE_SYSTEMD_SD_NOTIFYF)
56+
ADD_DEFINITIONS(-DHAVE_SYSTEMD)
57+
# should be from pkg-config --variable=systemdsystemconfdir systemd
58+
# Missing CMake macro: http://public.kitware.com/Bug/view.php?id=15634
59+
SET(SYSTEMD_SYSTEM_CONFDIR /etc/systemd/system)
60+
# should be from pkg-config --variable=systemdsystemunitdir systemd
61+
SET(SYSTEMD_SYSTEM_UNITDIR /usr/lib/systemd/system/)
62+
MESSAGE(STATUS "Systemd features enabled")
63+
ELSE()
64+
UNSET(LIBSYSTEMD)
65+
UNSET(HAVE_SYSTEMD_SD_DAEMON_H)
66+
UNSET(HAVE_SYSTEMD_SD_LISTEN_FDS)
67+
UNSET(HAVE_SYSTEMD_SD_NOTIFY)
68+
UNSET(HAVE_SYSTEMD_SD_NOTIFYF)
69+
MESSAGE(STATUS "Systemd features not enabled")
70+
IF(WITH_SYSTEMD STREQUAL "yes")
71+
MESSAGE(FATAL_ERROR "Requested WITH_SYSTEMD=YES however no dependencies installed/found")
72+
ENDIF()
73+
ENDIF()
74+
ENDIF()
75+
ENDIF()
76+
ENDMACRO()

config.h.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
#cmakedefine HAVE_LIBCRYPT 1
121121
#cmakedefine HAVE_LIBMTMALLOC 1
122122
#cmakedefine HAVE_LIBWRAP 1
123+
#cmakedefine HAVE_SYSTEMD 1
123124
/* Does "struct timespec" have a "sec" and "nsec" field? */
124125
#cmakedefine HAVE_TIMESPEC_TS_SEC 1
125126

debian/control

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Build-Depends: bison,
2323
zlib1g-dev (>= 1:1.1.3-5~),
2424
${MAYBE_LIBCRACK}
2525
libjemalloc-dev (>= 3.0.0~) [linux-any]
26+
libsystemd-daemon-dev | libsystemd-dev, dh-systemd
2627
Standards-Version: 3.8.2
2728
Homepage: http://mariadb.org/
2829
Vcs-Git: https://github.com/MariaDB/server.git

debian/mariadb-server-10.1.files.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ usr/bin/wsrep_sst_mysqldump
5555
usr/bin/wsrep_sst_rsync
5656
usr/bin/wsrep_sst_xtrabackup
5757
usr/bin/wsrep_sst_xtrabackup-v2
58+
usr/bin/mariadb-system-convert
5859
usr/share/doc/mariadb-server-10.1/mysqld.sym.gz
5960
usr/share/doc/mariadb-server-10.1/INFO_SRC
6061
usr/share/doc/mariadb-server-10.1/INFO_BIN

debian/mariadb-server-10.1.postinst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@ if [ "$1" = "configure" ]; then
276276
db_go
277277
fi
278278

279+
# copy out any mysqld_safe settings
280+
systemd_conf=/etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf
281+
if [ -x /usr/bin/mariadb-service-convert -a ! -f "${systemd_conf}" ]; then
282+
mkdir -p /etc/systemd/system/mariadb.service.d
283+
/usr/bin/mariadb-service-convert > "${systemd_conf}"
284+
fi
279285
fi
280286

281287
db_stop # in case invoke failes

debian/rules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ install: build
180180
install -m 0644 $(builddir)/Docs/INFO_SRC $(TMP)/usr/share/doc/mariadb-server-10.1/INFO_SRC
181181
install -m 0644 $(builddir)/Docs/INFO_BIN $(TMP)/usr/share/doc/mariadb-server-10.1/INFO_BIN
182182

183+
# systemd helpers
184+
install -m 0755 scripts/mariadb-service-convert $(TMP)/usr/bin/
185+
install -d $(TMP)/etc/systemd/system/mariadb@bootstrap.service.d/
186+
install -m 0644 $(BUILDDIR)/support-files/mariadb-bootstrap.conf \
187+
$(TMP)/etc/systemd/system/mariadb@bootstrap.service.d/wsrep-new-cluster.conf
188+
183189
# mariadb-test
184190
mv $(TMP)/usr/mysql-test $(TMP)/usr/share/mysql
185191

@@ -215,7 +221,10 @@ binary-indep: build install
215221
dh_installexamples -i
216222
dh_installmenu -i
217223
dh_installlogrotate -i
224+
dh_systemd_enable -i support-files/mariadb.service
225+
dh_systemd_enable --no-enable support-files/mariadb@.service
218226
dh_installinit -i
227+
dh_systemd_start -i --restart-after-upgrade mariadb.service
219228
dh_installcron -i
220229
dh_installman -i
221230
dh_installinfo -i

include/my_systemd.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
#ifndef MY_SYSTEMD_INCLUDED
3+
#define MY_SYSTEMD_INCLUDED
4+
5+
#if defined(HAVE_SYSTEMD) && !defined(EMBEDDED_LIBRARY)
6+
#include <systemd/sd-daemon.h>
7+
8+
#else
9+
10+
11+
12+
#define sd_notify(X, Y)
13+
#define sd_notifyf(E, F, ...)
14+
15+
#endif
16+
17+
#endif /* MY_SYSTEMD_INCLUDED */

scripts/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ ELSE()
300300
mysqld_multi
301301
mysqld_safe
302302
${WSREP_BINARIES}
303+
mariadb-service-convert
303304
)
304305
FOREACH(file ${BIN_SCRIPTS})
305306
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.sh)

0 commit comments

Comments
 (0)