Skip to content

Commit 7936254

Browse files
eworm-deLinuxJedi
authored andcommitted
MDEV-19210: use environment file in systemd units for _WSREP_START_POSITION
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 26f01f8 commit 7936254

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
@@ -71,17 +71,23 @@ ProtectHome=true
7171
# Execute pre and post scripts as root, otherwise it does it as User=
7272
PermissionsStartOnly=true
7373

74+
# Use an environment file to pass variable _WSREP_NEW_CLUSTER
75+
EnvironmentFile=-@mysqlunixdir@/wsrep-new-cluster
76+
77+
# Use an environment file to pass variable _WSREP_START_POSITION
78+
EnvironmentFile=-@mysqlunixdir@/wsrep-start-position
79+
7480
@SYSTEMD_EXECSTARTPRE@
7581

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

8692
# Needed to create system tables etc.
8793
# ExecStartPre=@scriptdir@/mysql_install_db -u mysql
@@ -94,7 +100,7 @@ ExecStartPre=/bin/sh -c "[ ! -e @bindir@/galera_recovery ] && VAR= || \
94100
ExecStart=@sbindir@/mariadbd $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION
95101

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

99105
@SYSTEMD_EXECSTARTPOST@
100106

0 commit comments

Comments
 (0)