diff --git a/docker/apphub/Dockerfile b/docker/apphub/Dockerfile index 3462a923..b9583f4e 100644 --- a/docker/apphub/Dockerfile +++ b/docker/apphub/Dockerfile @@ -1,6 +1,6 @@ # This file can running at actions # MEDIA_VERSION and LIBRARY_VERSION will trigger its release -# modify time: 202412171516, you can modify here to trigger Docker Build action +# modify time: 202412181615, you can modify here to trigger Docker Build action FROM python:3.10-slim-bullseye @@ -46,6 +46,9 @@ RUN apt update && apt install -y --no-install-recommends curl git jq cron iprout apt clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/man /usr/share/doc /usr/share/doc-base +# Create a file named migration_flag +RUN touch /websoft9/migration_flag + # supervisor COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY config/logging_config.yaml /etc/supervisor/conf.d/logging_config.yaml diff --git a/docker/apphub/script/entrypoint.sh b/docker/apphub/script/entrypoint.sh index 76329e6b..35b1e272 100644 --- a/docker/apphub/script/entrypoint.sh +++ b/docker/apphub/script/entrypoint.sh @@ -6,7 +6,11 @@ export PATH set -e -bash /websoft9/script/migration.sh +# execute migration script when container create +if [ -f /websoft9/migration_flag ]; then + bash /websoft9/script/migration.sh + rm -f /websoft9/migration_flag +fi try_times=5 supervisord diff --git a/docker/apphub/script/migration.sh b/docker/apphub/script/migration.sh index d5785173..70cac72d 100644 --- a/docker/apphub/script/migration.sh +++ b/docker/apphub/script/migration.sh @@ -41,9 +41,16 @@ with open(target_ini, 'w') as f: EOF } +# special migration +post_migration(){ + config_file="/websoft9/apphub/src/config/config.ini" + listen_port=$(grep -Po '^\s*listen_port\s*=\s*\K[0-9]+' "$config_file") + apphub setconfig --section nginx_proxy_manager --key listen_port --value "$listen_port" +} migrate_ini "/websoft9/apphub/src/config/config.ini" "/websoft9/config/config.ini" migrate_ini "/websoft9/apphub/src/config/system.ini" "/websoft9/config/system.ini" +post_migration if [ $? -eq 0 ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') - INFO - Success to update config.ini" diff --git a/systemd/script/crontab.sh b/systemd/script/crontab.sh index 24b7b4d9..f9a9a8a6 100644 --- a/systemd/script/crontab.sh +++ b/systemd/script/crontab.sh @@ -4,6 +4,10 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin cockpit_port="9000" container_name="websoft9-apphub" volume_name="websoft9_apphub_config" +volume_path=$(get_volume_path "$container_name" "$volume_name") +config_path="$volume_path/config.ini" +cockpit_service_path="/lib/systemd/system/cockpit.socket" +FILES="$cockpit_service_path $config_path" # get volume from container function get_volume_path() { @@ -29,13 +33,8 @@ function get_volume_path() { exit 1 } -volume_path=$(get_volume_path "$container_name" "$volume_name") -config_path="$volume_path/config.ini" -cockpit_service_path="/lib/systemd/system/cockpit.socket" -FILES="$cockpit_service_path $config_path" - -# 监控文件发生变动时需要做的事情 -on_change() { +# sync cockpit port from config.ini +sync_cockpit_port_fromconfig() { set +e cockpit_port=$(docker exec -i websoft9-apphub apphub getconfig --section cockpit --key port) listen_stream=$(grep -Po 'ListenStream=\K[0-9]*' /lib/systemd/system/cockpit.socket) @@ -58,19 +57,24 @@ set_Firewalld(){ firewall-cmd --reload 2>/dev/nul } -# when websoft9 restart, sync cockpit port and ssl -on_change -cp -r /etc/cockpit/ws-certs.d/* /var/lib/docker/volumes/websoft9_nginx_data/_data/custom_ssl/ +force_sync(){ + echo "Force sync cockpit port and certs" + sync_cockpit_port_fromconfig + cp -r /etc/cockpit/ws-certs.d/* /var/lib/docker/volumes/websoft9_nginx_data/_data/custom_ssl/ +} + +# when websoft9 restart, force sync cockpit port and certs +force_sync # monitor /lib/systemd/system/cockpit.socket and config.ini, make sure config.ini port is the same with cockpit.socket inotifywait -e modify,attrib -m $FILES | while read PATH EVENT FILE; do echo "Set cockpit port by config.ini..." export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH - on_change + sync_cockpit_port_fromconfig done # monitor /etc/cockpit/ws-certs.d and copy files to /var/lib/docker/volumes/websoft9_nginx_data/_data/custom_ssl -inotifywait -e create,modify,delete -m /etc/cockpit/ws-certs.d | while read PATH EVENT FILE; do +inotifywait -e create,modify,delete,attrib -m /etc/cockpit/ws-certs.d | while read PATH EVENT FILE; do echo "Copying files from /etc/cockpit/ws-certs.d to /var/lib/docker/volumes/websoft9_nginx_data/_data/custom_ssl..." cp -r /etc/cockpit/ws-certs.d/* /var/lib/docker/volumes/websoft9_nginx_data/_data/custom_ssl/ done \ No newline at end of file diff --git a/version.json b/version.json index 522058dd..7056741a 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { - "version": "2.1.18-rc2", + "version": "2.1.18-rc3", "plugins": { "portainer": "0.1.3", "nginx": "0.1.0",