* [meta-oe][PATCH] mariadb.inc: fix mysqld hung at first init time based on systemd
@ 2015-11-21 3:47 Hongxu Jia
2015-11-21 8:05 ` Hongxu Jia
0 siblings, 1 reply; 7+ messages in thread
From: Hongxu Jia @ 2015-11-21 3:47 UTC (permalink / raw)
To: openembedded-devel
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 mysqld.service and mysql-systemd-start from ${S}/packaging/rpm-oel/.
For review convenience, we add them as files.
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 newly mysqld.service add ExecStartPre and ExecStartPost than previous:
ExecStartPre invoke 'mysql-systemd-start pre' to install db before mysqld
start at first runtime; ExecStartPost invoke 'mysql-systemd-start post' to
wait for mysqld service startup completed.
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
...
Use "?=" rather than "=" to assign SYSTEMD_AUTO_ENABLE_${PN}-server, so we could
override it in local.conf
Add 'mysql-systemd-start pre' to sysvinit startup script, so mysqld could work
on the system based on sysvinit.
Tweak my.cnf to remove obsolete/incorrect parameter.
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
meta-oe/recipes-support/mysql/mariadb.inc | 22 ++-----
.../mariadb/install-db-before-start-mysqld.patch | 29 +++++++++
meta-oe/recipes-support/mysql/mariadb/my.cnf | 1 -
.../mysql/mariadb/mysql-systemd-start | 68 ++++++++++++++++++++++
.../recipes-support/mysql/mariadb/mysqld.service | 50 +++++++++++++---
5 files changed, 144 insertions(+), 26 deletions(-)
create mode 100644 meta-oe/recipes-support/mysql/mariadb/install-db-before-start-mysqld.patch
create mode 100644 meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start
diff --git a/meta-oe/recipes-support/mysql/mariadb.inc b/meta-oe/recipes-support/mysql/mariadb.inc
index 42a4eda..3a29f58 100644
--- a/meta-oe/recipes-support/mysql/mariadb.inc
+++ b/meta-oe/recipes-support/mysql/mariadb.inc
@@ -10,8 +10,10 @@ SRC_URI = "http://archive.mariadb.org/mariadb-${PV}/source/mariadb-${PV}.tar.gz
file://fix-mysqlclient-r-version.patch \
file://my.cnf \
file://mysqld.service \
+ file://mysql-systemd-start \
file://configure.cmake-fix-valgrind.patch \
file://fix-a-building-failure.patch \
+ file://install-db-before-start-mysqld.patch \
"
SRC_URI[md5sum] = "92f682b00eb137af01e59ea93f7e31f7"
@@ -33,7 +35,7 @@ GROUPADD_PARAM_${PN}-server = "--system mysql"
SYSTEMD_PACKAGES = "${PN}-server"
SYSTEMD_SERVICE_${PN}-server = "mysqld.service"
-SYSTEMD_AUTO_ENABLE_${PN}-server = "disable"
+SYSTEMD_AUTO_ENABLE_${PN}-server ?= "disable"
EXTRA_OEMAKE = "'GEN_LEX_HASH=${STAGING_BINDIR_NATIVE}/gen_lex_hash'"
@@ -125,22 +127,9 @@ do_install() {
echo "f /var/log/mysqld.err 0640 mysql mysql -" \
> ${D}${sysconfdir}/tmpfiles.d/99-mysqld.conf
fi
-}
-
-pkg_postinst_${PN}-server () {
- if [ "x$D" != "x" ]; then
- exit 1
- fi
-
- #Install the database
- test -d /usr/bin || mkdir -p /usr/bin
- test -e /usr/bin/hostname || ln -s /bin/hostname /usr/bin/hostname
- mkdir /var/lib/mysql
- chown mysql.mysql /var/lib/mysql
-
- mysql_install_db --basedir=${prefix} --user=mysql
+ install -d ${D}${bindir}
+ install -m 755 ${WORKDIR}/mysql-systemd-start ${D}${bindir}
- [ -x /sbin/restorecon ] && /sbin/restorecon -RF /var/lib/mysql
}
PACKAGES = "${PN}-dbg ${PN} \
@@ -236,6 +225,7 @@ FILES_${PN}-server = "\
${bindir}/mysql_install_db \
${bindir}/mysql_secure_installation \
${bindir}/mysql_setpermission \
+ ${bindir}/mysql-systemd-start \
${bindir}/mysql_tzinfo_to_sql \
${bindir}/mysql_upgrade \
${bindir}/mysql_plugin \
diff --git a/meta-oe/recipes-support/mysql/mariadb/install-db-before-start-mysqld.patch b/meta-oe/recipes-support/mysql/mariadb/install-db-before-start-mysqld.patch
new file mode 100644
index 0000000..b11b9c7
--- /dev/null
+++ b/meta-oe/recipes-support/mysql/mariadb/install-db-before-start-mysqld.patch
@@ -0,0 +1,29 @@
+From 5d8495e81a748350c89849c1a385e57ee31836e2 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Fri, 20 Nov 2015 09:52:29 -0500
+Subject: [PATCH] support-files/mysql.server.sh: install db at first runtime
+
+Install db at first runtime before mysqld start, rather than
+do that at postinst, which keep sync with systemd.
+
+Upstream status: pending
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ support-files/mysql.server.sh | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/support-files/mysql.server.sh b/support-files/mysql.server.sh
+index e23b837..e5926f5 100644
+--- a/support-files/mysql.server.sh
++++ b/support-files/mysql.server.sh
+@@ -304,6 +304,7 @@ case "$mode" in
+ cd $basedir
+
+ echo $echo_n "Starting MySQL"
++ $bindir/mysql-systemd-start pre
+ if test -x $bindir/mysqld_safe
+ then
+ # Give extra arguments to mysqld with the my.cnf file. This script
+--
+1.9.1
+
diff --git a/meta-oe/recipes-support/mysql/mariadb/my.cnf b/meta-oe/recipes-support/mysql/mariadb/my.cnf
index 28d3899..dc4c172 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 0000000..8e7006b
--- /dev/null
+++ b/meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start
@@ -0,0 +1,68 @@
+#! /bin/sh
+#
+# 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
+#
+
+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 757d038..1bcb0ee 100644
--- a/meta-oe/recipes-support/mysql/mariadb/mysqld.service
+++ b/meta-oe/recipes-support/mysql/mariadb/mysqld.service
@@ -1,16 +1,48 @@
+#
+# Simple MySQL systemd service file
+#
+# systemd supports lots of fancy features, look here (and linked docs) for a full list:
+# http://www.freedesktop.org/software/systemd/man/systemd.exec.html
+#
+# Note: this file ( /usr/lib/systemd/system/mysql.service )
+# will be overwritten on package upgrade, please copy the file to
+#
+# /etc/systemd/system/mysql.service
+#
+# to make needed changes.
+#
+# systemd-delta can be used to check differences between the two mysql.service files.
+#
+
[Unit]
-Description=MariaDB database server
-After=syslog.target
+Description=MySQL Community Server
After=network.target
+After=syslog.target
+
+[Install]
+WantedBy=multi-user.target
+Alias=mysql.service
[Service]
-PIDFile=/var/lib/mysql/mysqld.pid
-Type=simple
User=mysql
Group=mysql
-ExecStart=@BINDIR@/mysqld_safe --basedir=@PREFIX@
-TimeoutSec=300
-PrivateTmp=true
-[Install]
-WantedBy=multi-user.target
+# Execute pre and post scripts as root
+PermissionsStartOnly=true
+
+# Needed to create system tables etc.
+ExecStartPre=@BINDIR@/mysql-systemd-start pre
+
+# Start main service
+ExecStart=@BINDIR@/mysqld_safe
+
+# Don't signal startup success before a ping works
+ExecStartPost=@BINDIR@/mysql-systemd-start post
+
+# Give up if ping don't get an answer
+TimeoutSec=600
+
+Restart=always
+PrivateTmp=false
+
+
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [meta-oe][PATCH] mariadb.inc: fix mysqld hung at first init time based on systemd
2015-11-21 3:47 [meta-oe][PATCH] mariadb.inc: fix mysqld hung at first init time based on systemd Hongxu Jia
@ 2015-11-21 8:05 ` Hongxu Jia
2015-11-21 8:10 ` [meta-oe][PATCH V2] " Hongxu Jia
2015-11-21 8:13 ` Hongxu Jia
0 siblings, 2 replies; 7+ messages in thread
From: Hongxu Jia @ 2015-11-21 8:05 UTC (permalink / raw)
To: openembedded-devel
On 11/21/2015 11:47 AM, Hongxu Jia wrote:
> +Install db at first runtime before mysqld start, rather than
> +do that at postinst, which keep sync with systemd.
> +
> +Upstream status: pending
s/Upstream status/Upstream-Status/
V2 incoming
//Hongxu
> +Signed-off-by: Hongxu Jia<hongxu.jia@windriver.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [meta-oe][PATCH V2] mariadb.inc: fix mysqld hung at first init time based on systemd
2015-11-21 8:05 ` Hongxu Jia
@ 2015-11-21 8:10 ` Hongxu Jia
2015-11-21 8:12 ` Hongxu Jia
2015-11-21 8:13 ` Hongxu Jia
1 sibling, 1 reply; 7+ messages in thread
From: Hongxu Jia @ 2015-11-21 8:10 UTC (permalink / raw)
To: openembedded-core, ross.burton
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 mysqld.service and mysql-systemd-start from ${S}/packaging/rpm-oel/.
For review convenience, we add them as files.
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 newly mysqld.service add ExecStartPre and ExecStartPost than previous:
ExecStartPre invoke 'mysql-systemd-start pre' to install db before mysqld
start at first runtime; ExecStartPost invoke 'mysql-systemd-start post' to
wait for mysqld service startup completed.
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
...
Use "?=" rather than "=" to assign SYSTEMD_AUTO_ENABLE_${PN}-server, so we could
override it in local.conf
Add 'mysql-systemd-start pre' to sysvinit startup script, so mysqld could work
on the system based on sysvinit.
Tweak my.cnf to remove obsolete/incorrect parameter.
Issue: LIN8-1397
Issue: LIN8-1687
(LOCAL REV: NOT UPSTREAM) -- sent to oe on 20151121
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
meta-oe/recipes-support/mysql/mariadb.inc | 22 ++-----
.../mariadb/install-db-before-start-mysqld.patch | 32 ++++++++++
meta-oe/recipes-support/mysql/mariadb/my.cnf | 1 -
.../mysql/mariadb/mysql-systemd-start | 68 ++++++++++++++++++++++
.../recipes-support/mysql/mariadb/mysqld.service | 50 +++++++++++++---
5 files changed, 147 insertions(+), 26 deletions(-)
create mode 100644 meta-oe/recipes-support/mysql/mariadb/install-db-before-start-mysqld.patch
create mode 100644 meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start
diff --git a/meta-oe/recipes-support/mysql/mariadb.inc b/meta-oe/recipes-support/mysql/mariadb.inc
index 42a4eda..3a29f58 100644
--- a/meta-oe/recipes-support/mysql/mariadb.inc
+++ b/meta-oe/recipes-support/mysql/mariadb.inc
@@ -10,8 +10,10 @@ SRC_URI = "http://archive.mariadb.org/mariadb-${PV}/source/mariadb-${PV}.tar.gz
file://fix-mysqlclient-r-version.patch \
file://my.cnf \
file://mysqld.service \
+ file://mysql-systemd-start \
file://configure.cmake-fix-valgrind.patch \
file://fix-a-building-failure.patch \
+ file://install-db-before-start-mysqld.patch \
"
SRC_URI[md5sum] = "92f682b00eb137af01e59ea93f7e31f7"
@@ -33,7 +35,7 @@ GROUPADD_PARAM_${PN}-server = "--system mysql"
SYSTEMD_PACKAGES = "${PN}-server"
SYSTEMD_SERVICE_${PN}-server = "mysqld.service"
-SYSTEMD_AUTO_ENABLE_${PN}-server = "disable"
+SYSTEMD_AUTO_ENABLE_${PN}-server ?= "disable"
EXTRA_OEMAKE = "'GEN_LEX_HASH=${STAGING_BINDIR_NATIVE}/gen_lex_hash'"
@@ -125,22 +127,9 @@ do_install() {
echo "f /var/log/mysqld.err 0640 mysql mysql -" \
> ${D}${sysconfdir}/tmpfiles.d/99-mysqld.conf
fi
-}
-
-pkg_postinst_${PN}-server () {
- if [ "x$D" != "x" ]; then
- exit 1
- fi
-
- #Install the database
- test -d /usr/bin || mkdir -p /usr/bin
- test -e /usr/bin/hostname || ln -s /bin/hostname /usr/bin/hostname
- mkdir /var/lib/mysql
- chown mysql.mysql /var/lib/mysql
-
- mysql_install_db --basedir=${prefix} --user=mysql
+ install -d ${D}${bindir}
+ install -m 755 ${WORKDIR}/mysql-systemd-start ${D}${bindir}
- [ -x /sbin/restorecon ] && /sbin/restorecon -RF /var/lib/mysql
}
PACKAGES = "${PN}-dbg ${PN} \
@@ -236,6 +225,7 @@ FILES_${PN}-server = "\
${bindir}/mysql_install_db \
${bindir}/mysql_secure_installation \
${bindir}/mysql_setpermission \
+ ${bindir}/mysql-systemd-start \
${bindir}/mysql_tzinfo_to_sql \
${bindir}/mysql_upgrade \
${bindir}/mysql_plugin \
diff --git a/meta-oe/recipes-support/mysql/mariadb/install-db-before-start-mysqld.patch b/meta-oe/recipes-support/mysql/mariadb/install-db-before-start-mysqld.patch
new file mode 100644
index 0000000..724618f
--- /dev/null
+++ b/meta-oe/recipes-support/mysql/mariadb/install-db-before-start-mysqld.patch
@@ -0,0 +1,32 @@
+From 5d8495e81a748350c89849c1a385e57ee31836e2 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Fri, 20 Nov 2015 09:52:29 -0500
+Subject: [PATCH] support-files/mysql.server.sh: install db at first runtime
+
+We remove postinst in mariadb-server, and still need to install db
+at first runtime before mysqld start. So invoke 'mysql-systemd-start
+pre' before mysqld startup on sysvinit system.
+
+The first runtime means it will skip install if a db already existed.
+
+Upstream-Status: inappropriate [meta-oe specific]
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ support-files/mysql.server.sh | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/support-files/mysql.server.sh b/support-files/mysql.server.sh
+index e23b837..e5926f5 100644
+--- a/support-files/mysql.server.sh
++++ b/support-files/mysql.server.sh
+@@ -304,6 +304,7 @@ case "$mode" in
+ cd $basedir
+
+ echo $echo_n "Starting MySQL"
++ $bindir/mysql-systemd-start pre
+ if test -x $bindir/mysqld_safe
+ then
+ # Give extra arguments to mysqld with the my.cnf file. This script
+--
+1.9.1
+
diff --git a/meta-oe/recipes-support/mysql/mariadb/my.cnf b/meta-oe/recipes-support/mysql/mariadb/my.cnf
index 28d3899..dc4c172 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 0000000..8e7006b
--- /dev/null
+++ b/meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start
@@ -0,0 +1,68 @@
+#! /bin/sh
+#
+# 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
+#
+
+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 757d038..1bcb0ee 100644
--- a/meta-oe/recipes-support/mysql/mariadb/mysqld.service
+++ b/meta-oe/recipes-support/mysql/mariadb/mysqld.service
@@ -1,16 +1,48 @@
+#
+# Simple MySQL systemd service file
+#
+# systemd supports lots of fancy features, look here (and linked docs) for a full list:
+# http://www.freedesktop.org/software/systemd/man/systemd.exec.html
+#
+# Note: this file ( /usr/lib/systemd/system/mysql.service )
+# will be overwritten on package upgrade, please copy the file to
+#
+# /etc/systemd/system/mysql.service
+#
+# to make needed changes.
+#
+# systemd-delta can be used to check differences between the two mysql.service files.
+#
+
[Unit]
-Description=MariaDB database server
-After=syslog.target
+Description=MySQL Community Server
After=network.target
+After=syslog.target
+
+[Install]
+WantedBy=multi-user.target
+Alias=mysql.service
[Service]
-PIDFile=/var/lib/mysql/mysqld.pid
-Type=simple
User=mysql
Group=mysql
-ExecStart=@BINDIR@/mysqld_safe --basedir=@PREFIX@
-TimeoutSec=300
-PrivateTmp=true
-[Install]
-WantedBy=multi-user.target
+# Execute pre and post scripts as root
+PermissionsStartOnly=true
+
+# Needed to create system tables etc.
+ExecStartPre=@BINDIR@/mysql-systemd-start pre
+
+# Start main service
+ExecStart=@BINDIR@/mysqld_safe
+
+# Don't signal startup success before a ping works
+ExecStartPost=@BINDIR@/mysql-systemd-start post
+
+# Give up if ping don't get an answer
+TimeoutSec=600
+
+Restart=always
+PrivateTmp=false
+
+
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [meta-oe][PATCH V2] mariadb.inc: fix mysqld hung at first init time based on systemd
2015-11-21 8:10 ` [meta-oe][PATCH V2] " Hongxu Jia
@ 2015-11-21 8:12 ` Hongxu Jia
0 siblings, 0 replies; 7+ messages in thread
From: Hongxu Jia @ 2015-11-21 8:12 UTC (permalink / raw)
To: openembedded-core, ross.burton
Sorry for mistaking the mailing list, please drop it.
//Hongxu
On 11/21/2015 04:10 PM, Hongxu Jia wrote:
> 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 mysqld.service and mysql-systemd-start from ${S}/packaging/rpm-oel/.
> For review convenience, we add them as files.
>
> 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 newly mysqld.service add ExecStartPre and ExecStartPost than previous:
> ExecStartPre invoke 'mysql-systemd-start pre' to install db before mysqld
> start at first runtime; ExecStartPost invoke 'mysql-systemd-start post' to
> wait for mysqld service startup completed.
>
> 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
> ...
>
> Use "?=" rather than "=" to assign SYSTEMD_AUTO_ENABLE_${PN}-server, so we could
> override it in local.conf
>
> Add 'mysql-systemd-start pre' to sysvinit startup script, so mysqld could work
> on the system based on sysvinit.
>
> Tweak my.cnf to remove obsolete/incorrect parameter.
>
> Issue: LIN8-1397
> Issue: LIN8-1687
> (LOCAL REV: NOT UPSTREAM) -- sent to oe on 20151121
>
> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> ---
> meta-oe/recipes-support/mysql/mariadb.inc | 22 ++-----
> .../mariadb/install-db-before-start-mysqld.patch | 32 ++++++++++
> meta-oe/recipes-support/mysql/mariadb/my.cnf | 1 -
> .../mysql/mariadb/mysql-systemd-start | 68 ++++++++++++++++++++++
> .../recipes-support/mysql/mariadb/mysqld.service | 50 +++++++++++++---
> 5 files changed, 147 insertions(+), 26 deletions(-)
> create mode 100644 meta-oe/recipes-support/mysql/mariadb/install-db-before-start-mysqld.patch
> create mode 100644 meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start
>
> diff --git a/meta-oe/recipes-support/mysql/mariadb.inc b/meta-oe/recipes-support/mysql/mariadb.inc
> index 42a4eda..3a29f58 100644
> --- a/meta-oe/recipes-support/mysql/mariadb.inc
> +++ b/meta-oe/recipes-support/mysql/mariadb.inc
> @@ -10,8 +10,10 @@ SRC_URI = "http://archive.mariadb.org/mariadb-${PV}/source/mariadb-${PV}.tar.gz
> file://fix-mysqlclient-r-version.patch \
> file://my.cnf \
> file://mysqld.service \
> + file://mysql-systemd-start \
> file://configure.cmake-fix-valgrind.patch \
> file://fix-a-building-failure.patch \
> + file://install-db-before-start-mysqld.patch \
> "
>
> SRC_URI[md5sum] = "92f682b00eb137af01e59ea93f7e31f7"
> @@ -33,7 +35,7 @@ GROUPADD_PARAM_${PN}-server = "--system mysql"
>
> SYSTEMD_PACKAGES = "${PN}-server"
> SYSTEMD_SERVICE_${PN}-server = "mysqld.service"
> -SYSTEMD_AUTO_ENABLE_${PN}-server = "disable"
> +SYSTEMD_AUTO_ENABLE_${PN}-server ?= "disable"
>
> EXTRA_OEMAKE = "'GEN_LEX_HASH=${STAGING_BINDIR_NATIVE}/gen_lex_hash'"
>
> @@ -125,22 +127,9 @@ do_install() {
> echo "f /var/log/mysqld.err 0640 mysql mysql -" \
> > ${D}${sysconfdir}/tmpfiles.d/99-mysqld.conf
> fi
> -}
> -
> -pkg_postinst_${PN}-server () {
> - if [ "x$D" != "x" ]; then
> - exit 1
> - fi
> -
> - #Install the database
> - test -d /usr/bin || mkdir -p /usr/bin
> - test -e /usr/bin/hostname || ln -s /bin/hostname /usr/bin/hostname
> - mkdir /var/lib/mysql
> - chown mysql.mysql /var/lib/mysql
> -
> - mysql_install_db --basedir=${prefix} --user=mysql
> + install -d ${D}${bindir}
> + install -m 755 ${WORKDIR}/mysql-systemd-start ${D}${bindir}
>
> - [ -x /sbin/restorecon ] && /sbin/restorecon -RF /var/lib/mysql
> }
>
> PACKAGES = "${PN}-dbg ${PN} \
> @@ -236,6 +225,7 @@ FILES_${PN}-server = "\
> ${bindir}/mysql_install_db \
> ${bindir}/mysql_secure_installation \
> ${bindir}/mysql_setpermission \
> + ${bindir}/mysql-systemd-start \
> ${bindir}/mysql_tzinfo_to_sql \
> ${bindir}/mysql_upgrade \
> ${bindir}/mysql_plugin \
> diff --git a/meta-oe/recipes-support/mysql/mariadb/install-db-before-start-mysqld.patch b/meta-oe/recipes-support/mysql/mariadb/install-db-before-start-mysqld.patch
> new file mode 100644
> index 0000000..724618f
> --- /dev/null
> +++ b/meta-oe/recipes-support/mysql/mariadb/install-db-before-start-mysqld.patch
> @@ -0,0 +1,32 @@
> +From 5d8495e81a748350c89849c1a385e57ee31836e2 Mon Sep 17 00:00:00 2001
> +From: Hongxu Jia <hongxu.jia@windriver.com>
> +Date: Fri, 20 Nov 2015 09:52:29 -0500
> +Subject: [PATCH] support-files/mysql.server.sh: install db at first runtime
> +
> +We remove postinst in mariadb-server, and still need to install db
> +at first runtime before mysqld start. So invoke 'mysql-systemd-start
> +pre' before mysqld startup on sysvinit system.
> +
> +The first runtime means it will skip install if a db already existed.
> +
> +Upstream-Status: inappropriate [meta-oe specific]
> +Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> +---
> + support-files/mysql.server.sh | 1 +
> + 1 file changed, 1 insertion(+)
> +
> +diff --git a/support-files/mysql.server.sh b/support-files/mysql.server.sh
> +index e23b837..e5926f5 100644
> +--- a/support-files/mysql.server.sh
> ++++ b/support-files/mysql.server.sh
> +@@ -304,6 +304,7 @@ case "$mode" in
> + cd $basedir
> +
> + echo $echo_n "Starting MySQL"
> ++ $bindir/mysql-systemd-start pre
> + if test -x $bindir/mysqld_safe
> + then
> + # Give extra arguments to mysqld with the my.cnf file. This script
> +--
> +1.9.1
> +
> diff --git a/meta-oe/recipes-support/mysql/mariadb/my.cnf b/meta-oe/recipes-support/mysql/mariadb/my.cnf
> index 28d3899..dc4c172 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 0000000..8e7006b
> --- /dev/null
> +++ b/meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start
> @@ -0,0 +1,68 @@
> +#! /bin/sh
> +#
> +# 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
> +#
> +
> +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 757d038..1bcb0ee 100644
> --- a/meta-oe/recipes-support/mysql/mariadb/mysqld.service
> +++ b/meta-oe/recipes-support/mysql/mariadb/mysqld.service
> @@ -1,16 +1,48 @@
> +#
> +# Simple MySQL systemd service file
> +#
> +# systemd supports lots of fancy features, look here (and linked docs) for a full list:
> +# http://www.freedesktop.org/software/systemd/man/systemd.exec.html
> +#
> +# Note: this file ( /usr/lib/systemd/system/mysql.service )
> +# will be overwritten on package upgrade, please copy the file to
> +#
> +# /etc/systemd/system/mysql.service
> +#
> +# to make needed changes.
> +#
> +# systemd-delta can be used to check differences between the two mysql.service files.
> +#
> +
> [Unit]
> -Description=MariaDB database server
> -After=syslog.target
> +Description=MySQL Community Server
> After=network.target
> +After=syslog.target
> +
> +[Install]
> +WantedBy=multi-user.target
> +Alias=mysql.service
>
> [Service]
> -PIDFile=/var/lib/mysql/mysqld.pid
> -Type=simple
> User=mysql
> Group=mysql
> -ExecStart=@BINDIR@/mysqld_safe --basedir=@PREFIX@
> -TimeoutSec=300
> -PrivateTmp=true
>
> -[Install]
> -WantedBy=multi-user.target
> +# Execute pre and post scripts as root
> +PermissionsStartOnly=true
> +
> +# Needed to create system tables etc.
> +ExecStartPre=@BINDIR@/mysql-systemd-start pre
> +
> +# Start main service
> +ExecStart=@BINDIR@/mysqld_safe
> +
> +# Don't signal startup success before a ping works
> +ExecStartPost=@BINDIR@/mysql-systemd-start post
> +
> +# Give up if ping don't get an answer
> +TimeoutSec=600
> +
> +Restart=always
> +PrivateTmp=false
> +
> +
^ permalink raw reply [flat|nested] 7+ messages in thread
* [meta-oe][PATCH V2] mariadb.inc: fix mysqld hung at first init time based on systemd
2015-11-21 8:05 ` Hongxu Jia
2015-11-21 8:10 ` [meta-oe][PATCH V2] " Hongxu Jia
@ 2015-11-21 8:13 ` Hongxu Jia
2015-11-25 2:04 ` [PATCH V3] " Hongxu Jia
1 sibling, 1 reply; 7+ messages in thread
From: Hongxu Jia @ 2015-11-21 8:13 UTC (permalink / raw)
To: openembedded-devel
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 mysqld.service and mysql-systemd-start from ${S}/packaging/rpm-oel/.
For review convenience, we add them as files.
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 newly mysqld.service add ExecStartPre and ExecStartPost than previous:
ExecStartPre invoke 'mysql-systemd-start pre' to install db before mysqld
start at first runtime; ExecStartPost invoke 'mysql-systemd-start post' to
wait for mysqld service startup completed.
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
...
Use "?=" rather than "=" to assign SYSTEMD_AUTO_ENABLE_${PN}-server, so we could
override it in local.conf
Add 'mysql-systemd-start pre' to sysvinit startup script, so mysqld could work
on the system based on sysvinit.
Tweak my.cnf to remove obsolete/incorrect parameter.
Issue: LIN8-1397
Issue: LIN8-1687
(LOCAL REV: NOT UPSTREAM) -- sent to oe on 20151121
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
meta-oe/recipes-support/mysql/mariadb.inc | 22 ++-----
.../mariadb/install-db-before-start-mysqld.patch | 32 ++++++++++
meta-oe/recipes-support/mysql/mariadb/my.cnf | 1 -
.../mysql/mariadb/mysql-systemd-start | 68 ++++++++++++++++++++++
.../recipes-support/mysql/mariadb/mysqld.service | 50 +++++++++++++---
5 files changed, 147 insertions(+), 26 deletions(-)
create mode 100644 meta-oe/recipes-support/mysql/mariadb/install-db-before-start-mysqld.patch
create mode 100644 meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start
diff --git a/meta-oe/recipes-support/mysql/mariadb.inc b/meta-oe/recipes-support/mysql/mariadb.inc
index 42a4eda..3a29f58 100644
--- a/meta-oe/recipes-support/mysql/mariadb.inc
+++ b/meta-oe/recipes-support/mysql/mariadb.inc
@@ -10,8 +10,10 @@ SRC_URI = "http://archive.mariadb.org/mariadb-${PV}/source/mariadb-${PV}.tar.gz
file://fix-mysqlclient-r-version.patch \
file://my.cnf \
file://mysqld.service \
+ file://mysql-systemd-start \
file://configure.cmake-fix-valgrind.patch \
file://fix-a-building-failure.patch \
+ file://install-db-before-start-mysqld.patch \
"
SRC_URI[md5sum] = "92f682b00eb137af01e59ea93f7e31f7"
@@ -33,7 +35,7 @@ GROUPADD_PARAM_${PN}-server = "--system mysql"
SYSTEMD_PACKAGES = "${PN}-server"
SYSTEMD_SERVICE_${PN}-server = "mysqld.service"
-SYSTEMD_AUTO_ENABLE_${PN}-server = "disable"
+SYSTEMD_AUTO_ENABLE_${PN}-server ?= "disable"
EXTRA_OEMAKE = "'GEN_LEX_HASH=${STAGING_BINDIR_NATIVE}/gen_lex_hash'"
@@ -125,22 +127,9 @@ do_install() {
echo "f /var/log/mysqld.err 0640 mysql mysql -" \
> ${D}${sysconfdir}/tmpfiles.d/99-mysqld.conf
fi
-}
-
-pkg_postinst_${PN}-server () {
- if [ "x$D" != "x" ]; then
- exit 1
- fi
-
- #Install the database
- test -d /usr/bin || mkdir -p /usr/bin
- test -e /usr/bin/hostname || ln -s /bin/hostname /usr/bin/hostname
- mkdir /var/lib/mysql
- chown mysql.mysql /var/lib/mysql
-
- mysql_install_db --basedir=${prefix} --user=mysql
+ install -d ${D}${bindir}
+ install -m 755 ${WORKDIR}/mysql-systemd-start ${D}${bindir}
- [ -x /sbin/restorecon ] && /sbin/restorecon -RF /var/lib/mysql
}
PACKAGES = "${PN}-dbg ${PN} \
@@ -236,6 +225,7 @@ FILES_${PN}-server = "\
${bindir}/mysql_install_db \
${bindir}/mysql_secure_installation \
${bindir}/mysql_setpermission \
+ ${bindir}/mysql-systemd-start \
${bindir}/mysql_tzinfo_to_sql \
${bindir}/mysql_upgrade \
${bindir}/mysql_plugin \
diff --git a/meta-oe/recipes-support/mysql/mariadb/install-db-before-start-mysqld.patch b/meta-oe/recipes-support/mysql/mariadb/install-db-before-start-mysqld.patch
new file mode 100644
index 0000000..724618f
--- /dev/null
+++ b/meta-oe/recipes-support/mysql/mariadb/install-db-before-start-mysqld.patch
@@ -0,0 +1,32 @@
+From 5d8495e81a748350c89849c1a385e57ee31836e2 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Fri, 20 Nov 2015 09:52:29 -0500
+Subject: [PATCH] support-files/mysql.server.sh: install db at first runtime
+
+We remove postinst in mariadb-server, and still need to install db
+at first runtime before mysqld start. So invoke 'mysql-systemd-start
+pre' before mysqld startup on sysvinit system.
+
+The first runtime means it will skip install if a db already existed.
+
+Upstream-Status: inappropriate [meta-oe specific]
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ support-files/mysql.server.sh | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/support-files/mysql.server.sh b/support-files/mysql.server.sh
+index e23b837..e5926f5 100644
+--- a/support-files/mysql.server.sh
++++ b/support-files/mysql.server.sh
+@@ -304,6 +304,7 @@ case "$mode" in
+ cd $basedir
+
+ echo $echo_n "Starting MySQL"
++ $bindir/mysql-systemd-start pre
+ if test -x $bindir/mysqld_safe
+ then
+ # Give extra arguments to mysqld with the my.cnf file. This script
+--
+1.9.1
+
diff --git a/meta-oe/recipes-support/mysql/mariadb/my.cnf b/meta-oe/recipes-support/mysql/mariadb/my.cnf
index 28d3899..dc4c172 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 0000000..8e7006b
--- /dev/null
+++ b/meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start
@@ -0,0 +1,68 @@
+#! /bin/sh
+#
+# 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
+#
+
+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 757d038..1bcb0ee 100644
--- a/meta-oe/recipes-support/mysql/mariadb/mysqld.service
+++ b/meta-oe/recipes-support/mysql/mariadb/mysqld.service
@@ -1,16 +1,48 @@
+#
+# Simple MySQL systemd service file
+#
+# systemd supports lots of fancy features, look here (and linked docs) for a full list:
+# http://www.freedesktop.org/software/systemd/man/systemd.exec.html
+#
+# Note: this file ( /usr/lib/systemd/system/mysql.service )
+# will be overwritten on package upgrade, please copy the file to
+#
+# /etc/systemd/system/mysql.service
+#
+# to make needed changes.
+#
+# systemd-delta can be used to check differences between the two mysql.service files.
+#
+
[Unit]
-Description=MariaDB database server
-After=syslog.target
+Description=MySQL Community Server
After=network.target
+After=syslog.target
+
+[Install]
+WantedBy=multi-user.target
+Alias=mysql.service
[Service]
-PIDFile=/var/lib/mysql/mysqld.pid
-Type=simple
User=mysql
Group=mysql
-ExecStart=@BINDIR@/mysqld_safe --basedir=@PREFIX@
-TimeoutSec=300
-PrivateTmp=true
-[Install]
-WantedBy=multi-user.target
+# Execute pre and post scripts as root
+PermissionsStartOnly=true
+
+# Needed to create system tables etc.
+ExecStartPre=@BINDIR@/mysql-systemd-start pre
+
+# Start main service
+ExecStart=@BINDIR@/mysqld_safe
+
+# Don't signal startup success before a ping works
+ExecStartPost=@BINDIR@/mysql-systemd-start post
+
+# Give up if ping don't get an answer
+TimeoutSec=600
+
+Restart=always
+PrivateTmp=false
+
+
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH V3] mariadb.inc: fix mysqld hung at first init time based on systemd
2015-11-21 8:13 ` Hongxu Jia
@ 2015-11-25 2:04 ` Hongxu Jia
2015-11-25 2:08 ` Hongxu Jia
0 siblings, 1 reply; 7+ messages in thread
From: Hongxu Jia @ 2015-11-25 2:04 UTC (permalink / raw)
To: openembedded-devel
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>
---
meta-oe/recipes-support/mysql/mariadb.inc | 51 +++++++++--------
meta-oe/recipes-support/mysql/mariadb/install_db | 13 +++++
.../mysql/mariadb/install_db.service | 17 ++++++
meta-oe/recipes-support/mysql/mariadb/my.cnf | 1 -
.../mysql/mariadb/mysql-systemd-start | 66 ++++++++++++++++++++++
.../recipes-support/mysql/mariadb/mysqld.service | 9 +++
6 files changed, 132 insertions(+), 25 deletions(-)
create mode 100755 meta-oe/recipes-support/mysql/mariadb/install_db
create mode 100644 meta-oe/recipes-support/mysql/mariadb/install_db.service
create mode 100644 meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start
diff --git a/meta-oe/recipes-support/mysql/mariadb.inc b/meta-oe/recipes-support/mysql/mariadb.inc
index 42a4eda..a6826c3 100644
--- a/meta-oe/recipes-support/mysql/mariadb.inc
+++ b/meta-oe/recipes-support/mysql/mariadb.inc
@@ -10,6 +10,9 @@ SRC_URI = "http://archive.mariadb.org/mariadb-${PV}/source/mariadb-${PV}.tar.gz
file://fix-mysqlclient-r-version.patch \
file://my.cnf \
file://mysqld.service \
+ file://install_db.service \
+ file://install_db \
+ file://mysql-systemd-start \
file://configure.cmake-fix-valgrind.patch \
file://fix-a-building-failure.patch \
"
@@ -23,26 +26,35 @@ BINCONFIG_GLOB = "mysql_config"
inherit cmake gettext binconfig update-rc.d useradd systemd
-INITSCRIPT_PACKAGES = "${PN}-server"
-INITSCRIPT_NAME = "mysqld"
-INITSCRIPT_PARAMS = "start 45 5 . stop 45 0 6 1 ."
+INITSCRIPT_PACKAGES = "${PN}-server ${PN}-setupdb"
+INITSCRIPT_NAME_${PN}-server = "mysqld"
+INITSCRIPT_PARAMS_${PN}-server ?= "start 45 5 . stop 45 0 6 1 ."
USERADD_PACKAGES = "${PN}-server"
USERADD_PARAM_${PN}-server = "--system --home-dir /var/mysql -g mysql --shell /bin/false mysql"
GROUPADD_PARAM_${PN}-server = "--system mysql"
-SYSTEMD_PACKAGES = "${PN}-server"
+INITSCRIPT_NAME_${PN}-setupdb = "install_db"
+INITSCRIPT_PARAMS_${PN}-setupdb ?= "defaults 44 44"
+
+SYSTEMD_PACKAGES = "${PN}-server ${PN}-setupdb"
SYSTEMD_SERVICE_${PN}-server = "mysqld.service"
-SYSTEMD_AUTO_ENABLE_${PN}-server = "disable"
+SYSTEMD_AUTO_ENABLE_${PN}-server ?= "disable"
+
+SYSTEMD_SERVICE_${PN}-setupdb = "install_db.service"
+SYSTEMD_AUTO_ENABLE_${PN}-setupdb ?= "enable"
+ALLOW_EMPTY_${PN}-setupdb ?= "1"
+FILES_${PN}-setupdb = "${sysconfdir}/init.d/install_db"
EXTRA_OEMAKE = "'GEN_LEX_HASH=${STAGING_BINDIR_NATIVE}/gen_lex_hash'"
-PACKAGECONFIG ??= "${@bb.utils.contains('DISTRO_FEATURES', 'pam', 'pam', '', d)}"
+PACKAGECONFIG ??= "${@bb.utils.contains('DISTRO_FEATURES', 'pam', 'pam', '', d)} setupdb"
PACKAGECONFIG_class-native = ""
PACKAGECONFIG[pam] = ",-DWITHOUT_AUTH_PAM=TRUE,libpam"
PACKAGECONFIG[valgrind] = "-DWITH_VALGRIND=TRUE,-DWITH_VALGRIND=FALSE,valgrind"
PACKAGECONFIG[libedit] = "-DLIBEDIT_INTERFACE=TRUE,-DLIBEDIT_INTERFACE=FALSE,libedit"
PACKAGECONFIG[krb5] = ", ,krb5"
+PACKAGECONFIG[setupdb] = ", ,,${PN}-setupdb"
# MariaDB doesn't link properly with gold
# https://mariadb.atlassian.net/browse/MDEV-5982
@@ -114,39 +126,29 @@ do_install() {
install -d ${D}/${sysconfdir}/init.d
install -m 0644 ${WORKDIR}/my.cnf ${D}/${sysconfdir}/
+ install -m 0755 ${WORKDIR}/install_db ${D}/${sysconfdir}/init.d/
mv ${D}/${sysconfdir}/init.d/mysql ${D}/${sysconfdir}/init.d/mysqld
install -d ${D}${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/mysqld.service ${D}${systemd_unitdir}/system
- sed -i -e 's,@BINDIR@,${bindir},g' -e 's,@PREFIX@,${prefix},g' ${D}${systemd_unitdir}/system/mysqld.service
+ install -m 0644 ${WORKDIR}/install_db.service ${D}${systemd_unitdir}/system
+ sed -i -e 's,@BINDIR@,${bindir},g' -e 's,@PREFIX@,${prefix},g' ${D}${systemd_unitdir}/system/mysqld.service \
+ ${D}${systemd_unitdir}/system/install_db.service
if ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}; then
install -d ${D}${sysconfdir}/tmpfiles.d
echo "f /var/log/mysqld.err 0640 mysql mysql -" \
> ${D}${sysconfdir}/tmpfiles.d/99-mysqld.conf
fi
-}
-
-pkg_postinst_${PN}-server () {
- if [ "x$D" != "x" ]; then
- exit 1
- fi
-
- #Install the database
- test -d /usr/bin || mkdir -p /usr/bin
- test -e /usr/bin/hostname || ln -s /bin/hostname /usr/bin/hostname
- mkdir /var/lib/mysql
- chown mysql.mysql /var/lib/mysql
-
- mysql_install_db --basedir=${prefix} --user=mysql
+ install -d ${D}${bindir}
+ install -m 755 ${WORKDIR}/mysql-systemd-start ${D}${bindir}
- [ -x /sbin/restorecon ] && /sbin/restorecon -RF /var/lib/mysql
}
PACKAGES = "${PN}-dbg ${PN} \
libmysqlclient-r libmysqlclient-r-dev libmysqlclient-r-staticdev libmysqlclient-r-dbg \
libmysqlclient libmysqlclient-dev libmysqlclient-staticdev libmysqlclient-dbg \
- libmysqld libmysqld-dev ${PN}-client ${PN}-server ${PN}-leftovers"
+ libmysqld libmysqld-dev ${PN}-client ${PN}-server ${PN}-setupdb ${PN}-leftovers"
CONFFILES_${PN}-server += "${sysconfdir}/my.cnf ${sysconfdir}/my.cnf.d/server.cnf"
CONFFILES_${PN}-client += "${sysconfdir}/my.cnf.d/mysql-clients.cnf"
CONFFILES_libmysqlclient += "${sysconfdir}/my.cnf.d/client.cnf"
@@ -236,6 +238,7 @@ FILES_${PN}-server = "\
${bindir}/mysql_install_db \
${bindir}/mysql_secure_installation \
${bindir}/mysql_setpermission \
+ ${bindir}/mysql-systemd-start \
${bindir}/mysql_tzinfo_to_sql \
${bindir}/mysql_upgrade \
${bindir}/mysql_plugin \
@@ -268,7 +271,7 @@ FILES_${PN}-server = "\
${libdir}/plugin/*.so \
${datadir}/mysql/ \
${localstatedir}/mysql/ \
- ${sysconfdir}/init.d \
+ ${sysconfdir}/init.d/mysqld \
${sysconfdir}/my.cnf \
${sysconfdir}/my.cnf.d/server.cnf \
${sysconfdir}/tmpfiles.d"
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 0000000..512a7da
--- /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 0000000..c8369f5
--- /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 28d3899..dc4c172 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 0000000..189c020
--- /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 757d038..d883617 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
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH V3] mariadb.inc: fix mysqld hung at first init time based on systemd
2015-11-25 2:04 ` [PATCH V3] " Hongxu Jia
@ 2015-11-25 2:08 ` Hongxu Jia
0 siblings, 0 replies; 7+ messages in thread
From: Hongxu Jia @ 2015-11-25 2:08 UTC (permalink / raw)
Cc: openembedded-devel
Changed in V3:
As Bruce suggested, create a separate package to
install database at first boot, it allows anothers could
opt-out of the startup by overriding PACKAGECONFIG.
//Hongxu
On 11/25/2015 10:04 AM, Hongxu Jia wrote:
> 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>
> ---
> meta-oe/recipes-support/mysql/mariadb.inc | 51 +++++++++--------
> meta-oe/recipes-support/mysql/mariadb/install_db | 13 +++++
> .../mysql/mariadb/install_db.service | 17 ++++++
> meta-oe/recipes-support/mysql/mariadb/my.cnf | 1 -
> .../mysql/mariadb/mysql-systemd-start | 66 ++++++++++++++++++++++
> .../recipes-support/mysql/mariadb/mysqld.service | 9 +++
> 6 files changed, 132 insertions(+), 25 deletions(-)
> create mode 100755 meta-oe/recipes-support/mysql/mariadb/install_db
> create mode 100644 meta-oe/recipes-support/mysql/mariadb/install_db.service
> create mode 100644 meta-oe/recipes-support/mysql/mariadb/mysql-systemd-start
>
> diff --git a/meta-oe/recipes-support/mysql/mariadb.inc b/meta-oe/recipes-support/mysql/mariadb.inc
> index 42a4eda..a6826c3 100644
> --- a/meta-oe/recipes-support/mysql/mariadb.inc
> +++ b/meta-oe/recipes-support/mysql/mariadb.inc
> @@ -10,6 +10,9 @@ SRC_URI = "http://archive.mariadb.org/mariadb-${PV}/source/mariadb-${PV}.tar.gz
> file://fix-mysqlclient-r-version.patch \
> file://my.cnf \
> file://mysqld.service \
> + file://install_db.service \
> + file://install_db \
> + file://mysql-systemd-start \
> file://configure.cmake-fix-valgrind.patch \
> file://fix-a-building-failure.patch \
> "
> @@ -23,26 +26,35 @@ BINCONFIG_GLOB = "mysql_config"
>
> inherit cmake gettext binconfig update-rc.d useradd systemd
>
> -INITSCRIPT_PACKAGES = "${PN}-server"
> -INITSCRIPT_NAME = "mysqld"
> -INITSCRIPT_PARAMS = "start 45 5 . stop 45 0 6 1 ."
> +INITSCRIPT_PACKAGES = "${PN}-server ${PN}-setupdb"
> +INITSCRIPT_NAME_${PN}-server = "mysqld"
> +INITSCRIPT_PARAMS_${PN}-server ?= "start 45 5 . stop 45 0 6 1 ."
>
> USERADD_PACKAGES = "${PN}-server"
> USERADD_PARAM_${PN}-server = "--system --home-dir /var/mysql -g mysql --shell /bin/false mysql"
> GROUPADD_PARAM_${PN}-server = "--system mysql"
>
> -SYSTEMD_PACKAGES = "${PN}-server"
> +INITSCRIPT_NAME_${PN}-setupdb = "install_db"
> +INITSCRIPT_PARAMS_${PN}-setupdb ?= "defaults 44 44"
> +
> +SYSTEMD_PACKAGES = "${PN}-server ${PN}-setupdb"
> SYSTEMD_SERVICE_${PN}-server = "mysqld.service"
> -SYSTEMD_AUTO_ENABLE_${PN}-server = "disable"
> +SYSTEMD_AUTO_ENABLE_${PN}-server ?= "disable"
> +
> +SYSTEMD_SERVICE_${PN}-setupdb = "install_db.service"
> +SYSTEMD_AUTO_ENABLE_${PN}-setupdb ?= "enable"
> +ALLOW_EMPTY_${PN}-setupdb ?= "1"
> +FILES_${PN}-setupdb = "${sysconfdir}/init.d/install_db"
>
> EXTRA_OEMAKE = "'GEN_LEX_HASH=${STAGING_BINDIR_NATIVE}/gen_lex_hash'"
>
> -PACKAGECONFIG ??= "${@bb.utils.contains('DISTRO_FEATURES', 'pam', 'pam', '', d)}"
> +PACKAGECONFIG ??= "${@bb.utils.contains('DISTRO_FEATURES', 'pam', 'pam', '', d)} setupdb"
> PACKAGECONFIG_class-native = ""
> PACKAGECONFIG[pam] = ",-DWITHOUT_AUTH_PAM=TRUE,libpam"
> PACKAGECONFIG[valgrind] = "-DWITH_VALGRIND=TRUE,-DWITH_VALGRIND=FALSE,valgrind"
> PACKAGECONFIG[libedit] = "-DLIBEDIT_INTERFACE=TRUE,-DLIBEDIT_INTERFACE=FALSE,libedit"
> PACKAGECONFIG[krb5] = ", ,krb5"
> +PACKAGECONFIG[setupdb] = ", ,,${PN}-setupdb"
>
> # MariaDB doesn't link properly with gold
> # https://mariadb.atlassian.net/browse/MDEV-5982
> @@ -114,39 +126,29 @@ do_install() {
>
> install -d ${D}/${sysconfdir}/init.d
> install -m 0644 ${WORKDIR}/my.cnf ${D}/${sysconfdir}/
> + install -m 0755 ${WORKDIR}/install_db ${D}/${sysconfdir}/init.d/
> mv ${D}/${sysconfdir}/init.d/mysql ${D}/${sysconfdir}/init.d/mysqld
>
> install -d ${D}${systemd_unitdir}/system
> install -m 0644 ${WORKDIR}/mysqld.service ${D}${systemd_unitdir}/system
> - sed -i -e 's,@BINDIR@,${bindir},g' -e 's,@PREFIX@,${prefix},g' ${D}${systemd_unitdir}/system/mysqld.service
> + install -m 0644 ${WORKDIR}/install_db.service ${D}${systemd_unitdir}/system
> + sed -i -e 's,@BINDIR@,${bindir},g' -e 's,@PREFIX@,${prefix},g' ${D}${systemd_unitdir}/system/mysqld.service \
> + ${D}${systemd_unitdir}/system/install_db.service
>
> if ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}; then
> install -d ${D}${sysconfdir}/tmpfiles.d
> echo "f /var/log/mysqld.err 0640 mysql mysql -" \
> > ${D}${sysconfdir}/tmpfiles.d/99-mysqld.conf
> fi
> -}
> -
> -pkg_postinst_${PN}-server () {
> - if [ "x$D" != "x" ]; then
> - exit 1
> - fi
> -
> - #Install the database
> - test -d /usr/bin || mkdir -p /usr/bin
> - test -e /usr/bin/hostname || ln -s /bin/hostname /usr/bin/hostname
> - mkdir /var/lib/mysql
> - chown mysql.mysql /var/lib/mysql
> -
> - mysql_install_db --basedir=${prefix} --user=mysql
> + install -d ${D}${bindir}
> + install -m 755 ${WORKDIR}/mysql-systemd-start ${D}${bindir}
>
> - [ -x /sbin/restorecon ] && /sbin/restorecon -RF /var/lib/mysql
> }
>
> PACKAGES = "${PN}-dbg ${PN} \
> libmysqlclient-r libmysqlclient-r-dev libmysqlclient-r-staticdev libmysqlclient-r-dbg \
> libmysqlclient libmysqlclient-dev libmysqlclient-staticdev libmysqlclient-dbg \
> - libmysqld libmysqld-dev ${PN}-client ${PN}-server ${PN}-leftovers"
> + libmysqld libmysqld-dev ${PN}-client ${PN}-server ${PN}-setupdb ${PN}-leftovers"
> CONFFILES_${PN}-server += "${sysconfdir}/my.cnf ${sysconfdir}/my.cnf.d/server.cnf"
> CONFFILES_${PN}-client += "${sysconfdir}/my.cnf.d/mysql-clients.cnf"
> CONFFILES_libmysqlclient += "${sysconfdir}/my.cnf.d/client.cnf"
> @@ -236,6 +238,7 @@ FILES_${PN}-server = "\
> ${bindir}/mysql_install_db \
> ${bindir}/mysql_secure_installation \
> ${bindir}/mysql_setpermission \
> + ${bindir}/mysql-systemd-start \
> ${bindir}/mysql_tzinfo_to_sql \
> ${bindir}/mysql_upgrade \
> ${bindir}/mysql_plugin \
> @@ -268,7 +271,7 @@ FILES_${PN}-server = "\
> ${libdir}/plugin/*.so \
> ${datadir}/mysql/ \
> ${localstatedir}/mysql/ \
> - ${sysconfdir}/init.d \
> + ${sysconfdir}/init.d/mysqld \
> ${sysconfdir}/my.cnf \
> ${sysconfdir}/my.cnf.d/server.cnf \
> ${sysconfdir}/tmpfiles.d"
> 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 0000000..512a7da
> --- /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 0000000..c8369f5
> --- /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 28d3899..dc4c172 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 0000000..189c020
> --- /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 757d038..d883617 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
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-11-25 2:08 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-21 3:47 [meta-oe][PATCH] mariadb.inc: fix mysqld hung at first init time based on systemd Hongxu Jia
2015-11-21 8:05 ` Hongxu Jia
2015-11-21 8:10 ` [meta-oe][PATCH V2] " Hongxu Jia
2015-11-21 8:12 ` Hongxu Jia
2015-11-21 8:13 ` Hongxu Jia
2015-11-25 2:04 ` [PATCH V3] " Hongxu Jia
2015-11-25 2:08 ` Hongxu Jia
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.