Commit 6c405904 authored by Christian Hesse's avatar Christian Hesse Committed by Andrew Hutchings

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.
parent ab10a675
...@@ -32,6 +32,8 @@ ELSE() ...@@ -32,6 +32,8 @@ ELSE()
SET(MYSQLD_GROUP "mysql") SET(MYSQLD_GROUP "mysql")
SET(ini_file_extension "cnf") SET(ini_file_extension "cnf")
SET(HOSTNAME "uname -n") SET(HOSTNAME "uname -n")
get_filename_component(MYSQL_UNIX_DIR ${MYSQL_UNIX_ADDR} DIRECTORY)
SET(mysqlunixdir ${MYSQL_UNIX_DIR})
ENDIF() ENDIF()
# XXX: shouldn't we just have variables for all this stuff and centralise # XXX: shouldn't we just have variables for all this stuff and centralise
......
...@@ -70,20 +70,20 @@ ProtectSystem=full ...@@ -70,20 +70,20 @@ ProtectSystem=full
# Prevent accessing /home, /root and /run/user # Prevent accessing /home, /root and /run/user
ProtectHome=true ProtectHome=true
# Execute pre and post scripts as root, otherwise it does it as User= # Use an environment file to pass variable _WSREP_START_POSITION
PermissionsStartOnly=true EnvironmentFile=-@mysqlunixdir@/wsrep-start-position
@SYSTEMD_EXECSTARTPRE@ @SYSTEMD_EXECSTARTPRE@
# Perform automatic wsrep recovery. When server is started without wsrep, # Perform automatic wsrep recovery. When server is started without wsrep,
# galera_recovery simply returns an empty string. In any case, however, # galera_recovery simply returns an empty string. In any case, however,
# the script is not expected to return with a non-zero status. # the script is not expected to return with a non-zero status.
# It is always safe to unset _WSREP_START_POSITION environment variable. # It is always safe to remove @mysqlunixdir@/wsrep-start-position
# environment file.
# Do not panic if galera_recovery script is not available. (MDEV-10538) # Do not panic if galera_recovery script is not available. (MDEV-10538)
ExecStartPre=/bin/sh -c "systemctl unset-environment _WSREP_START_POSITION"
ExecStartPre=/bin/sh -c "[ ! -e @bindir@/galera_recovery ] && VAR= || \ ExecStartPre=/bin/sh -c "[ ! -e @bindir@/galera_recovery ] && VAR= || \
VAR=`cd @bindir@/..; @bindir@/galera_recovery`; [ $? -eq 0 ] \ VAR=`cd @bindir@/..; @bindir@/galera_recovery`; [ $? -eq 0 ] \
&& systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1" && echo _WSREP_START_POSITION=$VAR > @mysqlunixdir@/wsrep-start-position || exit 1"
# Needed to create system tables etc. # Needed to create system tables etc.
# ExecStartPre=@scriptdir@/mysql_install_db -u mysql # ExecStartPre=@scriptdir@/mysql_install_db -u mysql
...@@ -96,7 +96,7 @@ ExecStartPre=/bin/sh -c "[ ! -e @bindir@/galera_recovery ] && VAR= || \ ...@@ -96,7 +96,7 @@ ExecStartPre=/bin/sh -c "[ ! -e @bindir@/galera_recovery ] && VAR= || \
ExecStart=@sbindir@/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION ExecStart=@sbindir@/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION
# Unset _WSREP_START_POSITION environment variable. # Unset _WSREP_START_POSITION environment variable.
ExecStartPost=/bin/sh -c "systemctl unset-environment _WSREP_START_POSITION" ExecStartPost=/bin/rm -f @mysqlunixdir@/wsrep-start-position
@SYSTEMD_EXECSTARTPOST@ @SYSTEMD_EXECSTARTPOST@
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment