This commit is contained in:
Darren 2024-12-19 11:51:36 +08:00 committed by GitHub
parent 7fdf7ba3f1
commit 607a06a6a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 24 deletions

View File

@ -3,10 +3,9 @@
echo "$(date '+%Y-%m-%d %H:%M:%S') - INFO - start to migrate config.ini"
migrate_ini() {
# Define file paths, use template ini and syn exsit items from target ini
# Combine source_ini to target ini
export target_ini="$1"
export template_ini="$2"
export source_ini="$2"
python3 - <<EOF
import configparser
@ -14,34 +13,34 @@ import os
import sys
target_ini = os.environ['target_ini']
template_ini = os.environ['template_ini']
source_ini = os.environ['source_ini']
# Create two config parsers
target_parser = configparser.ConfigParser()
template_parser = configparser.ConfigParser()
source_parser = configparser.ConfigParser()
try:
target_parser.read(target_ini)
template_parser.read(template_ini)
source_parser.read(source_ini)
except configparser.MissingSectionHeaderError:
print("Error: The provided files are not valid INI files.")
sys.exit(1)
# use target_parser to override template_parser
# use target_parser to override source_parser
for section in target_parser.sections():
if template_parser.has_section(section):
if source_parser.has_section(section):
for key, value in target_parser.items(section):
if template_parser.has_option(section, key):
template_parser.set(section, key, value)
if source_parser.has_option(section, key):
source_parser.set(section, key, value)
with open(target_ini, 'w') as f:
template_parser.write(f)
source_parser.write(f)
EOF
}
# special migration
# Special migration
post_migration(){
echo "$(date '+%Y-%m-%d %H:%M:%S') - INFO - Set listen_port to nginx_proxy_manager"
config_file="/websoft9/config/config.ini"

View File

@ -4,6 +4,9 @@ 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"
cockpit_service_path="/lib/systemd/system/cockpit.socket"
cockpit_ssl_path="/etc/cockpit/ws-certs.d/"
npm_ssl_path="/var/lib/docker/volumes/websoft9_nginx_data/_data/custom_ssl/"
# get volume from container
function get_volume_path() {
@ -30,11 +33,10 @@ function get_volume_path() {
}
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"
# sync cockpit port from config.ini
sync_cockpit_port_fromconfig() {
sync_cockpit_port() {
echo "sync cockpit port from config.ini"
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)
@ -59,22 +61,22 @@ set_Firewalld(){
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/
sync_cockpit_port
cp -r "${cockpit_ssl_path}"* $npm_ssl_path
}
# 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 cockpit.socket and config.ini, make sure port at config.ins sync to cockpit.socket
inotifywait -e modify,attrib -m $FILES | while read PATH EVENT FILE; do
echo "Set cockpit port by config.ini..."
echo "Reset cockpit port when config.ini changed"
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
sync_cockpit_port_fromconfig
sync_cockpit_port
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,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/
# monitor cockpit ssl path and sync to NPM ssl path if changed
inotifywait -e create,modify,delete,attrib -m $cockpit_ssl_path | while read PATH EVENT FILE; do
echo "Sync CA files from cockipt to NPM when changed"
cp -r "${cockpit_ssl_path}"* $npm_ssl_path
done