Skip to content
/ server Public

Commit 8775722

Browse files
eworm-devuvova
authored andcommitted
MDEV-35904/MDEV-19210: use environment file in systemd units for _WSREP_START_POSITION
MDEV-35904 - backport MDEV-19210 to 10.11 as referenced by unset environment variables become warnings. We used to run `systemctl set-environment` to pass _WSREP_START_POSITION. This is bad because: * it clutter systemd's environment (yes, pid 1) * it requires root privileges * options (like LimitNOFILE=) are not applied Let's just create an environment file in ExecStartPre=, that is read before ExecStart= kicks in. We have _WSREP_START_POSITION around for the main process without any downsides.
1 parent fafa57b commit 8775722

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

support-files/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ ELSE()
3232
SET(MYSQLD_GROUP "mysql")
3333
SET(ini_file_extension "cnf")
3434
SET(HOSTNAME "uname -n")
35+
get_filename_component(MYSQL_UNIX_DIR ${MYSQL_UNIX_ADDR} DIRECTORY)
36+
SET(mysqlunixdir ${MYSQL_UNIX_DIR})
3537
ENDIF()
3638

3739
# XXX: shouldn't we just have variables for all this stuff and centralise

support-files/mariadb.service.in

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,23 @@ ProtectHome=true
6969
# Execute pre and post scripts as root, otherwise it does it as User=
7070
PermissionsStartOnly=true
7171

72+
# Use an environment file to pass variable _WSREP_NEW_CLUSTER
73+
EnvironmentFile=-@mysqlunixdir@/wsrep-new-cluster
74+
75+
# Use an environment file to pass variable _WSREP_START_POSITION
76+
EnvironmentFile=-@mysqlunixdir@/wsrep-start-position
77+
7278
@SYSTEMD_EXECSTARTPRE@
7379

7480
# Perform automatic wsrep recovery. When server is started without wsrep,
7581
# galera_recovery simply returns an empty string. In any case, however,
7682
# the script is not expected to return with a non-zero status.
77-
# It is always safe to unset _WSREP_START_POSITION environment variable.
83+
# It is always safe to remove @mysqlunixdir@/wsrep-start-position
84+
# environment file.
7885
# Do not panic if galera_recovery script is not available. (MDEV-10538)
79-
ExecStartPre=/bin/sh -c "systemctl unset-environment _WSREP_START_POSITION"
8086
ExecStartPre=/bin/sh -c "[ ! -e @bindir@/galera_recovery ] && VAR= || \
8187
VAR=`@bindir@/galera_recovery`; [ $? -eq 0 ] \
82-
&& systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1"
88+
&& echo _WSREP_START_POSITION=$VAR > @mysqlunixdir@/wsrep-start-position || exit 1"
8389

8490
# Needed to create system tables etc.
8591
# ExecStartPre=@scriptdir@/mysql_install_db -u mysql
@@ -92,7 +98,7 @@ ExecStartPre=/bin/sh -c "[ ! -e @bindir@/galera_recovery ] && VAR= || \
9298
ExecStart=@sbindir@/mariadbd $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION
9399

94100
# Unset _WSREP_START_POSITION environment variable.
95-
ExecStartPost=/bin/sh -c "systemctl unset-environment _WSREP_START_POSITION"
101+
ExecStartPost=/bin/rm -f @mysqlunixdir@/wsrep-start-position
96102

97103
@SYSTEMD_EXECSTARTPOST@
98104

0 commit comments

Comments
 (0)