Updated DB Upgrade process (avoid internal upgrade issues (mysql_tables)

This commit is contained in:
DerLinkman 2023-03-21 12:25:19 +01:00
parent db6c50d046
commit ad157d9760
3 changed files with 34 additions and 7 deletions

View File

@ -321,7 +321,7 @@ class DockerUtils:
# api call: container_post - post_action: exec - cmd: system - task: mysql_upgrade # api call: container_post - post_action: exec - cmd: system - task: mysql_upgrade
def container_post__exec__system__mysql_upgrade(self, container_id, request_json): def container_post__exec__system__mysql_upgrade(self, container_id, request_json):
for container in self.docker_client.containers.list(filters={"id": container_id}): for container in self.docker_client.containers.list(filters={"id": container_id}):
sql_return = container.exec_run(["/bin/bash", "-c", "/usr/bin/mysql_upgrade -uroot -p'" + os.environ['DBROOT'].replace("'", "'\\''") + "'\n"], user='mysql') sql_return = container.exec_run(["/bin/bash", "-c", "/usr/bin/mysql-upgrade -uroot -p'" + os.environ['DBROOT'].replace("'", "'\\''") + "'\n"], user='mysql')
if sql_return.exit_code == 0: if sql_return.exit_code == 0:
matched = False matched = False
for line in sql_return.output.decode('utf-8').split("\n"): for line in sql_return.output.decode('utf-8').split("\n"):
@ -337,6 +337,27 @@ class DockerUtils:
else: else:
res = { 'type': 'error', 'msg': 'mysql_upgrade: error running command', 'text': sql_return.output.decode('utf-8')} res = { 'type': 'error', 'msg': 'mysql_upgrade: error running command', 'text': sql_return.output.decode('utf-8')}
return Response(content=json.dumps(res, indent=4), media_type="application/json") return Response(content=json.dumps(res, indent=4), media_type="application/json")
# api call: container_post - post_action: exec - cmd: system - task: mariadb_upgrade (new for 10.6+)
def container_post__exec__system__mariadb_upgrade(self, container_id, request_json):
for container in self.docker_client.containers.list(filters={"id": container_id}):
sql_return = container.exec_run(["/bin/bash", "-c", "/usr/bin/mariadb-upgrade -uroot -p'" + os.environ['DBROOT'].replace("'", "'\\''") + "'\n"], user='mysql')
if sql_return.exit_code == 0:
matched = False
for line in sql_return.output.decode('utf-8').split("\n"):
if 'is already upgraded to' in line:
matched = True
if matched:
res = { 'type': 'success', 'msg':'mariadb_upgrade: already upgraded', 'text': sql_return.output.decode('utf-8')}
return Response(content=json.dumps(res, indent=4), media_type="application/json")
else:
container.restart()
res = { 'type': 'warning', 'msg':'mariadb_upgrade: upgrade was applied', 'text': sql_return.output.decode('utf-8')}
return Response(content=json.dumps(res, indent=4), media_type="application/json")
else:
res = { 'type': 'error', 'msg': 'mariadb_upgrade: error running command', 'text': sql_return.output.decode('utf-8')}
return Response(content=json.dumps(res, indent=4), media_type="application/json")
# api call: container_post - post_action: exec - cmd: system - task: mysql_tzinfo_to_sql # api call: container_post - post_action: exec - cmd: system - task: mysql_tzinfo_to_sql
def container_post__exec__system__mysql_tzinfo_to_sql(self, container_id, request_json): def container_post__exec__system__mysql_tzinfo_to_sql(self, container_id, request_json):
for container in self.docker_client.containers.list(filters={"id": container_id}): for container in self.docker_client.containers.list(filters={"id": container_id}):

View File

@ -29,18 +29,24 @@ done
echo "MySQL @ ${CONTAINER_ID}" echo "MySQL @ ${CONTAINER_ID}"
SQL_LOOP_C=0 SQL_LOOP_C=0
SQL_CHANGED=0 SQL_CHANGED=0
SQL_TYPE=$(mysqladmin version -u${DBUSER} -p${DBPASS} --socket=/var/run/mysqld/mysqld.sock | grep -o -m 1 -E 'MySQL|MariaDB' | tr '[:upper:]' '[:lower:]')
if [[ ${SQL_TYPE} == "mariadb" ]]; then
SQL_FULL_UPGRADE_RETURN=$(curl --silent --insecure -XPOST https://dockerapi/containers/${CONTAINER_ID}/exec -d '{"cmd":"system", "task":"mariadb_upgrade"}' --silent -H 'Content-type: application/json')
elif [[ ${SQL_TYPE} == "mysql" ]]; then
SQL_FULL_UPGRADE_RETURN=$(curl --silent --insecure -XPOST https://dockerapi/containers/${CONTAINER_ID}/exec -d '{"cmd":"system", "task":"mysql_upgrade"}' --silent -H 'Content-type: application/json')
fi
until [[ ${SQL_UPGRADE_STATUS} == 'success' ]]; do until [[ ${SQL_UPGRADE_STATUS} == 'success' ]]; do
if [ ${SQL_LOOP_C} -gt 4 ]; then if [ ${SQL_LOOP_C} -gt 4 ]; then
echo "Tried to upgrade MySQL and failed, giving up after ${SQL_LOOP_C} retries and starting container (oops, not good)" echo "Tried to upgrade MySQL and failed, giving up after ${SQL_LOOP_C} retries and starting container (oops, not good)"
break break
fi fi
SQL_FULL_UPGRADE_RETURN=$(curl --silent --insecure -XPOST https://dockerapi/containers/${CONTAINER_ID}/exec -d '{"cmd":"system", "task":"mysql_upgrade"}' --silent -H 'Content-type: application/json')
SQL_UPGRADE_STATUS=$(echo ${SQL_FULL_UPGRADE_RETURN} | jq -r .type) SQL_UPGRADE_STATUS=$(echo ${SQL_FULL_UPGRADE_RETURN} | jq -r .type)
SQL_LOOP_C=$((SQL_LOOP_C+1)) SQL_LOOP_C=$((SQL_LOOP_C+1))
echo "SQL upgrade iteration #${SQL_LOOP_C}" echo "SQL upgrade iteration #${SQL_LOOP_C}"
if [[ ${SQL_UPGRADE_STATUS} == 'warning' ]]; then if [[ ${SQL_UPGRADE_STATUS} == 'warning' ]]; then
SQL_CHANGED=1 SQL_CHANGED=1
echo "MySQL applied an upgrade, debug output:" echo "${SQL_TYPE} applied an upgrade, debug output:"
echo ${SQL_FULL_UPGRADE_RETURN} echo ${SQL_FULL_UPGRADE_RETURN}
sleep 3 sleep 3
while ! mysqladmin status --socket=/var/run/mysqld/mysqld.sock -u${DBUSER} -p${DBPASS} --silent; do while ! mysqladmin status --socket=/var/run/mysqld/mysqld.sock -u${DBUSER} -p${DBPASS} --silent; do
@ -49,10 +55,10 @@ until [[ ${SQL_UPGRADE_STATUS} == 'success' ]]; do
done done
continue continue
elif [[ ${SQL_UPGRADE_STATUS} == 'success' ]]; then elif [[ ${SQL_UPGRADE_STATUS} == 'success' ]]; then
echo "MySQL is up-to-date - debug output:" echo "${SQL_TYPE} is up-to-date - debug output:"
echo ${SQL_FULL_UPGRADE_RETURN} echo ${SQL_FULL_UPGRADE_RETURN}
else else
echo "No valid reponse for mysql_upgrade was received, debug output:" echo "No valid reponse for ${SQL_TYPE}_upgrade was received, debug output:"
echo ${SQL_FULL_UPGRADE_RETURN} echo ${SQL_FULL_UPGRADE_RETURN}
fi fi
done done

View File

@ -106,7 +106,7 @@ services:
- rspamd - rspamd
php-fpm-mailcow: php-fpm-mailcow:
image: mailcow/phpfpm:1.82 image: mailcow/phpfpm:1.83
command: "php-fpm -d date.timezone=${TZ} -d expose_php=0" command: "php-fpm -d date.timezone=${TZ} -d expose_php=0"
depends_on: depends_on:
- redis-mailcow - redis-mailcow
@ -510,7 +510,7 @@ services:
- watchdog - watchdog
dockerapi-mailcow: dockerapi-mailcow:
image: mailcow/dockerapi:2.01 image: mailcow/dockerapi:2.02
security_opt: security_opt:
- label=disable - label=disable
restart: always restart: always