Skip to content

Commit 17973cc

Browse files
committed
Bug#23588977 CONSISTENCY ISSUES IN DEB PACKAGING
* Replaced /bin/sh with /bin/bash in mysql-common.postinst * Moved checking/creation of directories and database from various places to shared helper script * Remove full binary path for e.g. mysqld when running in scripts
1 parent d7b37d4 commit 17973cc

8 files changed

+187
-257
lines changed

packaging/deb-in/extra/mysql-helpers

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; version 2 of the License.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15+
16+
# Wait for server to start up (this requires the client package)
17+
pinger () {
18+
while /bin/true ; do
19+
sleep 1
20+
mysqladmin ping >/dev/null 2>&1 && break
21+
done
22+
}
23+
24+
# To avoid having hardcoded paths in the script, we do a search on the path, as suggested at:
25+
# https://www.debian.org/doc/manuals/developers-reference/ch06.en.html#bpp-debian-maint-scripts
26+
pathfind() {
27+
OLDIFS="$IFS"
28+
IFS=:
29+
for p in $PATH; do
30+
if [ -x "$p/$*" ]; then
31+
IFS="$OLDIFS"
32+
return 0
33+
fi
34+
done
35+
IFS="$OLDIFS"
36+
return 1
37+
}
38+
39+
# Fetch value from config files
40+
# Usage: get_mysql_option [section] [option] [default value]
41+
get_mysql_option() {
42+
if pathfind my_print_defaults; then
43+
RESULT=$(my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1)
44+
fi
45+
if [ -z "$RESULT" ]; then
46+
RESULT="$3"
47+
fi
48+
echo $RESULT
49+
}
50+
51+
# Check if server is running
52+
get_running () {
53+
PIDFILE=$(get_mysql_option mysqld_safe pid-file "")
54+
if [ -z "$PIDFILE" ]; then
55+
PIDFILE=$(get_mysql_option mysqld pid-file "$MYSQLDATA/$(hostname).pid")
56+
fi
57+
if [ -e "$PIDFILE" ] && [ -d "/proc/$(cat "$PIDFILE")" ]; then
58+
echo 1
59+
else
60+
echo 0
61+
fi
62+
}
63+
64+
# Runs an arbitrary init sql file supplied in $1. Does not require login access
65+
run_init_sql() {
66+
tmpdir=$(mktemp -d)
67+
chown mysql:mysql "$tmpdir"
68+
mysqld --bootstrap --user=mysql --socket="$tmpdir/mysqld.sock" --pid-file="$tmpdir/mysqld.pid" > /dev/null 2>&1 < "$1"
69+
result=$?
70+
rm -rf "$tmpdir"
71+
return $result
72+
}
73+
74+
# Verify that everything the server needs to run is set up
75+
verify_ready() {
76+
77+
MYSQLDATA=/var/lib/mysql
78+
MYSQLFILES=/var/lib/mysql-files
79+
MYSQLKEYRING=/var/lib/mysql-keyring
80+
MYSQLLOG=/var/log/mysql
81+
MYSQLRUN=/var/run/mysqld
82+
83+
if ! getent group mysql >/dev/null; then
84+
addgroup --system mysql >/dev/null
85+
fi
86+
87+
if ! getent passwd mysql >/dev/null; then
88+
adduser --ingroup mysql --system --disabled-login --no-create-home --home ${MYSQLDATA} --shell /bin/false --gecos "MySQL Server" mysql >/dev/null
89+
fi
90+
91+
if [ ! -d ${MYSQLDATA} -a ! -L ${MYSQLDATA} ]; then
92+
install -d -m0750 -omysql -gmysql ${MYSQLDATA}
93+
fi
94+
95+
if [ ! -d ${MYSQLFILES} -a ! -L ${MYSQLFILES} ]; then
96+
install -d -m0770 -omysql -gmysql ${MYSQLFILES}
97+
fi
98+
99+
if [ ! -d ${MYSQLKEYRING} -a ! -L ${MYSQLKEYRING} ]; then
100+
install -d -m0750 -omysql -gmysql ${MYSQLKEYRING}
101+
fi
102+
103+
if [ ! -d ${MYSQLLOG} -a ! -L ${MYSQLLOG} ]; then
104+
install -d -m0750 -omysql -gadm ${MYSQLLOG}
105+
install /dev/null -m0640 -omysql -gadm ${MYSQLLOG}/error.log
106+
fi
107+
108+
if [ ! -d ${MYSQLRUN} -a ! -L ${MYSQLRUN} ]; then
109+
install -d -m0755 -omysql -gmysql ${MYSQLRUN}
110+
fi
111+
}
112+
113+
# Verify the database exists and is ssl ready
114+
verify_database() {
115+
MYSQLDATA=/var/lib/mysql
116+
MYSQLFILES=/var/lib/mysql-files
117+
118+
if [ ! -d "${MYSQLDATA}/mysql" ] && [ -d "${MYSQLFILES}" ]; then
119+
su - mysql -s /bin/bash -c "mysql_install_db --user=mysql > /dev/null"
120+
SQL=$(mktemp -u ${MYSQLFILES}/XXXXXXXXXX)
121+
install /dev/null -m0600 -omysql -gmysql "${SQL}"
122+
cat << EOF > ${SQL}
123+
USE mysql;
124+
INSTALL PLUGIN auth_socket SONAME 'auth_socket.so';
125+
UPDATE user SET plugin='auth_socket' WHERE user='root';
126+
FLUSH PRIVILEGES;
127+
EOF
128+
run_init_sql "$SQL"
129+
rm -f "$SQL"
130+
fi
131+
132+
if [ -x /usr/bin/mysql_ssl_rsa_setup -a ! -e "${MYSQLDATA}/server-key.pem" ]; then
133+
mysql_ssl_rsa_setup --datadir="${MYSQLDATA}" --uid=mysql >/dev/null 2>&1
134+
fi
135+
}
136+
137+
verify_server () {
138+
TIMEOUT=0
139+
if [ "${1}" = "start" ]; then
140+
TIMEOUT=${STARTTIMEOUT}
141+
elif [ "${1}" = "stop" ]; then
142+
TIMEOUT=${STOPTIMEOUT}
143+
fi
144+
145+
COUNT=0
146+
while [ ${COUNT} -lt ${TIMEOUT} ];
147+
do
148+
COUNT=$(( COUNT+1 ))
149+
echo -n .
150+
if [ "${1}" = "start" ] && [ "$(get_running)" = 1 ]; then
151+
if [ -z ${2} ]; then
152+
echo
153+
fi
154+
return 0
155+
fi
156+
if [ "${1}" = "stop" ] && [ "$(get_running)" = 0 ]; then
157+
if [ -z ${2} ]; then
158+
echo
159+
fi
160+
return 0
161+
fi
162+
sleep 1
163+
done
164+
return 1
165+
}
166+

