mirror of
https://github.com/wnlen/clash-for-linux.git
synced 2026-03-21 22:06:45 +08:00
del
This commit is contained in:
@ -12,6 +12,7 @@ mkdir -p "$RUNTIME_DIR" "$LOG_DIR"
|
||||
FOREGROUND=false
|
||||
DAEMON=false
|
||||
|
||||
# 解析参数
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--foreground) FOREGROUND=true ;;
|
||||
@ -23,6 +24,11 @@ for arg in "$@"; do
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$FOREGROUND" = true ] && [ "$DAEMON" = true ]; then
|
||||
echo "[ERROR] Cannot use both --foreground and --daemon" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ ! -s "$CONFIG_FILE" ]; then
|
||||
echo "[ERROR] runtime config not found: $CONFIG_FILE" >&2
|
||||
exit 2
|
||||
@ -33,22 +39,25 @@ if grep -q '\${' "$CONFIG_FILE"; then
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# 这里先沿用你原来的 resolve_clash.sh
|
||||
# shellcheck disable=SC1091
|
||||
source "$PROJECT_DIR/scripts/get_cpu_arch.sh"
|
||||
# shellcheck disable=SC1091
|
||||
source "$PROJECT_DIR/scripts/resolve_clash.sh"
|
||||
|
||||
CLASH_BIN="$(resolve_clash_bin "$PROJECT_DIR" "${CpuArch:-}")"
|
||||
|
||||
# systemd 模式
|
||||
if [ "$FOREGROUND" = true ]; then
|
||||
write_run_state "running" "systemd"
|
||||
exec "$CLASH_BIN" -f "$CONFIG_FILE" -d "$RUNTIME_DIR"
|
||||
fi
|
||||
|
||||
# script / daemon 模式
|
||||
if [ "$DAEMON" = true ]; then
|
||||
nohup "$CLASH_BIN" -f "$CONFIG_FILE" -d "$RUNTIME_DIR" >>"$LOG_DIR/clash.log" 2>&1 &
|
||||
echo $! > "$PID_FILE"
|
||||
echo "[OK] Clash started in script mode, pid=$(cat "$PID_FILE")"
|
||||
pid=$!
|
||||
echo "$pid" > "$PID_FILE"
|
||||
write_run_state "running" "script" "$pid"
|
||||
echo "[OK] Clash started in script mode, pid=$pid"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
@ -72,8 +72,16 @@ stop_via_script() {
|
||||
fi
|
||||
fi
|
||||
rm -f "$PID_FILE"
|
||||
if [ -f "$PROJECT_DIR/runtime/state.env" ]; then
|
||||
if grep -q '^LAST_RUN_STATUS=' "$PROJECT_DIR/runtime/state.env" 2>/dev/null; then
|
||||
sed -i -E "s/^LAST_RUN_STATUS=.*/LAST_RUN_STATUS=stopped/" "$PROJECT_DIR/runtime/state.env"
|
||||
else
|
||||
echo "LAST_RUN_STATUS=stopped" >> "$PROJECT_DIR/runtime/state.env"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
restart_via_script() {
|
||||
stop_via_script || true
|
||||
start_via_script
|
||||
|
||||
0
scripts/status.sh
Normal file
0
scripts/status.sh
Normal file
0
scripts/stop_clash.sh
Normal file
0
scripts/stop_clash.sh
Normal file
Reference in New Issue
Block a user