summaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start
diff options
context:
space:
mode:
authorHongxu Jia <hongxu.jia@windriver.com>2015-11-25 10:04:31 +0800
committerArmin Kuster <akuster808@gmail.com>2015-12-20 14:26:37 -0800
commit956089410906c7efdbebdee68c4b5daaeaebbaaf (patch)
tree019aabf288ded65d56d8865d9120de700e563017 /meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start
parent9af04860be7697694ecd1cfb0a948a186ac86727 (diff)
downloadmeta-openembedded-956089410906c7efdbebdee68c4b5daaeaebbaaf.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> Signed-off-by: Armin Kuster <akuster808@gmail.com>
Diffstat (limited to 'meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start')
-rw-r--r--meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start66
1 files changed, 66 insertions, 0 deletions
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 000000000..189c02021
--- /dev/null
+++ b/meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start
@@ -0,0 +1,66 @@
1#! /bin/sh
2#
3# Needed argument: pre | post
4#
5# pre mode : try to run mysql_install_db and fix perms and SELinux contexts
6# post mode : ping server until answer is received
7#
8
9get_option () {
10 local section=$1
11 local option=$2
12 local default=$3
13 ret=$(/usr/bin/my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2-)
14 [ -z $ret ] && ret=$default
15 echo $ret
16}
17
18install_db () {
19 # Note: something different than datadir=/var/lib/mysql requires SELinux policy changes (in enforcing mode)
20 datadir=$(get_option mysqld datadir "/var/lib/mysql")
21
22 # Restore log, dir, perms and SELinux contexts
23 [ -d "$datadir" ] || install -d -m 0755 -omysql -gmysql "$datadir" || exit 1
24 log=/var/log/mysqld.log
25 [ -e $log ] || touch $log
26 chmod 0640 $log
27 chown mysql:mysql $log || exit 1
28 if [ -x /usr/sbin/restorecon ]; then
29 /usr/sbin/restorecon "$datadir"
30 /usr/sbin/restorecon $log
31 fi
32
33 # If special mysql dir is in place, skip db install
34 [ -d "$datadir/mysql" ] && exit 0
35
36 # Create initial db
37 /usr/bin/mysql_install_db --rpm --datadir="$datadir" --user=mysql
38 exit 0
39}
40
41pinger () {
42 # Wait for ping to answer to signal startup completed,
43 # might take a while in case of e.g. crash recovery
44 # MySQL systemd service will timeout script if no answer
45 datadir=$(get_option mysqld datadir "/var/lib/mysql")
46 socket=$(get_option mysqld socket "$datadir/mysql.sock")
47 case $socket in
48 /*) adminsocket="$socket" ;;
49 *) adminsocket="$datadir/$socket" ;;
50 esac
51
52 while /bin/true ; do
53 sleep 1
54 mysqladmin --no-defaults --socket="$adminsocket" --user=UNKNOWN_MYSQL_USER ping >/dev/null 2>&1 && break
55 done
56 exit 0
57}
58
59# main
60case $1 in
61 "pre") install_db ;;
62 "post") pinger ;;
63esac
64
65exit 0
66