Skip to content

Commit 6346d1d

Browse files
committed
MDEV-427/MDEV-5713 Add systemd script with notify functionality
After review/QA fixes.
1 parent 20c2ae3 commit 6346d1d

19 files changed

+164
-113
lines changed

cmake/install_layout.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ SET(INSTALL_SUPPORTFILESDIR_RPM "share/mysql")
161161
SET(INSTALL_MYSQLDATADIR_RPM "/var/lib/mysql")
162162

163163
SET(INSTALL_UNIX_ADDRDIR_RPM "${INSTALL_MYSQLDATADIR_RPM}/mysql.sock")
164+
SET(INSTALL_SYSTEMD_UNITDIR_RPM "/usr/lib/systemd/system")
164165

165166
#
166167
# DEB layout
@@ -189,6 +190,8 @@ SET(INSTALL_SUPPORTFILESDIR_DEB "share/mysql")
189190
SET(INSTALL_MYSQLDATADIR_DEB "/var/lib/mysql")
190191

191192
SET(INSTALL_UNIX_ADDRDIR_DEB "/var/run/mysqld/mysqld.sock")
193+
SET(INSTALL_SYSTEMD_UNITDIR_DEB "/lib/systemd/system")
194+
192195
#
193196
# SVR4 layout
194197
#
@@ -228,7 +231,8 @@ SET(OLD_INSTALL_LAYOUT ${INSTALL_LAYOUT} CACHE INTERNAL "")
228231
# will be defined as ${INSTALL_BINDIR_STANDALONE} by default if STANDALONE
229232
# layout is chosen)
230233
FOREACH(var BIN SBIN LIB MYSQLSHARE SHARE PLUGIN INCLUDE SCRIPT DOC MAN SYSCONF SYSCONF2
231-
INFO MYSQLTEST SQLBENCH DOCREADME SUPPORTFILES MYSQLDATA UNIX_ADDR)
234+
INFO MYSQLTEST SQLBENCH DOCREADME SUPPORTFILES MYSQLDATA UNIX_ADDR
235+
SYSTEMD_UNIT)
232236
SET(INSTALL_${var}DIR ${INSTALL_${var}DIR_${INSTALL_LAYOUT}}
233237
CACHE STRING "${var} installation directory" ${FORCE})
234238
MARK_AS_ADVANCED(INSTALL_${var}DIR)

