Skip to content

Commit 569039e

Browse files
eworm-degrooverdan
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 f84f2ce commit 569039e

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
@@ -45,6 +45,8 @@ ELSE()
4545
IF(DEB)
4646
SET(su_user "#su mysql mysql")
4747
ENDIF()
48+
get_filename_component(MYSQL_UNIX_DIR ${MYSQL_UNIX_ADDR} DIRECTORY)
49+
SET(mysqlunixdir ${MYSQL_UNIX_DIR})
4850
ENDIF()
4951

5052
# 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
@@ -65,17 +65,23 @@ ProtectHome=true
6565
# Execute pre and post scripts as root, otherwise it does it as User=
6666
PermissionsStartOnly=true
6767

68+
# Use an environment file to pass variable _WSREP_NEW_CLUSTER
69+
EnvironmentFile=-@mysqlunixdir@/wsrep-new-cluster
70+
71+
# Use an environment file to pass variable _WSREP_START_POSITION
72+
EnvironmentFile=-@mysqlunixdir@/wsrep-start-position
73+
6874
@SYSTEMD_EXECSTARTPRE@
6975

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

8086
# Needed to create system tables etc.
8187
# ExecStartPre=@scriptdir@/mariadb-install-db -u mysql
@@ -88,7 +94,7 @@ ExecStartPre=/bin/sh -c "[ ! -e @bindir@/galera_recovery ] && VAR= || \
8894
ExecStart=@sbindir@/mariadbd $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION
8995

9096
# Unset _WSREP_START_POSITION environment variable.
91-
ExecStartPost=/bin/sh -c "systemctl unset-environment _WSREP_START_POSITION"
97+
ExecStartPost=/bin/rm -f @mysqlunixdir@/wsrep-start-position
9298

9399
@SYSTEMD_EXECSTARTPOST@
94100

0 commit comments

Comments
 (0)