websoft9/systemd/script/crontab.sh

35 lines
1.3 KiB
Bash
Raw Normal View History

2023-10-06 03:19:57 +00:00
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
2023-10-11 09:19:38 +00:00
# 监控的文件
2023-10-13 01:29:52 +00:00
FILES="/lib/systemd/system/cockpit.socket /var/lib/docker/volumes/websoft9_apphub_config/_data/config.ini"
2023-10-11 09:19:38 +00:00
cockpit_port="9000"
# 监控文件发生变动时需要做的事情
on_change() {
set +e
2023-10-12 06:31:06 +00:00
# 从配置文件中获取端口号
cockpit_port=$(docker exec -i websoft9-apphub apphub getconfig --section cockpit --key port)
sed -i "s/ListenStream=[0-9]*/ListenStream=${cockpit_port}/" /lib/systemd/system/cockpit.socket
systemctl daemon-reload
systemctl restart cockpit.socket 2> /dev/null
systemctl restart cockpit || exit 1
2023-10-11 09:19:38 +00:00
set_Firewalld
set -e
}
set_Firewalld(){
echo "Set cockpit service to Firewalld..."
sed -i "s/port=\"[0-9]*\"/port=\"$cockpit_port\"/g" /etc/firewalld/services/cockpit.xml 2>/dev/nul
sed -i "s/port=\"[0-9]*\"/port=\"$cockpit_port\"/g" /usr/lib/firewalld/services/cockpit.xml 2>/dev/nul
firewall-cmd --reload 2>/dev/nul
2023-10-11 09:19:38 +00:00
}
2023-10-17 09:42:38 +00:00
# monitor /lib/systemd/system/cockpit.socket and config.ini, make sure config.ini port is the same with cockpit.socket
inotifywait -e modify -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
2023-10-09 08:56:46 +00:00
done
2023-10-17 09:42:38 +00:00