Skip to content

Commit 649216e

Browse files
committed
MDEV-37726 wsrep-new-cluster and wsrep-start-position in wrong directory with wrong selinux permissions
After moving the systemd service to using environment files instead of `systemctl set-environment` in 11.6 (MDEV-19210), they (wsrep-new-cluster and wsrep-start-position) are located in /var/lib/mysql along with the socket file in Fedora/RHEL-based distros. This causes them to have incorrect selinux permissions and therefore be not readable by systemd. A solution is to generate these files in the run directory, instead, which already has correct selinux label mysqld_var_run_t mysql-selinux-1.0.12. Dissociating these files and the socket in CMake configs can also prove useful for other things. This also corrects some of the duplicate code in the build scripts and made INSTALL_RUNDATADIR into a proper location and used this for the tmpfiles where the temporary files are created. Debian's location is /run/mysqld/ matching its INSTALL_UNIX_ADDRDIR, which is now a temporary location controlled by tmpfiles.
1 parent 569039e commit 649216e

File tree

5 files changed

+36
-15
lines changed

5 files changed

+36
-15
lines changed

cmake/install_layout.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ SET(INSTALL_UNIX_ADDRDIR_RPM "${INSTALL_MYSQLDATADIR_RPM}/mysql.sock"
163163
SET(INSTALL_SYSTEMD_UNITDIR_RPM "/usr/lib/systemd/system")
164164
SET(INSTALL_SYSTEMD_SYSUSERSDIR_RPM "/usr/lib/sysusers.d")
165165
SET(INSTALL_SYSTEMD_TMPFILESDIR_RPM "/usr/lib/tmpfiles.d")
166+
SET(INSTALL_RUNDATADIR_RPM "/run/mariadb")
166167
SET(INSTALL_PAMDIR_RPM "/${INSTALL_LIBDIR_RPM}/security")
167168
SET(INSTALL_PAMDATADIR_RPM "/etc/security")
168169

@@ -193,7 +194,8 @@ SET(INSTALL_SUPPORTFILESDIR_DEB "share/mysql")
193194
#
194195
SET(INSTALL_MYSQLDATADIR_DEB "/var/lib/mysql")
195196

196-
SET(INSTALL_UNIX_ADDRDIR_DEB "/run/mysqld/mysqld.sock")
197+
SET(INSTALL_RUNDATADIR_DEB "/run/mysqld")
198+
SET(INSTALL_UNIX_ADDRDIR_DEB "${INSTALL_RUNDATADIR_DEB}/mysqld.sock")
197199
SET(INSTALL_SYSTEMD_UNITDIR_DEB "/lib/systemd/system")
198200
SET(INSTALL_SYSTEMD_SYSUSERSDIR_DEB "/usr/lib/sysusers.d")
199201
SET(INSTALL_SYSTEMD_TMPFILESDIR_DEB "/usr/lib/tmpfiles.d")
@@ -257,3 +259,7 @@ IF(NOT MYSQL_UNIX_ADDR)
257259
SET(MYSQL_UNIX_ADDR ${INSTALL_UNIX_ADDRDIR})
258260
ENDIF()
259261

262+
IF(NOT INSTALL_RUNDATADIR)
263+
get_filename_component(MYSQL_UNIX_DIR ${MYSQL_UNIX_ADDR} DIRECTORY)
264+
SET(INSTALL_RUNDATADIR "${MYSQL_UNIX_DIR}" CACHE FILEPATH "Rundata installation directory" ${FORCE})
265+
ENDIF()

scripts/galera_new_cluster.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ EOF
2121
exit 0
2222
fi
2323

24-
systemctl set-environment _WSREP_NEW_CLUSTER='--wsrep-new-cluster' && \
25-
systemctl restart ${1:-mariadb}
24+
echo _WSREP_NEW_CLUSTER='--wsrep-new-cluster' > "@INSTALL_RUNDATADIR@/wsrep-new-cluster" && \
25+
systemctl restart mariadb.service
2626

2727
extcode=$?
2828

29-
systemctl set-environment _WSREP_NEW_CLUSTER=''
29+
rm -f "@INSTALL_RUNDATADIR@/wsrep-new-cluster"
3030

3131
exit $extcode

support-files/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ 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})
5048
ENDIF()
5149

5250
# XXX: shouldn't we just have variables for all this stuff and centralise
@@ -212,8 +210,11 @@ IF(UNIX AND NOT WITHOUT_SERVER)
212210
RENAME mariadb.conf COMPONENT Server)
213211
ENDIF()
214212