packaging/deb-in/extra/mysql-systemd-start

Lines changed: 6 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3+
# Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
44
#
55
# This program is free software; you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by
@@ -22,73 +22,14 @@
2222
# pre mode : try to perform sanity check for configuration, log, data
2323
# post mode : ping server until answer is received
2424

25-
pinger () {
26-
while /bin/true ; do
27-
sleep 1
28-
mysqladmin ping >/dev/null 2>&1 && break
29-
done
30-
}
31-
32-
get_path () {
33-
my_print_defaults mysqld | grep "$1" | cut -d= -f2 | tail -n 1
34-
}
35-
36-
# Runs an arbitrary init sql file supplied in $1. Does not require login access
37-
run_init_sql() {
38-
tmpdir=$(mktemp -d)
39-
chown mysql:mysql "$tmpdir"
40-
mysqld --user=mysql --bootstrap --socket="$tmpdir/mysqld.sock" --pid-file="$tmpdir/mysqld.pid" > /dev/null 2>&1 < "$1"
41-
result=$?
42-
rm -rf "$tmpdir"
43-
return $result
44-
}
25+
# Include helper functions
26+
. /usr/share/mysql/mysql-helpers
4527

4628
sanity () {
47-
MYSQLRUN=/var/run/mysqld
48-
MYSQLDATA=/var/lib/mysql
49-
MYSQLFILES=/var/lib/mysql-files
50-
MYSQLKEYRING=/var/lib/mysql-keyring
51-
MYSQLLOG=/var/log/mysql
52-
53-
if [ ! -d ${MYSQLDATA} -a ! -L ${MYSQLDATA} ];
54-
then
55-
install -d -m0750 -omysql -gmysql ${MYSQLDATA}
56-
fi
57-
58-
if [ ! -d ${MYSQLFILES} -a ! -L ${MYSQLFILES} ];
59-
then
60-
install -d -m0770 -omysql -gmysql ${MYSQLFILES}
61-
fi
62-
63-
if [ ! -d ${MYSQLKEYRING} -a ! -L ${MYSQLKEYRING} ];
64-
then
65-
install -d -m0750 -omysql -gmysql ${MYSQLKEYRING}
66-
fi
67-
68-
if [ ! "$(ls -A ${MYSQLDATA}/mysql)" ];
69-
then
70-
SQL=$(mktemp -u ${MYSQLFILES}/XXXXXXXXXX)
71-
install /dev/null -m0600 -omysql -gmysql "${SQL}"
72-
cat << EOF > ${SQL}
73-
UPDATE user SET password=PASSWORD('${PASSWD}') WHERE user='root';
74-
DELETE FROM user WHERE user='';
75-
FLUSH PRIVILEGES;
76-
EOF
77-
mysql_install_db --user=mysql > /dev/null
78-
run_init_sql "$SQL"
79-
rm -f "$SQL"
80-
fi
81-
82-
if [ -x /usr/bin/mysql_ssl_rsa_setup -a ! -e "${MYSQLDATA}/server-key.pem" ];
83-
then
84-
/usr/bin/mysql_ssl_rsa_setup --datadir="${MYSQLDATA}" --uid=mysql >/dev/null 2>&1
85-
fi
29+
# Make sure database and required directories exist
30+
verify_ready
31+
verify_database
8632

87-
if [ ! -d ${MYSQLLOG} -a ! -L ${MYSQLLOG} ];
88-
then
89-
install -d -m0750 -omysql -gadm ${MYSQLLOG}
90-
install /dev/null -m0640 -omysql -gadm ${MYSQLLOG}/error.log
91-
fi
9233

9334
@DEB_INIT_APPARMOR@
9435

packaging/deb-in/mysql-common.postinst.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

3-
# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3+
# Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
44
#
55
# This program is free software; you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by

packaging/deb-in/mysql-packagesource-server.install.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -92,6 +92,7 @@ usr/lib/mysql/plugin/debug/validate_password.so
9292
usr/share/mysql/dictionary.txt
9393
usr/share/mysql/magic
9494
usr/share/mysql/mysql-log-rotate
95+
usr/share/mysql/mysql-helpers
9596
# localized error msgs
9697
usr/share/mysql/*/errmsg.sys
9798
usr/share/mysql/errmsg-utf8.txt

0 commit comments

Comments
 (0)