Skip to content

Commit acdf92d

Browse files
author
Andrzej Religa
committed
WL#13707 add systemd notify support
WL#13708 speed up component tests via systemd notify protocol WL#13707 introduces use of the systemd notification mechanism to notify about the Router readiness and stopping. WL#13708 uses the systemd notification mechanism in the Router component tests to figure out when the launched processes like Router and Mock Server are initialized and ready to be tested. RB: 24213
1 parent 98609e2 commit acdf92d

File tree

93 files changed

+2361
-885
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2361
-885
lines changed

cmake/install_layout.cmake

+6-4
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,6 @@ ENDIF()
354354
# Install layout for router, follows the same pattern as above.
355355
#
356356

357-
IF("${ROUTER_INSTALL_DOCDIR}" STREQUAL "")
358-
SET(ROUTER_INSTALL_DOCDIR "${INSTALL_DOCDIR}")
359-
ENDIF()
360-
361357
IF(NOT ROUTER_INSTALL_LAYOUT)
362358
SET(DEFAULT_ROUTER_INSTALL_LAYOUT "${INSTALL_LAYOUT}")
363359
ENDIF()
@@ -391,6 +387,7 @@ ELSE()
391387
ENDIF()
392388
SET(ROUTER_INSTALL_LOGROTATEDIR_STANDALONE ".")
393389
SET(ROUTER_INSTALL_LOGROTATEFILE_STANDALONE "mysqlrouter-log-rotate")
390+
SET(ROUTER_INSTALL_DOCDIR_STANDALONE "docs")
394391

395392
#
396393
# TARGZ layout
@@ -404,6 +401,7 @@ FOREACH(var
404401
LIB
405402
PLUGIN
406403
LOGROTATE
404+
DOC
407405
)
408406
SET(ROUTER_INSTALL_${var}DIR_TARGZ ${ROUTER_INSTALL_${var}DIR_STANDALONE})
409407
ENDFOREACH()
@@ -436,6 +434,7 @@ ELSE()
436434
ENDIF()
437435
SET(ROUTER_INSTALL_LOGROTATEDIR_RPM "/etc/logrotate.d")
438436
SET(ROUTER_INSTALL_LOGROTATEFILE_RPM "mysqlrouter")
437+
#SET(ROUTER_INSTALL_DOCDIR_RPM unset - installed directly by RPM)
439438

440439
#
441440
# DEB layout
@@ -450,6 +449,7 @@ SET(ROUTER_INSTALL_LIBDIR_DEB "lib/mysqlrouter/private")
450449
SET(ROUTER_INSTALL_PLUGINDIR_DEB "lib/mysqlrouter/plugin")
451450
SET(ROUTER_INSTALL_LOGROTATEDIR_DEB "/etc/logrotate.d")
452451
SET(ROUTER_INSTALL_LOGROTATEFILE_DEB "mysqlrouter")
452+
SET(ROUTER_INSTALL_DOCDIR_DEB "share/mysqlrouter/docs")
453453

454454
#
455455
# SVR4 layout
@@ -463,6 +463,7 @@ FOREACH(var
463463
LIB
464464
PLUGIN
465465
LOGROTATE
466+
DOC
466467
)
467468
SET(ROUTER_INSTALL_${var}DIR_SVR4 ${ROUTER_INSTALL_${var}DIR_STANDALONE})
468469
ENDFOREACH()
@@ -486,6 +487,7 @@ FOREACH(directory
486487
LIB
487488
PLUGIN
488489
LOGROTATE
490+
DOC
489491
)
490492
SET(ROUTER_INSTALL_${directory}DIR
491493
${ROUTER_INSTALL_${directory}DIR_${ROUTER_INSTALL_LAYOUT}}

cmake/systemd.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2015, 2020, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0,

packaging/deb-in/CMakeLists.txt

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2016, 2020, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0,
@@ -212,7 +212,8 @@ SET (DEB_CONTROL_BDEPS "")
212212
SET (DEB_RULES_INSTALL_APPARMOR "")
213213
SET (DEB_RULES_APPARMOR_LOAD "")
214214
SET (DEB_INSTALL_SERVER_APPARMOR "")
215-
SET (DEB_INIT_APPARMOR "")
215+
SET (DEB_INIT_SERVER_APPARMOR "")
216+
SET (DEB_INIT_ROUTER_APPARMOR "")
216217
# Only used on Ubuntu 16.04 for manually created debug symbol packages
217218
SET (DEB_CONTROL_DBGSYM "")
218219
SET (DEB_RULES_STRIP "")
@@ -237,8 +238,9 @@ IF(DEB_ID STREQUAL "ubuntu")
237238
")
238239
SET (DEB_INSTALL_SERVER_APPARMOR "etc/apparmor.d/usr.sbin.mysqld")
239240
SET (DEB_INSTALL_ROUTER_APPARMOR "etc/apparmor.d/usr.bin.mysqlrouter")
240-
SET (DEB_INIT_APPARMOR "/lib/apparmor/profile-load usr.sbin.mysqld")
241-
241+
SET (DEB_INIT_SERVER_APPARMOR "/lib/apparmor/profile-load usr.sbin.mysqld")
242+
SET (DEB_INIT_ROUTER_APPARMOR "/lib/apparmor/profile-load usr.bin.mysqlrouter")
243+
242244
# Ubuntu 16.04 doesn't automatically create debug symbol packages
243245
IF(DEB_CODENAME STREQUAL "xenial")
244246
SET (DEB_CONTROL_DBGSYM ${DEB_CONTROL_DBGSYM_DEFAULT})

packaging/deb-in/extra/apparmor-profile-router.in

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
#include <tunables/global>
44

5-
/usr/bin/mysqlrouter {
5+
# flags=(attach_disconnected) is needed, otherwise when trying
6+
# to write to NOTIFY_SOCKET Router hits:
7+
# Failed name lookup - disconnected path" error=-13
8+
# profile="/usr/bin/mysqlrouter" name="run/systemd/notify"
9+
10+
/usr/bin/mysqlrouter flags=(attach_disconnected) {
611
#include <abstractions/base>
712
#include <abstractions/nameservice>
813
#include <abstractions/user-tmp>
@@ -27,6 +32,9 @@
2732
/var/run/mysqlrouter/** rw,
2833
/run/mysqlrouter/** rw,
2934

35+
# Allow systemd notify messages
36+
/{,var/}run/systemd/notify w,
37+
3038
# Allow read/ write to /tmp
3139
/tmp/ r,
3240
/tmp/* rw,

packaging/deb-in/extra/mysql-systemd-start

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
3+
# Copyright (c) 2015, 2020, Oracle and/or its affiliates.
44
#
55
# This program is free software; you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License, version 2.0,
@@ -36,7 +36,7 @@ sanity () {
3636
verify_ready $1
3737
verify_database $1
3838

39-
@DEB_INIT_APPARMOR@
39+
@DEB_INIT_SERVER_APPARMOR@
4040

4141
if [ ! -r /etc/mysql/my.cnf ]; then
4242
echo "MySQL configuration not found at /etc/mysql/my.cnf. Please install one."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) 2020, Oracle and/or its affiliates.
4+
#
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License, version 2.0,
7+
# as published by the Free Software Foundation.
8+
#
9+
# This program is also distributed with certain software (including
10+
# but not limited to OpenSSL) that is licensed under separate terms,
11+
# as designated in a particular file or component or in included license
12+
# documentation. The authors of MySQL hereby grant you an additional
13+
# permission to link the program and your derivative works with the
14+
# separately licensed software that they have included with MySQL.
15+
#
16+
# This program is distributed in the hope that it will be useful,
17+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
# GNU General Public License, version 2.0, for more details.
20+
#
21+
# You should have received a copy of the GNU General Public License
22+
# along with this program; if not, write to the Free Software
23+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24+
25+
# Scripts to run by MySQL Router systemd service
26+
#
27+
# Needed argument: pre
28+
#
29+
# pre mode : try to perform sanity check for configuration, log, data
30+
31+
sanity () {
32+
@DEB_INIT_ROUTER_APPARMOR@
33+
34+
if [ ! -r /etc/mysqlrouter/mysqlrouter.conf ]; then
35+
echo "MySQL configuration not found at /etc/mysqlrouter/mysqlrouter.conf."
36+
exit 1
37+
fi
38+
}
39+
40+
case $1 in
41+
"pre") sanity $2 ;;
42+
esac

packaging/deb-in/mysql-router-packagesource.install.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ usr/lib/mysqlrouter/private/libmysqlrouter_http.so.1
4444
usr/lib/mysqlrouter/private/libmysqlrouter_http_auth_backend.so.1
4545
usr/lib/mysqlrouter/private/libmysqlrouter_http_auth_realm.so.1
4646

47-
usr/share/mysql-@MYSQL_BASE_VERSION@/docs/sample_mysqlrouter.conf
47+
usr/share/mysqlrouter/docs/sample_mysqlrouter.conf
48+
usr/share/mysqlrouter/mysqlrouter-systemd-start
4849
usr/share/man/man1/mysqlrouter.1
4950
usr/share/man/man1/mysqlrouter_passwd.1
5051
usr/share/man/man1/mysqlrouter_plugin_info.1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2020, Oracle and/or its affiliates.
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, version 2.0,
5+
# as published by the Free Software Foundation.
6+
#
7+
# This program is also distributed with certain software (including
8+
# but not limited to OpenSSL) that is licensed under separate terms,
9+
# as designated in a particular file or component or in included license
10+
# documentation. The authors of MySQL hereby grant you an additional
11+
# permission to link the program and your derivative works with the
12+
# separately licensed software that they have included with MySQL.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License, version 2.0, for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with this program; if not, write to the Free Software
21+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22+
23+
# MySQL Router service file
24+
25+
[Unit]
26+
Description=MySQL @DEB_LICENSENAME@ Router
27+
Documentation=man:mysqlrouter
28+
After=network.target
29+
30+
[Install]
31+
WantedBy=multi-user.target
32+
33+
[Service]
34+
User=mysqlrouter
35+
Group=mysqlrouter
36+
Type=notify
37+
ExecStartPre=/usr/share/mysqlrouter/mysqlrouter-systemd-start pre
38+
ExecStart=/usr/bin/mysqlrouter
39+
LimitNOFILE = 10000
40+
Restart=on-failure
41+
PrivateTmp=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) 2020, Oracle and/or its affiliates.
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, version 2.0,
5+
# as published by the Free Software Foundation.
6+
#
7+
# This program is also distributed with certain software (including
8+
# but not limited to OpenSSL) that is licensed under separate terms,
9+
# as designated in a particular file or component or in included license
10+
# documentation. The authors of MySQL hereby grant you an additional
11+
# permission to link the program and your derivative works with the
12+
# separately licensed software that they have included with MySQL.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License, version 2.0, for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with this program; if not, write to the Free Software
21+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22+
23+
d @ROUTER_INSTALL_RUNTIMEDIR@ 0755 mysqlrouter mysqlrouter -

packaging/deb-in/rules.in

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/make -f
22

3-
# Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
3+
# Copyright (c) 2015, 2020, Oracle and/or its affiliates.
44
#
55
# This program is free software; you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License, version 2.0,
@@ -81,8 +81,9 @@ override_dh_auto_install:
8181
install -m 0644 debian/extra/mysql-helpers debian/tmp/usr/share/mysql-@MYSQL_BASE_VERSION@/
8282
# add apparmor profile
8383
@DEB_RULES_INSTALL_APPARMOR@
84-
# add systemd script
84+
# add systemd scripts
8585
install -m 0755 debian/extra/mysql-systemd-start debian/tmp/usr/share/mysql-@MYSQL_BASE_VERSION@/
86+
install -m 0755 debian/extra/mysqlrouter-systemd-start debian/tmp/usr/share/mysqlrouter/
8687
touch $@
8788

8889
override_dh_installinit:

packaging/rpm-common/CMakeLists.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2016, 2020, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0,
@@ -38,8 +38,6 @@ FOREACH(cfile
3838
my.cnf
3939
mysql.logrotate
4040
mysqlrouter.conf
41-
mysqlrouter.service
42-
mysqlrouter.tmpfiles.d
4341
)
4442
CONFIGURE_FILE(${cfile}.in ${CMAKE_CURRENT_BINARY_DIR}/${cfile} @ONLY)
4543
ENDFOREACH()

packaging/rpm-fedora/mysql.spec.in

-2
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,6 @@ install -d -m 0755 %{buildroot}%{_sysconfdir}/ld.so.conf.d
576576
echo "%{_libdir}/mysql" > %{buildroot}%{_sysconfdir}/ld.so.conf.d/mysql-%{_arch}.conf
577577

578578
# Router files
579-
install -D -p -m 0644 packaging/rpm-common/mysqlrouter.service %{buildroot}%{_unitdir}/mysqlrouter.service
580-
install -D -p -m 0644 packaging/rpm-common/mysqlrouter.tmpfiles.d %{buildroot}%{_tmpfilesdir}/mysqlrouter.conf
581579
install -D -p -m 0644 packaging/rpm-common/mysqlrouter.conf %{buildroot}%{_sysconfdir}/mysqlrouter/mysqlrouter.conf
582580

583581
# Back to top level

packaging/rpm-oel/mysql.spec.in

-2
Original file line numberDiff line numberDiff line change
@@ -903,8 +903,6 @@ install -p -m 0755 packaging/rpm-common/mysql_config.sh %{buildroot}/%{_bindir}/
903903
%endif # cluster
904904

905905
%if 0%{?systemd}
906-
install -D -p -m 0644 packaging/rpm-common/mysqlrouter.service %{buildroot}%{_unitdir}/mysqlrouter.service
907-
install -D -p -m 0644 packaging/rpm-common/mysqlrouter.tmpfiles.d %{buildroot}%{_tmpfilesdir}/mysqlrouter.conf
908906
%else
909907
install -D -p -m 0755 packaging/rpm-common/mysqlrouter.init %{buildroot}%{_sysconfdir}/init.d/mysqlrouter
910908
%endif # systemd

packaging/rpm-sles/mysql.spec.in

-2
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,6 @@ echo "%{_libdir}/mysql" > %{buildroot}%{_sysconfdir}/ld.so.conf.d/mysql-%{_arch}
680680
install -d -m 0755 %{buildroot}/var/log/mysqlrouter
681681
install -d -m 0755 %{buildroot}/var/run/mysqlrouter
682682

683-
install -D -p -m 0644 packaging/rpm-common/mysqlrouter.service %{buildroot}%{_unitdir}/mysqlrouter.service
684-
install -D -p -m 0644 packaging/rpm-common/mysqlrouter.tmpfiles.d %{buildroot}%{_tmpfilesdir}/mysqlrouter.conf
685683
install -D -p -m 0644 packaging/rpm-common/mysqlrouter.conf %{buildroot}%{_sysconfdir}/mysqlrouter/mysqlrouter.conf
686684

687685
# Remove files pages we explicitly do not want to package

router/src/harness/include/mysql/harness/loader.h

+3
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,9 @@ class HARNESS_EXPORT Loader {
10051005

10061006
void spawn_signal_handler_thread();
10071007

1008+
std::mutex signal_thread_ready_m_;
1009+
std::condition_variable signal_thread_ready_cond_;
1010+
bool signal_thread_ready_{false};
10081011
std::thread signal_thread_;
10091012

10101013
#ifdef FRIEND_TEST
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright (c) 2020, Oracle and/or its affiliates.
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, version 2.0,
6+
as published by the Free Software Foundation.
7+
8+
This program is also distributed with certain software (including
9+
but not limited to OpenSSL) that is licensed under separate terms,
10+
as designated in a particular file or component or in included license
11+
documentation. The authors of MySQL hereby grant you an additional
12+
permission to link the program and your derivative works with the
13+
separately licensed software that they have included with MySQL.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU General Public License for more details.
19+
20+
You should have received a copy of the GNU General Public License
21+
along with this program; if not, write to the Free Software
22+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23+
*/
24+
25+
#ifndef MYSQL_HARNESS_SD_NOTIFY_INCLUDED
26+
#define MYSQL_HARNESS_SD_NOTIFY_INCLUDED
27+
28+
#include "harness_export.h"
29+
30+
namespace mysql_harness {
31+
32+
bool HARNESS_EXPORT notify_ready();
33+
bool HARNESS_EXPORT notify_stopping();
34+
35+
} // namespace mysql_harness
36+
#endif /* MYSQL_HARNESS_SD_NOTIFY_INCLUDED */

0 commit comments

Comments
 (0)