215-
IF((HAVE_SYSTEMD OR INSTALL_SYSTEMD_TMPUSERS) AND INSTALL_SYSTEMD_TMPFILESDIR)
216-
get_filename_component(MYSQL_UNIX_DIR ${MYSQL_UNIX_ADDR} DIRECTORY)
213+
IF((HAVE_SYSTEMD OR INSTALL_SYSTEMD_TMPUSERS) AND INSTALL_SYSTEMD_TMPFILESDIR
214+
AND INSTALL_RUNDATADIR)
215+
IF(MYSQL_DATADIR STREQUAL INSTALL_RUNDATADIR)
216+
SET(DISABLE_TMP "#")
217+
ENDIF()
217218
CONFIGURE_FILE(tmpfiles.conf.in
218219
${CMAKE_CURRENT_BINARY_DIR}/tmpfiles.conf @ONLY)
219220
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/tmpfiles.conf

support-files/mariadb.service.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,22 @@ ProtectHome=true
6666
PermissionsStartOnly=true
6767

6868
# Use an environment file to pass variable _WSREP_NEW_CLUSTER
69-
EnvironmentFile=-@mysqlunixdir@/wsrep-new-cluster
69+
EnvironmentFile=-@INSTALL_RUNDATADIR@/wsrep-new-cluster
7070

7171
# Use an environment file to pass variable _WSREP_START_POSITION
72-
EnvironmentFile=-@mysqlunixdir@/wsrep-start-position
72+
EnvironmentFile=-@INSTALL_RUNDATADIR@/wsrep-start-position
7373

7474
@SYSTEMD_EXECSTARTPRE@
7575

7676
# Perform automatic wsrep recovery. When server is started without wsrep,
7777
# galera_recovery simply returns an empty string. In any case, however,
7878
# the script is not expected to return with a non-zero status.
79-
# It is always safe to remove @mysqlunixdir@/wsrep-start-position
79+
# It is always safe to remove @INSTALL_RUNDATADIR@/wsrep-start-position
8080
# environment file.
8181
# Do not panic if galera_recovery script is not available. (MDEV-10538)
8282
ExecStartPre=/bin/sh -c "[ ! -e @bindir@/galera_recovery ] && VAR= || \
8383
VAR=`@bindir@/galera_recovery`; [ $? -eq 0 ] \
84-
&& echo _WSREP_START_POSITION=$VAR > @mysqlunixdir@/wsrep-start-position || exit 1"
84+
&& echo _WSREP_START_POSITION=$VAR > @INSTALL_RUNDATADIR@/wsrep-start-position || exit 1"
8585

8686
# Needed to create system tables etc.
8787
# ExecStartPre=@scriptdir@/mariadb-install-db -u mysql
@@ -93,8 +93,8 @@ ExecStartPre=/bin/sh -c "[ ! -e @bindir@/galera_recovery ] && VAR= || \
9393
# _WSREP_NEW_CLUSTER is for the exclusive use of the script galera_new_cluster
9494
ExecStart=@sbindir@/mariadbd $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION
9595

96-
# Unset _WSREP_START_POSITION environment variable.
97-
ExecStartPost=/bin/rm -f @mysqlunixdir@/wsrep-start-position
96+
# Unset _WSREP_START_POSITION/_WSREP_NEW_CLUSTER environment variable.
97+
ExecStartPost=/bin/rm -f @INSTALL_RUNDATADIR@/wsrep-start-position @INSTALL_RUNDATADIR@/wsrep-new-cluster
9898

9999
@SYSTEMD_EXECSTARTPOST@
100100

support-files/tmpfiles.conf.in

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
d @MYSQL_UNIX_DIR@ 0755 @MYSQLD_USER@ @MYSQLD_USER@ -
1+
# This is the directory where the unix socket
2+
# of MariaDB may be created.
3+
#
4+
# Under Galera this is where an envfile of
5+
# the Galera start position is stored.
6+
#
7+
# Other temporary directories can be created here like:
8+
# * tmpdir
9+
# * innodb_tmpdir
10+
# * innodb_temp_data_file_path
11+
# * rocksdb_tmpdir
12+
# etc.
13+
# It shouldn't be used for datadir which is why it
14+
# may be disabled.
15+
@DISABLE_TMP@d @INSTALL_RUNDATADIR@ 0755 @MYSQLD_USER@ @MYSQLD_USER@ -

0 commit comments

Comments
 (0)