Skip to content

Commit

Permalink
chore: fix container restart bug & ddns script error
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed May 12, 2024
1 parent 5e78ac9 commit 28e177b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
4 changes: 4 additions & 0 deletions build/dnf_data/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#! /bin/bash

# 清楚mysql sock以及pid文件
rm -rf /var/lib/mysql/mysql.sock
rm -rf /var/lib/mysql/*.pid
rm -rf /var/lib/mysql/*.err
# 清除MONITOR_PUBLIC_IP文件
rm -rf /data/monitor_ip/MONITOR_PUBLIC_IP
# 清理日志
Expand Down
Empty file modified build/dnf_data/monitor_ip/auto_public_ip.sh
100644 → 100755
Empty file.
Empty file modified build/dnf_data/monitor_ip/get_ddns_ip.sh
100644 → 100755
Empty file.
30 changes: 14 additions & 16 deletions build/dnf_data/monitor_ip/monitor_ip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ do
if [ -n "$netbird_ip" ] && [ "$management_status" = "Connected" ] && [ "$signal_status" = "Connected" ]; then
echo "connected to netbird with ip $netbird_ip"
MONITOR_PUBLIC_IP=$netbird_ip
# 将内网IP写入文件中
echo $MONITOR_PUBLIC_IP > /data/monitor_ip/NETBIRD_IP
# 通知其他进程[写入文件]
echo $MONITOR_PUBLIC_IP > /data/monitor_ip/MONITOR_PUBLIC_IP
break
Expand All @@ -48,44 +46,42 @@ do
fi
done

# DDNS等待时间
wait_time=${DDNS_INTERVAL:-10}
# DDNS-域名
while [ -z "$MONITOR_PUBLIC_IP" ] && [ "$DDNS_ENABLE" = true ] && [ -n "$DDNS_DOMAIN" ];
do
old_ip=$(cat /data/monitor_ip/DDNS_IP_RECORD 2>/dev/null || true)
old_ip=$(cat /data/monitor_ip/MONITOR_PUBLIC_IP 2>/dev/null || true)
nslookup_output=$(nslookup -debug $DDNS_DOMAIN 2>/dev/null || true)
ddns_ip=$(echo "$nslookup_output" | awk '/^Address: / { print $2 }')
if [ "$ddns_ip" != "$old_ip" ] ; then
echo "ip changed, old ip is $old_ip, new ip is $ddns_ip"
MONITOR_PUBLIC_IP=$ddns_ip
echo "domain ip changed, old ip is $old_ip, new ip is $ddns_ip"
# 通知其他进程[写入文件]
echo $MONITOR_PUBLIC_IP > /data/monitor_ip/MONITOR_PUBLIC_IP
# 保存本次IP记录
echo "$MONITOR_PUBLIC_IP" > /data/monitor_ip/DDNS_IP_RECORD
echo $ddns_ip > /data/monitor_ip/MONITOR_PUBLIC_IP
# 重启所有频道服务
supervisorctl restart dnf_channel:*
else
echo "domain ip not change, ip is $ddns_ip, wait $wait_time second"
fi
# 等待
wait_time=${DDNS_INTERVAL:-10}
sleep $wait_time
done

# DDNS-IP
while [ -z "$MONITOR_PUBLIC_IP" ] && [ "$DDNS_ENABLE" = true ];
do
old_ip=$(cat /data/monitor_ip/DDNS_IP_RECORD 2>/dev/null || true)
old_ip=$(cat /data/monitor_ip/MONITOR_PUBLIC_IP 2>/dev/null || true)
ddns_ip=$(/data/monitor_ip/get_ddns_ip.sh 2>/dev/null || true)
if [ "$ddns_ip" != "$old_ip" ] ; then
echo "ip changed, old ip is $old_ip, new ip is $ddns_ip"
MONITOR_PUBLIC_IP=$ddns_ip
echo "net ip changed, old ip is $old_ip, new ip is $ddns_ip"
# 通知其他进程[写入文件]
echo $MONITOR_PUBLIC_IP > /data/monitor_ip/MONITOR_PUBLIC_IP
# 保存本次IP记录
echo "$MONITOR_PUBLIC_IP" > /data/monitor_ip/DDNS_IP_RECORD
echo $ddns_ip > /data/monitor_ip/MONITOR_PUBLIC_IP
# 重启所有频道服务
supervisorctl restart dnf_channel:*
else
echo "net ip not change, ip is $ddns_ip, wait $wait_time second"
fi
# 等待
wait_time=${DDNS_INTERVAL:-10}
sleep $wait_time
done

Expand All @@ -95,5 +91,7 @@ if [ -z "$MONITOR_PUBLIC_IP" ]; then
echo "warning!!! empty PUBLIC_IP, exit..."
exit -1
else
# 通知其他进程[写入文件]
echo $MONITOR_PUBLIC_IP > /data/monitor_ip/MONITOR_PUBLIC_IP
echo "success, final ip is $MONITOR_PUBLIC_IP"
fi
10 changes: 9 additions & 1 deletion build/dnf_data/neople/game/start_siroco.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ channel_no=$1
process_sequence=$2
channel_name="siroco$channel_no"

echo "channel_name is $channel_name"
echo "prepare to start ch.$channel_no, process_sequence is $process_sequence"
# 等待bridge启动,最多等待30秒
counter=0
Expand All @@ -26,6 +27,7 @@ do
done
# 获取IP
MONITOR_PUBLIC_IP=$(cat /data/monitor_ip/MONITOR_PUBLIC_IP 2>/dev/null || true)
echo "MONITOR_PUBLIC_IP is $MONITOR_PUBLIC_IP"
# 生成配置文件
rm -rf /data/channel/$channel_name.cfg
cp /home/template/neople/game/cfg/siroco.template /data/channel/$channel_name.cfg
Expand All @@ -35,8 +37,14 @@ sed -i "s/PROCESS_SEQUENCE/$process_sequence/g" /data/channel/$channel_name.cfg
sed -i "s/PUBLIC_IP/$MONITOR_PUBLIC_IP/g" /data/channel/$channel_name.cfg
sed -i "s/DEC_GAME_PWD/$DEC_GAME_PWD/g" /data/channel/$channel_name.cfg
cp /data/channel/$channel_name.cfg /home/neople/game/cfg/$channel_name.cfg
echo "generate $channel_name.cfg success"
# 启动服务
kill -9 $(pgrep -f "df_game_r $channel_name start")
old_pid=$(pgrep -f "df_game_r $channel_name start")
echo "ch.$channel_no old pid is $old_pid"
if [ -n "$old_pid" ]; then
echo "old pid not empty, kill $old_pid"
kill -9 $old_pid
fi
rm -rf pid/$channel_name.pid
LD_PRELOAD=/data/dp/libhook.so ./df_game_r $channel_name start
sleep 2
Expand Down

0 comments on commit 28e177b

Please sign in to comment.