summaryrefslogtreecommitdiff
path: root/packaging/rpm-oel/mysql-systemd-start
diff options
context:
space:
mode:
Diffstat (limited to 'packaging/rpm-oel/mysql-systemd-start')
-rw-r--r--packaging/rpm-oel/mysql-systemd-start52
1 files changed, 52 insertions, 0 deletions
diff --git a/packaging/rpm-oel/mysql-systemd-start b/packaging/rpm-oel/mysql-systemd-start
new file mode 100644
index 00000000000..9cb2a25c990
--- /dev/null
+++ b/packaging/rpm-oel/mysql-systemd-start
@@ -0,0 +1,52 @@
+#! /bin/bash
+#
+# Scripts to run by MySQL systemd service
+#
+# Needed argument: pre | post
+#
+# pre mode : try to run mysql_install_db and fix perms and SELinux contexts
+# post mode : ping server until answer is received
+#
+
+install_db () {
+ # Note: something different than datadir=/var/lib/mysql requires SELinux policy changes (in enforcing mode)
+ datadir=$(/usr/bin/my_print_defaults server mysqld | grep '^--datadir=' | sed -n 's/--datadir=//p')
+
+ # Restore log, dir, perms and SELinux contexts
+ [ -d "$datadir" ] || install -d -m 0755 -omysql -gmysql "$datadir" || exit 1
+ log=/var/log/mysqld.log
+ [ -e $log ] || touch $log
+ chmod 0640 $log
+ chown mysql:mysql $log || exit 1
+ if [ -x /usr/sbin/restorecon ]; then
+ /usr/sbin/restorecon "$datadir"
+ /usr/sbin/restorecon $log
+ fi
+
+ # If special mysql dir is in place, skip db install
+ [ -d "$datadir/mysql" ] && exit 0
+
+ # Create initial db
+ /usr/bin/mysql_install_db --rpm --datadir="$datadir" --user=mysql
+ exit 0
+}
+
+pinger () {
+ # Wait for ping to answer to signal startup completed,
+ # might take a while in case of e.g. crash recovery
+ # MySQL systemd service will timeout script if no answer
+ while /bin/true ; do
+ sleep 1
+ mysqladmin ping >/dev/null 2>&1 && break
+ done
+ exit 0
+}
+
+# main
+case $1 in
+ "pre") install_db ;;
+ "post") pinger ;;
+esac
+
+exit 0
+