summaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-support/mysql/mariadb
diff options
context:
space:
mode:
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 @@
1#! /bin/sh
2case "$1" in
3 start)
4 echo "Starting to install database for mariadb"
5 /usr/bin/mysql-systemd-start pre
6 echo "done."
7 ;;
8 *)
9 echo "Usage: /etc/init.d/install_db start"
10 exit 1
11esac
12
13exit 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 @@
1#
2# Simple install MySQL database service file
3# It shoulb be done before mysqld.service
4
5[Unit]
6Description=Install MySQL Community Server Database
7After=network.target
8After=syslog.target
9Before=mysqld.service
10
11[Install]
12WantedBy=multi-user.target
13
14[Service]
15Type=oneshot
16ExecStart=@BINDIR@/mysql-systemd-start pre
17
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
4socket = /var/lib/mysql/mysql.sock 4socket = /var/lib/mysql/mysql.sock
5 5
6[mysqld_safe] 6[mysqld_safe]
7err-log = /var/log/mysql.err
8 7
9[mysqld] 8[mysqld]
10user = mysql 9user = 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 @@
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
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
8Type=simple 8Type=simple
9User=mysql 9User=mysql
10Group=mysql 10Group=mysql
11
12# Execute post scripts as root
13PermissionsStartOnly=true
14
15# Start main service
11ExecStart=@BINDIR@/mysqld_safe --basedir=@PREFIX@ 16ExecStart=@BINDIR@/mysqld_safe --basedir=@PREFIX@
17
18# Don't signal startup success before a ping works
19ExecStartPost=@BINDIR@/mysql-systemd-start post
20
12TimeoutSec=300 21TimeoutSec=300
13PrivateTmp=true 22PrivateTmp=true
14 23