cmake/systemd.cmake

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ MACRO(CHECK_SYSTEMD)
2222
IF(WITH_SYSTEMD STREQUAL "yes" OR WITH_SYSTEMD STREQUAL "auto")
2323
IF(PKG_CONFIG_FOUND)
2424
IF(WITH_SYSTEMD STREQUAL "yes")
25-
pkg_check_modules(LIBSYSTEMD REQUIRED libsystemd)
25+
pkg_search_module(LIBSYSTEMD REQUIRED libsystemd libsystemd-daemon)
2626
ELSE()
27-
pkg_check_modules(LIBSYSTEMD libsystemd)
27+
pkg_search_module(LIBSYSTEMD libsystemd libsystemd-daemon)
2828
ENDIF()
2929
IF(HAVE_DLOPEN)
3030
SET(LIBSYSTEMD ${LIBSYSTEMD_LIBRARIES})
@@ -51,17 +51,23 @@ MACRO(CHECK_SYSTEMD)
5151
CHECK_FUNCTION_EXISTS(sd_listen_fds HAVE_SYSTEMD_SD_LISTEN_FDS)
5252
CHECK_FUNCTION_EXISTS(sd_notify HAVE_SYSTEMD_SD_NOTIFY)
5353
CHECK_FUNCTION_EXISTS(sd_notifyf HAVE_SYSTEMD_SD_NOTIFYF)
54+
SET(CMAKE_REQUIRED_LIBRARIES)
5455
IF(HAVE_SYSTEMD AND HAVE_SYSTEMD_SD_DAEMON_H AND HAVE_SYSTEMD_SD_LISTEN_FDS
5556
AND HAVE_SYSTEMD_SD_NOTIFY AND HAVE_SYSTEMD_SD_NOTIFYF)
5657
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/)
58+
SET(SYSTEMD_SCRIPTS mariadb-service-convert)
59+
SET(SYSTEMD_DEB_FILES "usr/bin/mariadb-service-convert
60+
${INSTALL_SYSTEMD_UNITDIR}/mariadb.service
61+
${INSTALL_SYSTEMD_UNITDIR}/mariadb@.service
62+
${INSTALL_SYSTEMD_UNITDIR}/mariadb@bootstrap.service.d/wsrep-new-cluster.conf")
63+
IF(DEB)
64+
SET(SYSTEMD_EXECSTARTPRE "PermissionsStartOnly=true\nExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld")
65+
SET(SYSTEMD_EXECSTARTPOST "ExecStartPost=/etc/mysql/debian-start")
66+
ENDIF()
6267
MESSAGE(STATUS "Systemd features enabled")
6368
ELSE()
6469
UNSET(LIBSYSTEMD)
70+
UNSET(HAVE_SYSTEMD)
6571
UNSET(HAVE_SYSTEMD_SD_DAEMON_H)
6672
UNSET(HAVE_SYSTEMD_SD_LISTEN_FDS)
6773
UNSET(HAVE_SYSTEMD_SD_NOTIFY)

debian/control

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ 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
2726
Standards-Version: 3.8.2
2827
Homepage: http://mariadb.org/
2928
Vcs-Git: https://github.com/MariaDB/server.git

debian/mariadb-server-10.1.files.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ 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
5958
usr/share/doc/mariadb-server-10.1/mysqld.sym.gz
6059
usr/share/doc/mariadb-server-10.1/INFO_SRC
6160
usr/share/doc/mariadb-server-10.1/INFO_BIN
@@ -94,3 +93,4 @@ usr/share/mysql/wsrep_notify
9493
@CASSANDRA_DEB_FILES@
9594
@SPIDER_DEB_FILES@
9695
@TOKUDB_DEB_FILES@
96+
@SYSTEMD_DEB_FILES@

debian/mariadb-server-10.1.postinst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ fi
286286

287287
db_stop # in case invoke failes
288288

289+
# dh_systemd_start doesn't emit anything since we still ship /etc/init.d/mysql.
290+
# Thus MariaDB server is started via init.d script, which in turn redirects to
291+
# systemctl. If we upgrade from MySQL mysql.service may be masked, which also
292+
# means init.d script is disabled. Unmask mysql service explicitely.
293+
deb-systemd-helper unmask mysql.service >/dev/null || true
294+
289295
#DEBHELPER#
290296

291297
exit 0

debian/rules

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,6 @@ 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-
189183
# mariadb-test
190184
mv $(TMP)/usr/mysql-test $(TMP)/usr/share/mysql
191185

@@ -221,10 +215,7 @@ binary-indep: build install
221215
dh_installexamples -i
222216
dh_installmenu -i
223217
dh_installlogrotate -i
224-
dh_systemd_enable -i support-files/mariadb.service
225-
dh_systemd_enable --no-enable support-files/mariadb@.service
226218
dh_installinit -i
227-
dh_systemd_start -i --restart-after-upgrade mariadb.service
228219
dh_installcron -i
229220
dh_installman -i
230221
dh_installinfo -i
@@ -250,9 +241,12 @@ binary-arch: build install
250241
dh_installexamples -a
251242
dh_installmenu -a
252243
dh_installlogrotate -a --name mysql-server
244+
if [ -x /usr/bin/dh_systemd_enable -a -f debian/mariadb-server-10.1/lib/systemd/system/mariadb.service ]; then dh_systemd_enable -pmariadb-server-10.1 mariadb.service; fi
245+
if [ -x /usr/bin/dh_systemd_enable -a -f debian/mariadb-server-10.1/lib/systemd/system/mariadb@.service ]; then dh_systemd_enable --no-enable -pmariadb-server-10.1 mariadb@.service; fi
253246
# Start mysql in runlevel 19 before 20 where apache, proftpd etc gets
254247
# started which might depend on a running database server.
255248
dh_installinit -a --name=mysql -- defaults 19 21
249+
if [ -x /usr/bin/dh_systemd_start -a -f debian/mariadb-server-10.1/lib/systemd/system/mariadb.service ]; then dh_systemd_start -pmariadb-server-10.1 --restart-after-upgrade mariadb.service; fi
256250
dh_installcron -a --name mysql-server
257251
dh_installman -a
258252
dh_installinfo -a

include/my_systemd.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
1+
/*
2+
Copyright (c) 2015 Daniel Black. All rights reserved.
3+
4+
This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; version 2 of the License.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with this program; if not, write to the Free Software
15+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
16+
*/
17+
118

219
#ifndef MY_SYSTEMD_INCLUDED
320
#define MY_SYSTEMD_INCLUDED
421

522
#if defined(HAVE_SYSTEMD) && !defined(EMBEDDED_LIBRARY)
23+
/*
24+
sd-daemon.h may include inttypes.h. Explicitly request format macros before
25+
the first inclusion of inttypes.h.
26+
*/
27+
#define __STDC_FORMAT_MACROS
628
#include <systemd/sd-daemon.h>
7-
829
#else
9-
10-
11-
1230
#define sd_notify(X, Y)
1331
#define sd_notifyf(E, F, ...)
14-
1532
#endif
1633

1734
#endif /* MY_SYSTEMD_INCLUDED */

scripts/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ ELSE()
300300
mysqld_multi
301301
mysqld_safe
302302
${WSREP_BINARIES}
303-
mariadb-service-convert
303+
${SYSTEMD_SCRIPTS}
304304
)
305305
FOREACH(file ${BIN_SCRIPTS})
306306
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.sh)

scripts/mariadb-service-convert

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,7 @@
2525

