Sync 2026-04-06 15:53:28

This commit is contained in:
github-actions[bot] 2026-04-06 15:53:28 +08:00
parent 89b54f4dae
commit 4c8a301a9b
2 changed files with 50 additions and 21 deletions

View File

@ -1110,7 +1110,7 @@ socks_node_switch() {
}
clean_crontab() {
[ -f "/tmp/lock/${CONFIG}_cron.lock" ] && return
[ -f "${LOCK_PATH}/${CONFIG}_cron.lock" ] && return
touch /etc/crontabs/root
#sed -i "/${CONFIG}/d" /etc/crontabs/root >/dev/null 2>&1
sed -i "/$(echo "/etc/init.d/${CONFIG}" | sed 's#\/#\\\/#g')/d" /etc/crontabs/root >/dev/null 2>&1
@ -1118,7 +1118,7 @@ clean_crontab() {
sed -i "/$(echo "lua ${APP_PATH}/subscribe.lua start" | sed 's#\/#\\\/#g')/d" /etc/crontabs/root >/dev/null 2>&1
pgrep -af "${CONFIG}/" | awk '/tasks\.sh/{print $1}' | xargs kill -9 >/dev/null 2>&1
rm -rf /tmp/lock/${CONFIG}_tasks.lock
rm -f ${LOCK_PATH}/${CONFIG}_tasks.lock
}
start_crontab() {
@ -1127,8 +1127,8 @@ start_crontab() {
[ "$start_daemon" = "1" ] && $APP_PATH/monitor.sh > /dev/null 2>&1 &
fi
[ -f "/tmp/lock/${CONFIG}_cron.lock" ] && {
rm -rf "/tmp/lock/${CONFIG}_cron.lock"
[ -f "${LOCK_PATH}/${CONFIG}_cron.lock" ] && {
rm -f "${LOCK_PATH}/${CONFIG}_cron.lock"
echolog "当前为计划任务自动运行,不重新配置定时任务。"
return
}
@ -1233,7 +1233,7 @@ start_crontab() {
}
stop_crontab() {
[ -f "/tmp/lock/${CONFIG}_cron.lock" ] && return
[ -f "${LOCK_PATH}/${CONFIG}_cron.lock" ] && return
clean_crontab
/etc/init.d/cron restart
#echolog "清除定时执行命令。"
@ -1941,8 +1941,9 @@ stop() {
[ -n "${bak_bridge_nf_ip6t}" ] && sysctl -w net.bridge.bridge-nf-call-ip6tables=${bak_bridge_nf_ip6t} >/dev/null 2>&1
}
rm -rf $TMP_PATH
rm -rf /tmp/lock/${CONFIG}_socks_auto_switch*
rm -rf /tmp/lock/${CONFIG}_lease2hosts*
rm -f ${LOCK_PATH}/${CONFIG}_socks_auto_switch*
rm -f ${LOCK_PATH}/${CONFIG}_lease2hosts*
rm -f ${LOCK_PATH}/${CONFIG}_monitor*
echolog "清空并关闭相关程序和缓存完成。"
exit 0
}

View File

@ -1,31 +1,59 @@
#!/bin/sh
. /usr/share/passwall/utils.sh
DIR="$(cd "$(dirname "$0")" && pwd)"
. $DIR/utils.sh
LOCK_FILE=${LOCK_PATH}/${CONFIG}_monitor.lock
ENABLED=$(config_t_get global enabled 0)
[ "$ENABLED" != 1 ] && return 1
ENABLED=$(config_t_get global_delay start_daemon 0)
[ "$ENABLED" != 1 ] && return 1
MAX_RESTART_COUNT=10
RESTART_STATS_DIR="${TMP_PATH}/script_rstats"
mkdir -p "$RESTART_STATS_DIR"
sleep 58s
while [ "$ENABLED" -eq 1 ]; do
last_cleanup_date=$(date +%Y%m%d)
while [ 1 -eq 1 ]; do
[ -f "$LOCK_FILE" ] && {
sleep 6s
continue
}
touch $LOCK_FILE
for filename in $(ls ${TMP_SCRIPT_FUNC_PATH}); do
cmd=$(cat ${TMP_SCRIPT_FUNC_PATH}/${filename})
cmd_check=$(echo $cmd | awk -F '>' '{print $1}')
[ -n "$(echo $cmd_check | grep "dns2socks")" ] && cmd_check=$(echo $cmd_check | sed "s#:# #g")
icount=$(pgrep -f "$(echo $cmd_check)" | wc -l)
if [ $icount = 0 ]; then
for file in "$TMP_SCRIPT_FUNC_PATH"/*; do
[ -f "$file" ] || continue
IFS= read -r cmd < "$file"
[ -z "$cmd" ] && continue
cmd_check=$(printf '%s' "$cmd" | sed 's/>.*$//;s/[[:space:]]*$//')
case "$cmd_check" in
*dns2socks*) cmd_check=${cmd_check//:/ } ;;
esac
filename=$(basename "$file")
stats_file="${RESTART_STATS_DIR}/${filename}.count"
if [ -s "$stats_file" ]; then
read restart_count < "$stats_file"
[ -z "$restart_count" ] && restart_count=0
else
restart_count=0
fi
# 检查是否超过最大重启次数
[ "$restart_count" -ge "$MAX_RESTART_COUNT" ] && continue
if ! pgrep -f "$cmd_check" >/dev/null; then
restart_count=$((restart_count + 1))
echo "$restart_count" > "$stats_file"
#echo "${cmd} 进程挂掉,重启" >> /tmp/log/passwall.log
eval $(echo "nohup ${cmd} 2>&1 &") >/dev/null 2>&1 &
eval "$cmd 2>&1 &"
sleep 1
fi
done
# 每天清理一次统计文件(跨天后执行一次)
current_date=$(date +%Y%m%d)
if [ "$current_date" != "$last_cleanup_date" ]; then
rm -f "${RESTART_STATS_DIR:?}"/* 2>/dev/null
last_cleanup_date="$current_date"
fi
rm -f $LOCK_FILE
sleep 58s
done