Skip to content

Commit f989c0e

Browse files
authored
Merge pull request #112 from linuxserver/upgrade
Upgrade
2 parents 429ee21 + ad6f6c5 commit f989c0e

File tree

7 files changed

+74
-43
lines changed

7 files changed

+74
-43
lines changed

readme-vars.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ optional_block_1: false
5353
app_setup_block_enabled: true
5454
app_setup_block: |
5555
If you didn't set a password during installation, (see logs for warning) use
56-
`mysqladmin -u root password <PASSWORD>`
56+
`mariadb-admin -u root -p<PASSWORD>`
5757
to set one at the docker prompt...
5858
5959
NOTE changing the MYSQL_ROOT_PASSWORD variable after the container has set up the initial databases has no effect, use the mysqladmin tool to change your mariadb password.
@@ -94,8 +94,17 @@ app_setup_block: |
9494
```
9595
This will have the same effect as setting the `REMOTE_SQL` environment variable. The sql will only be run on the containers first boot and setup.
9696
97+
### Upgrading
98+
99+
When this container initializes, if `MYSQL_ROOT_PASSWORD` is set an upgrade check will run. If an upgrade is required the log will indicate the need to run:
100+
101+
```
102+
mariadb-upgrade -u root -p<PASSWORD>
103+
```
104+
97105
# changelog
98106
changelogs:
107+
- { date: "09.12.22:", desc: "Add upgrade check warning." }
99108
- { date: "11.10.22:", desc: "Rebase master to Alpine 3.16, migrate to s6v3, remove password escape logic which caused problems for a small subset of users." }
100109
- { date: "06.07.21:", desc: "Rebase master to alpine." }
101110
- { date: "03.07.21:", desc: "Rebase to 3.14." }
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,35 @@
11
#!/usr/bin/with-contenv bash
22
# shellcheck shell=bash
33

4-
# set start function that creates user and password, used later
5-
start_mysql() {
6-
mysqld --datadir="${DATADIR}" --init-file="${tempSqlFile}" --user=abc &
4+
# set start function used later
5+
start_mariadb() {
6+
mariadbd --datadir="${DATADIR}" --init-file="${tempSqlFile}" --user=abc &
77
pid="$!"
88
RET=1
99
while [[ RET -ne 0 ]]; do
10-
mysql -uroot -e "status" >/dev/null 2>&1
10+
mariadb -uroot -e "status" >/dev/null 2>&1
1111
RET=$?
1212
sleep 1
1313
done
1414
}
1515

1616
# test for existence of mysql folder in datadir and start initialise if not present
17-
# BEGIN: No indentation due to heredocs
1817
if [[ ! -d "${DATADIR}/mysql" ]]; then
19-
2018
# load env file if it exists
2119
if [[ -f "/config/env" ]]; then
20+
# shellcheck source=/dev/null
2221
source /config/env
2322
fi
2423

25-
# set basic sql command
24+
# make temp sql init file
2625
tempSqlFile=$(mktemp)
26+
27+
# set basic sql command
2728
cat >"${tempSqlFile}" <<-EOSQL
2829
DELETE FROM mysql.user WHERE user <> 'mariadb.sys';
2930
EOSQL
3031

31-
# set what to display if no password set with variable MYSQL_ROOT_PASSWORD
32-
NOPASS_SET=$(mktemp)
33-
cat >"${NOPASS_SET}" <<-EOFPASS
34-
#################################################################
35-
# No root password or too short a password, min of 4 characters #
36-
# No root password will be set, this is not a good thing #
37-
# You shoud set one after initialisation with the command #
38-
# mysqladmin -u root password <PASSWORD> #
39-
#################################################################
40-
EOFPASS
41-
42-
# test for empty password variable, if it's set to 0 or less than 4 characters
43-
if [[ -z "${MYSQL_ROOT_PASSWORD}" ]]; then
44-
TEST_LEN="0"
45-
else
46-
TEST_LEN=${#MYSQL_ROOT_PASSWORD}
47-
fi
48-
49-
if [[ "${TEST_LEN}" -lt "4" ]]; then
32+
if [[ "${#MYSQL_ROOT_PASSWORD}" -lt "4" ]]; then
5033
MYSQL_PASS="CREATE USER 'root'@'%' IDENTIFIED BY '' ;"
5134
else
5235
MYSQL_PASS="CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;"
@@ -58,7 +41,7 @@ EOFPASS
5841
[[ "${MYSQL_DATABASE+x}" ]] &&
5942
[[ "${MYSQL_PASSWORD+x}" ]] &&
6043
[[ "${#MYSQL_PASSWORD}" -gt "3" ]]; then
61-
read -r -d '' MYSQL_DB_SETUP <<EOM
44+
read -r -d '' MYSQL_DB_SETUP <<-EOM
6245
CREATE DATABASE \`${MYSQL_DATABASE}\`;
6346
CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}';
6447
GRANT ALL PRIVILEGES ON \`${MYSQL_DATABASE}\`.* TO '${MYSQL_USER}'@'%';
@@ -81,8 +64,6 @@ EONEWSQL
8164
cat /config/initdb.d/*.sql >>"${tempSqlFile}"
8265
fi
8366

84-
chown -R abc:abc "${tempSqlFile}"
85-
8667
# ingest remote sql if REMOTE_SQL is set
8768
if [[ -n "${REMOTE_SQL+set}" ]]; then
8869
IFS=, read -ra URLS <<<"${REMOTE_SQL}"
@@ -92,34 +73,46 @@ EONEWSQL
9273
fi
9374
done
9475
fi
95-
# set some permissions needed before we begin initialising
96-
chown -R abc:abc /config/log/mysql /var/run/mysqld /var/lib/mysql
76+
77+
# set some permissions needed before we begin
78+
lsiown -R abc:abc "${tempSqlFile}" /config/log/mysql /var/run/mysqld /var/lib/mysql
9779
chmod -R 777 /config/log/mysql /var/run/mysqld /var/lib/mysql
9880

9981
# initialise database structure
100-
mysql_install_db --datadir="${DATADIR}" --user=abc --auth-root-authentication-method=normal
82+
mariadb-install-db --datadir="${DATADIR}" --user=abc --auth-root-authentication-method=normal
10183

102-
# start mysql and apply our sql commands we set above
103-
start_mysql
84+
# start mariadb and apply our sql commands we set above
85+
start_mariadb
10486

10587
# shut down after apply sql commands, waiting for pid to stop
106-
mysqladmin -u root shutdown
88+
mariadb-admin -u root shutdown
10789
wait "${pid}"
10890
echo "Database Setup Completed"
10991

11092
# display a message about password if not set or too short
111-
if [[ "${TEST_LEN}" -lt "4" ]]; then
112-
printf '\n\n\n%s\n\n\n' "$(<"${NOPASS_SET}")"
93+
if [[ "${#MYSQL_ROOT_PASSWORD}" -lt "4" ]]; then
94+
cat <<-EOFPASS
95+
96+
97+
98+
#################################################################
99+
# No root password or too short a password, min of 4 characters #
100+
# No root password will be set, this is not a good thing #
101+
# You shoud set one after initialisation with the command #
102+
# mariadb-admin -u root -p<PASSWORD> #
103+
#################################################################
104+
105+
106+
107+
EOFPASS
108+
113109
sleep 5s
114110
fi
115111

116112
# clean up any old install files from /tmp
117-
rm -f "${NOPASS_SET}"
118113
rm -f "${tempSqlFile}"
119-
120-
# END: No indentation due to heredocs
121114
fi
122115

123116
# own the folder the pid for mysql runs in
124-
chown -R abc:abc /var/run/mysqld
125-
chown -R abc:abc /config
117+
lsiown -R abc:abc /var/run/mysqld
118+
lsiown -R abc:abc /config

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

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
3+
4+
if [[ "${#MYSQL_ROOT_PASSWORD}" -gt "3" ]]; then
5+
# display a message about upgrading database if needed
6+
if mariadb-upgrade -u root -p"${MYSQL_ROOT_PASSWORD}" --check-if-upgrade-is-needed >/dev/null 2>&1; then
7+
cat <<-EOF
8+
9+
10+
11+
#################################################################
12+
# #
13+
# An upgrade is required on your databases. #
14+
# #
15+
# Stop any services that are accessing databases #
16+
# in this container, and then run the command #
17+
# #
18+
# mariadb-upgrade -u root -p<PASSWORD> #
19+
# #
20+
#################################################################
21+
22+
23+
24+
EOF
25+
sleep 5s
26+
fi
27+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oneshot
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)