-
Notifications
You must be signed in to change notification settings - Fork 203
/
Copy pathcontainer-setup
executable file
·69 lines (54 loc) · 2.58 KB
/
container-setup
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
source ${CONTAINER_SCRIPTS_PATH}/common.sh
# This function returns all config files that daemon uses and their path
# includes /opt. It is used to get correct path to the config file.
mysql_get_config_files_scl() {
scl enable ${ENABLED_COLLECTIONS} -- my_print_defaults --help --verbose | \
grep --after=1 '^Default options' | \
tail -n 1 | \
grep -o '[^ ]*opt[^ ]*my.cnf'
}
# This function picks the main config file that deamon uses and we ship in rpm
mysql_get_correct_config() {
# we use the same config in non-SCL packages, not necessary to guess
[ -z "${ENABLED_COLLECTIONS}" ] && echo -n "/etc/my.cnf" && return
# from all config files read by daemon, pick the first that exists
for f in `mysql_get_config_files_scl` ; do
[ -f "$f" ] && echo "$f"
done | head -n 1
}
export MYSQL_CONFIG_FILE=$(mysql_get_correct_config)
[ -z "$MYSQL_CONFIG_FILE" ] && echo "MYSQL_CONFIG_FILE is empty" && exit 1
unset -f mysql_get_correct_config mysql_get_config_files_scl
# we provide own config files for the container, so clean what rpm ships here
mkdir -p ${MYSQL_CONFIG_FILE}.d
rm -f ${MYSQL_CONFIG_FILE}.d/*
# we may add options during service init, so we need to have this dir writable by daemon user
chown -R mysql:0 ${MYSQL_CONFIG_FILE}.d ${MYSQL_CONFIG_FILE}
restorecon -R ${MYSQL_CONFIG_FILE}.d ${MYSQL_CONFIG_FILE}
# API of the container are standard paths /etc/my.cnf and /etc/my.cnf.d
# we already include own /etc/my.cnf for container, but for cases the
# actually used config file is not on standard path /etc/my.cnf, we
# need to move it to the location daemon expects it and create symlinks
if [ "$MYSQL_CONFIG_FILE" != "/etc/my.cnf" ] ; then
rm -rf /etc/my.cnf.d
mv /etc/my.cnf ${MYSQL_CONFIG_FILE}
ln -s ${MYSQL_CONFIG_FILE} /etc/my.cnf
ln -s ${MYSQL_CONFIG_FILE}.d /etc/my.cnf.d
fi
# some config options are only valid for particular versions
if [ "`version2number $MYSQL_VERSION`" -ge "800" ] ; then
rm -f "${CONTAINER_SCRIPTS_PATH}/cnf/10-mysql57.cnf"
fi
# setup directory for data
mkdir -p /var/lib/mysql/data
chown -R mysql:0 /var/lib/mysql
restorecon -R /var/lib/mysql
# remove linux capability of the daemon, since it does not work in the container
setcap -r ${MYSQL_PREFIX}/libexec/mysqld
# Loosen permission bits for group to avoid problems running container with
# arbitrary UID
# When only specifying user, group is 0, that's why /var/lib/mysql must have
# owner mysql.0; that allows to avoid a+rwx for this dir
/usr/libexec/fix-permissions /var/lib/mysql ${MYSQL_CONFIG_FILE}.d ${APP_DATA}/..
usermod -a -G root mysql