From 79de33d60fb5763a844c9a5f81e552491b67b991 Mon Sep 17 00:00:00 2001 From: qiaofeng1227 <76487013@qq.com> Date: Thu, 9 Nov 2023 14:49:41 +0800 Subject: [PATCH] crontab --- systemd/script/crontab.sh | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/systemd/script/crontab.sh b/systemd/script/crontab.sh index 1249fdf2..c0f5b774 100644 --- a/systemd/script/crontab.sh +++ b/systemd/script/crontab.sh @@ -5,6 +5,20 @@ cockpit_port="9000" container_name="websoft9-apphub" volume_name="websoft9_apphub_config" +check_ports() { + + local ports=("$@") + for port in "${ports[@]}"; do + echo "Check port: $port" + if ss -tuln | grep ":$port " >/dev/null && ! systemctl status cockpit.socket | grep "$port" >/dev/null; then + echo "Port $port is in use, can not set this port to config.ini" + return 0 + fi + done + echo "All ports are available" + return 1 +} + # get volume from container function get_volume_path() { local container_name="$1" @@ -24,11 +38,16 @@ on_change() { 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) if [ "$cockpit_port" != "$listen_stream" ]; then - sed -i "s/ListenStream=${listen_stream}/ListenStream=${cockpit_port}/" /lib/systemd/system/cockpit.socket - systemctl daemon-reload - systemctl restart cockpit.socket 2> /dev/null - systemctl restart cockpit || exit 1 - set_Firewalld + check_ports "$cockpit_port" + if [ $? -eq 0 ]; then + sudo docker exec -i websoft9-apphub apphub setconfig --section cockpit --key port --value "$listen_stream" + else + sudo sed -i "s/ListenStream=${listen_stream}/ListenStream=${cockpit_port}/" "$cockpit_service_path" + systemctl daemon-reload + systemctl restart cockpit.socket 2> /dev/null + systemctl restart cockpit || exit 1 + set_Firewalld + fi fi set -e }