2626
tz_old=$TZ
2727

28-
get_params()
29-
{
30-
# does a return so needs to be wrapped in a function
31-
# . /usr/bin/mysqld_safe --simulate
32-
. scripts/mysqld_safe --simulate
33-
}
34-
35-
get_params
28+
. /usr/bin/mysqld_safe --dry-run
3629

3730
echo "# converted using $0"
3831
echo "#"
@@ -66,10 +59,11 @@ if [ -n "$mysqld_ld_library_path" ]; then
6659
fi
6760

6861
if [[ $want_syslog -eq 1 ]]; then
62+
echo StandardOutput=syslog
6963
echo StandardError=syslog
7064
echo SyslogFacility=daemon
71-
echo SyslogLevel=error
72-
echo SyslogLevelPrefix=${syslog_tag_mysqld}
65+
echo SyslogLevel=err
66+
echo SyslogIdentifier=${syslog_tag_mysqld}
7367
fi
7468

7569
if [[ "${flush_caches}" -gt 0 ]]; then
@@ -83,4 +77,6 @@ if [[ "${numa_interleave}" -gt 0 ]]; then
8377
echo
8478
fi
8579

86-
[ -n "${CRASH_SCRIPT}" ] && echo FailureAction=${CRASH_SCRIPT}
80+
if [ -n "${CRASH_SCRIPT}" ]; then
81+
echo FailureAction=${CRASH_SCRIPT}
82+
fi

scripts/mysqld_safe.sh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mysqld_ld_library_path=
2121
flush_caches=0
2222
numa_interleave=0
2323
wsrep_on=0
24-
simulate=0
24+
dry_run=0
2525

2626
# Initial logging status: error log is not open, and not using syslog
2727
logging=init
@@ -82,7 +82,7 @@ Usage: $0 [OPTIONS]
8282
--malloc-lib=LIB Preload shared library LIB if available
8383
--mysqld=FILE Use the specified file as mysqld
8484
--mysqld-version=VERSION Use "mysqld-VERSION" as mysqld
85-
--simulate Simulate the start to detect errors but don't start
85+
--dry-run Simulate the start to detect errors but don't start
8686
--nice=NICE Set the scheduling priority of mysqld
8787
--no-auto-restart Exit after starting mysqld
8888
--nowatch Exit after starting mysqld
@@ -133,7 +133,7 @@ my_which ()
133133
}
134134

135135
log_generic () {
136-
[ $simulate -eq 1 ] && return
136+
[ $dry_run -eq 1 ] && return
137137
priority="$1"
138138
shift
139139

@@ -321,7 +321,7 @@ parse_arguments() {
321321
MYSQLD="mysqld"
322322
fi
323323
;;
324-
--simulate) simulate=1 ;;
324+
--dry[-_]run) dry_run=1 ;;
325325
--nice=*) niceness="$val" ;;
326326
--nowatch|--no[-_]watch|--no[-_]auto[-_]restart) nowatch=1 ;;
327327
--open[-_]files[-_]limit=*) open_files="$val" ;;
@@ -866,7 +866,7 @@ fi
866866
#
867867
# If there exists an old pid file, check if the daemon is already running
868868
# Note: The switches to 'ps' may depend on your operating system
869-
if test -f "$pid_file" && [ $simulate -eq 0 ]
869+
if test -f "$pid_file" && [ $dry_run -eq 0 ]
870870
then
871871
PID=`cat "$pid_file"`
872872
if @CHECK_PID@
@@ -941,9 +941,8 @@ fi
941941
# ulimit -n 256 > /dev/null 2>&1 # Fix for BSD and FreeBSD systems
942942
#fi
943943

944-
945944
cmd="`mysqld_ld_preload_text`$NOHUP_NICENESS"
946-
[ $simulate -eq 0 ] && cmd=''
945+
[ $dry_run -eq 1 ] && cmd=''
947946

948947
#
949948
# Set mysqld's memory interleave policy.
@@ -963,7 +962,7 @@ then
963962
fi
964963

965964
# Launch mysqld with numactl.
966-
[ $simulate -eq 0 ] && cmd="$cmd numactl --interleave=all"
965+
[ $dry_run -eq 0 ] && cmd="$cmd numactl --interleave=all"
967966
elif test $numa_interleave -eq 1
968967
then
969968
log_error "--numa-interleave is not supported on this platform"
@@ -976,8 +975,8 @@ do
976975
cmd="$cmd "`shell_quote_string "$i"`
977976
done
978977
cmd="$cmd $args"
978+
[ $dry_run -eq 1 ] && return
979979
# Avoid 'nohup: ignoring input' warning
980-
[ $simulate -eq 0 ] && cmd='true'
981980
test -n "$NOHUP_NICENESS" && cmd="$cmd < /dev/null"
982981

983982
log_notice "Starting $MYSQLD daemon with databases from $DATADIR"

0 commit comments

Comments
 (0)