aboutsummaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-support/mysql/mariadb
diff options
context:
space:
mode:
authorHongxu Jia <hongxu.jia@windriver.com>2015-11-25 10:04:31 +0800
committerMartin Jansa <Martin.Jansa@gmail.com>2015-12-18 12:39:49 +0100
commitc0a1be1cebfc098d342f9efe147b193b51d5a8a2 (patch)
treeeece26973d343dee19cfc0fd924e143fdac9e18d /meta-oe/recipes-support/mysql/mariadb
parent0c923c7e33838f9132c9c62593bff42f5514a221 (diff)
downloadmeta-openembedded-c0a1be1cebfc098d342f9efe147b193b51d5a8a2.tar.gz
mariadb.inc: fix mysqld hung at first init time based on systemd
While SYSTEMD_AUTO_ENABLE_mariadb-server = "enable", the mysqld service hungs. ... [ **] A start job is running for Run pending postinsts (25s / no limit) [ OK ] Stopped MariaDB database server. ... In mariadb-server's pkg_postinst, it install db at first runtime. And the following 'systemctl mysqld restart' casued the hunging. So the fix idea is to reomove pkg_postinst and still install db at first runtime. Introduce mysql-systemd-start from ${S}/packaging/rpm-oel/. For review convenience, we add them as file. The mysql-systemd-start provides two functions: the install_db is to install db at fist runtime (the first runtime means if a db existed, the install_db will directly exit); the pinger is to wait for mysqld service startup completed. The mysqld.service add ExecStartPost than previous which invoke 'mysql-systemd-start post' to wait for mysqld service startup completed. We add a package to provide install_db, so the user could choose it to install database for mariadb at first boot before mysqld started. It also fix another issue: When you manually restart mysqld and do mysql test to connect the server, the return of the restart could make sure mysqld is ready, and the following db connect will not fail with: ... Can't connect to local MySQL server through socket ... Tweak my.cnf to remove obsolete/incorrect parameter. Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com> Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Diffstat (limited to 'meta-oe/recipes-support/mysql/mariadb')
-rwxr-xr-xmeta-oe/recipes-support/mysql/mariadb/install_db13
-rw-r--r--meta-oe/recipes-support/mysql/mariadb/install_db.service17
-rw-r--r--meta-oe/recipes-support/mysql/mariadb/my.cnf1
-rw-r--r--meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start66
-rw-r--r--meta-oe/recipes-support/mysql/mariadb/mysqld.service9
5 files changed, 105 insertions, 1 deletions
diff --git a/meta-oe/recipes-support/mysql/mariadb/install_db b/meta-oe/recipes-support/mysql/mariadb/install_db
new file mode 100755
index 0000000000..512a7da7ee
--- /dev/null
+++ b/meta-oe/recipes-support/mysql/mariadb/install_db
@@ -0,0 +1,13 @@
+#! /bin/sh
+case "$1" in
+ start)
+ echo "Starting to install database for mariadb"
+ /usr/bin/mysql-systemd-start pre
+ echo "done."
+ ;;
+ *)
+ echo "Usage: /etc/init.d/install_db start"
+ exit 1
+esac
+
+exit 0
diff --git a/meta-oe/recipes-support/mysql/mariadb/install_db.service b/meta-oe/recipes-support/mysql/mariadb/install_db.service
new file mode 100644
index 0000000000..c8369f569b
--- /dev/null
+++ b/meta-oe/recipes-support/mysql/mariadb/install_db.service
@@ -0,0 +1,17 @@
+#
+# Simple install MySQL database service file
+# It shoulb be done before mysqld.service
+
+[Unit]
+Description=Install MySQL Community Server Database
+After=network.target
+After=syslog.target
+Before=mysqld.service
+
+[Install]
+WantedBy=multi-user.target
+
+[Service]
+Type=oneshot
+ExecStart=@BINDIR@/mysql-systemd-start pre
+
diff --git a/meta-oe/recipes-support/mysql/mariadb/my.cnf b/meta-oe/recipes-support/mysql/mariadb/my.cnf
index 28d389922b..dc4c172e54 100644
--- a/meta-oe/recipes-support/mysql/mariadb/my.cnf
+++ b/meta-oe/recipes-support/mysql/mariadb/my.cnf
@@ -4,7 +4,6 @@ port = 3306
socket = /var/lib/mysql/mysql.sock
[mysqld_safe]
-err-log = /var/log/mysql.err
[mysqld]
user = mysql
diff --git a/meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start b/meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start
new file mode 100644
index 0000000000..189c02021d
--- /dev/null
+++ b/meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start
@@ -0,0 +1,66 @@
+#! /bin/sh
+#
+# 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
+#
+
+get_option () {
+ local section=$1
+ local option=$2
+ local default=$3
+ ret=$(/usr/bin/my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2-)
+ [ -z $ret ] && ret=$default
+ echo $ret
+}
+
+install_db () {
+ # Note: something different than datadir=/var/lib/mysql requires SELinux policy changes (in enforcing mode)
+ datadir=$(get_option mysqld datadir "/var/lib/mysql")
+
+ # 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
+ datadir=$(get_option mysqld datadir "/var/lib/mysql")
+ socket=$(get_option mysqld socket "$datadir/mysql.sock")
+ case $socket in
+ /*) adminsocket="$socket" ;;
+ *) adminsocket="$datadir/$socket" ;;
+ esac
+
+ while /bin/true ; do
+ sleep 1
+ mysqladmin --no-defaults --socket="$adminsocket" --user=UNKNOWN_MYSQL_USER ping >/dev/null 2>&1 && break
+ done
+ exit 0
+}
+
+# main
+case $1 in
+ "pre") install_db ;;
+ "post") pinger ;;
+esac
+
+exit 0
+
diff --git a/meta-oe/recipes-support/mysql/mariadb/mysqld.service b/meta-oe/recipes-support/mysql/mariadb/mysqld.service
index 757d0386c3..d88361703d 100644
--- a/meta-oe/recipes-support/mysql/mariadb/mysqld.service
+++ b/meta-oe/recipes-support/mysql/mariadb/mysqld.service
@@ -8,7 +8,16 @@ PIDFile=/var/lib/mysql/mysqld.pid
Type=simple
User=mysql
Group=mysql
+
+# Execute post scripts as root
+PermissionsStartOnly=true
+
+# Start main service
ExecStart=@BINDIR@/mysqld_safe --basedir=@PREFIX@
+
+# Don't signal startup success before a ping works
+ExecStartPost=@BINDIR@/mysql-systemd-start post
+
TimeoutSec=300
PrivateTmp=true