blob: 8670f889574ef252dbbb32f9470c747d0e75d6fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#! /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
#
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
|