Skip to content

Commit e584a8d

Browse files
committed
Move upgrade to post svc init
1 parent eab912a commit e584a8d

File tree

6 files changed

+33
-45
lines changed

6 files changed

+33
-45
lines changed

root/etc/s6-overlay/s6-rc.d/init-mariadb-initdb/run

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ start_mariadb() {
1313
done
1414
}
1515

16-
# make temp sql init file
17-
tempSqlFile=$(mktemp)
18-
19-
# test for empty password variable, if it's set to 0 or less than 4 characters
20-
if [[ -z "${MYSQL_ROOT_PASSWORD}" ]]; then
21-
TEST_LEN="0"
22-
else
23-
TEST_LEN=${#MYSQL_ROOT_PASSWORD}
24-
fi
25-
2616
# test for existence of mysql folder in datadir and start initialise if not present
2717
if [[ ! -d "${DATADIR}/mysql" ]]; then
2818
# load env file if it exists
@@ -31,11 +21,21 @@ if [[ ! -d "${DATADIR}/mysql" ]]; then
3121
source /config/env
3222
fi
3323

24+
# make temp sql init file
25+
tempSqlFile=$(mktemp)
26+
3427
# set basic sql command
3528
cat >"${tempSqlFile}" <<-EOSQL
3629
DELETE FROM mysql.user WHERE user <> 'mariadb.sys';
3730
EOSQL
3831

32+
# test for empty password variable, if it's set to 0 or less than 4 characters
33+
if [[ -z "${MYSQL_ROOT_PASSWORD}" ]]; then
34+
TEST_LEN="0"
35+
else
36+
TEST_LEN=${#MYSQL_ROOT_PASSWORD}
37+
fi
38+
3939
if [[ "${TEST_LEN}" -lt "4" ]]; then
4040
MYSQL_PASS="CREATE USER 'root'@'%' IDENTIFIED BY '' ;"
4141
else
@@ -115,44 +115,11 @@ EOFPASS
115115

116116
sleep 5s
117117
fi
118-
else
119-
if [[ "${TEST_LEN}" -lt "4" ]]; then
120-
echo "MYSQL_ROOT_PASSWORD is not set or too short, skipping upgrade check"
121-
else
122-
# set some permissions needed before we begin
123-
lsiown -R abc:abc "${tempSqlFile}"
124-
125-
# start mariadb
126-
start_mariadb
127-
128-
# display a message about upgrading database if needed
129-
if mariadb-upgrade -u root -p"${MYSQL_ROOT_PASSWORD}" --check-if-upgrade-is-needed >/dev/null 2>&1; then
130-
cat <<-EOFPASS
131-
132118

133-
134-
#################################################################
135-
# An upgrade is required on your databases. Run the command #
136-
# mariadb-upgrade -u root -p<PASSWORD> #
137-
#################################################################
138-
139-
140-
141-
EOFPASS
142-
143-
sleep 5s
144-
fi
145-
146-
# shut down after apply sql commands, waiting for pid to stop
147-
mariadb-admin -u root shutdown
148-
wait "${pid}"
149-
echo "Database Upgrade Check Completed"
150-
fi
119+
# clean up any old install files from /tmp
120+
rm -f "${tempSqlFile}"
151121
fi
152122

153-
# clean up any old install files from /tmp
154-
rm -f "${tempSqlFile}"
155-
156123
# own the folder the pid for mysql runs in
157124
lsiown -R abc:abc /var/run/mysqld
158125
lsiown -R abc:abc /config

root/etc/s6-overlay/s6-rc.d/init-mariadb-upgrade/dependencies.d/svc-mariadb

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
3+
4+
# display a message about upgrading database if needed
5+
if mariadb-upgrade -u root -p"${MYSQL_ROOT_PASSWORD}" --check-if-upgrade-is-needed >/dev/null 2>&1; then
6+
cat <<-EOF
7+
8+
9+
10+
#################################################################
11+
# An upgrade is required on your databases. Run the command #
12+
# mariadb-upgrade -u root -p<PASSWORD> #
13+
#################################################################
14+
15+
16+
17+
EOF
18+
sleep 5s
19+
fi
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oneshot
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/etc/s6-overlay/s6-rc.d/init-mariadb-upgrade/run

root/etc/s6-overlay/s6-rc.d/user/contents.d/init-mariadb-upgrade

Whitespace-only changes.

0 commit comments

Comments
 (0)