Add update flow, pidfile handling, and systemd unit

This commit is contained in:
wnlen
2026-01-13 23:17:27 +08:00
parent 4861cc40e5
commit 864841ef3c
6 changed files with 392 additions and 37 deletions

View File

@ -1,14 +1,41 @@
#!/bin/bash
# 关闭clash服务
PID_NUM=`ps -ef | grep [c]lash-linux-a | wc -l`
PID=`ps -ef | grep [c]lash-linux-a | awk '{print $2}'`
if [ $PID_NUM -ne 0 ]; then
kill -9 $PID
# ps -ef | grep [c]lash-linux-a | awk '{print $2}' | xargs kill -9
Server_Dir=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
Temp_Dir="$Server_Dir/temp"
PID_FILE="$Temp_Dir/clash.pid"
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if [ -n "$PID" ]; then
kill "$PID"
for i in {1..5}; do
sleep 1
if ! kill -0 "$PID" 2>/dev/null; then
break
fi
done
if kill -0 "$PID" 2>/dev/null; then
kill -9 "$PID"
fi
fi
rm -f "$PID_FILE"
else
PIDS=$(pgrep -f "clash-linux-")
if [ -n "$PIDS" ]; then
kill $PIDS
for i in {1..5}; do
sleep 1
if ! pgrep -f "clash-linux-" >/dev/null; then
break
fi
done
if pgrep -f "clash-linux-" >/dev/null; then
kill -9 $PIDS
fi
fi
fi
# 清除环境变量
> /etc/profile.d/clash.sh
> /etc/profile.d/clash-for-linux.sh
echo -e "\n服务关闭成功请执行以下命令关闭系统代理proxy_off\n"