This commit is contained in:
qiaofeng1227 2024-12-18 16:13:23 +08:00
parent 88a4d59efe
commit d279af60c4
5 changed files with 33 additions and 15 deletions

View File

@ -1,6 +1,6 @@
# This file can running at actions # This file can running at actions
# MEDIA_VERSION and LIBRARY_VERSION will trigger its release # 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 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 && \ apt clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/man /usr/share/doc /usr/share/doc-base 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 # supervisor
COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY config/logging_config.yaml /etc/supervisor/conf.d/logging_config.yaml COPY config/logging_config.yaml /etc/supervisor/conf.d/logging_config.yaml

View File

@ -6,7 +6,11 @@ export PATH
set -e 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 try_times=5
supervisord supervisord

View File

@ -41,9 +41,16 @@ with open(target_ini, 'w') as f:
EOF 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/config.ini" "/websoft9/config/config.ini"
migrate_ini "/websoft9/apphub/src/config/system.ini" "/websoft9/config/system.ini" migrate_ini "/websoft9/apphub/src/config/system.ini" "/websoft9/config/system.ini"
post_migration
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') - INFO - Success to update config.ini" echo "$(date '+%Y-%m-%d %H:%M:%S') - INFO - Success to update config.ini"

View File

@ -4,6 +4,10 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
cockpit_port="9000" cockpit_port="9000"
container_name="websoft9-apphub" container_name="websoft9-apphub"
volume_name="websoft9_apphub_config" 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 # get volume from container
function get_volume_path() { function get_volume_path() {
@ -29,13 +33,8 @@ function get_volume_path() {
exit 1 exit 1
} }
volume_path=$(get_volume_path "$container_name" "$volume_name") # sync cockpit port from config.ini
config_path="$volume_path/config.ini" sync_cockpit_port_fromconfig() {
cockpit_service_path="/lib/systemd/system/cockpit.socket"
FILES="$cockpit_service_path $config_path"
# 监控文件发生变动时需要做的事情
on_change() {
set +e set +e
cockpit_port=$(docker exec -i websoft9-apphub apphub getconfig --section cockpit --key port) 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) 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 firewall-cmd --reload 2>/dev/nul
} }
# when websoft9 restart, sync cockpit port and ssl force_sync(){
on_change echo "Force sync cockpit port and certs"
cp -r /etc/cockpit/ws-certs.d/* /var/lib/docker/volumes/websoft9_nginx_data/_data/custom_ssl/ 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 # 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 inotifywait -e modify,attrib -m $FILES | while read PATH EVENT FILE; do
echo "Set cockpit port by config.ini..." echo "Set cockpit port by config.ini..."
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
on_change sync_cockpit_port_fromconfig
done done
# monitor /etc/cockpit/ws-certs.d and copy files to /var/lib/docker/volumes/websoft9_nginx_data/_data/custom_ssl # 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..." 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/ cp -r /etc/cockpit/ws-certs.d/* /var/lib/docker/volumes/websoft9_nginx_data/_data/custom_ssl/
done done

View File

@ -1,5 +1,5 @@
{ {
"version": "2.1.18-rc2", "version": "2.1.18-rc3",
"plugins": { "plugins": {
"portainer": "0.1.3", "portainer": "0.1.3",
"nginx": "0.1.0", "nginx": "0.1.0",