Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion luci-app-openclash/root/etc/init.d/openclash
Original file line number Diff line number Diff line change
Expand Up @@ -3595,7 +3595,7 @@ start_service()
enable=$(uci_get_config "enable")
[ "$enable" != "1" ] && LOG_WARN "OpenClash Now Disabled, Need Start From Luci Page, Exit..." && SLOG_CLEAN && exit 0

if procd_running "openclash" >/dev/null; then
if procd_running "openclash" "openclash" >/dev/null; then
LOG_TIP "OpenClash Already Running, Exit..."
exit 0
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ do
done >/dev/null 2>&1

#check the clash service status
if ! ubus call service list '{"name":"openclash"}' 2>/dev/null | jsonfilter -e '@.openclash.instances.*.running' | grep -q 'true'; then
if ! ubus call service list '{"name":"openclash"}' 2>/dev/null | jsonfilter -e '@.openclash.instances.openclash.running' | grep -q 'true'; then
uci -q set openclash.config.enable=0
uci -q commit openclash
/etc/init.d/openclash stop >/dev/null 2>&1
Expand Down
28 changes: 28 additions & 0 deletions tests/openclash_core_instance_state_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail

REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
INIT_SCRIPT="$REPO_ROOT/luci-app-openclash/root/etc/init.d/openclash"
WATCHDOG="$REPO_ROOT/luci-app-openclash/root/usr/share/openclash/openclash_watchdog.sh"

if sed -n '/start_service()/,/OpenClash Start Running/p' "$INIT_SCRIPT" | grep -F 'if procd_running "openclash" >/dev/null; then' >/dev/null 2>&1; then
echo "start_service still treats any openclash instance as the core process" >&2
exit 1
fi

if ! sed -n '/start_service()/,/OpenClash Start Running/p' "$INIT_SCRIPT" | grep -F 'procd_running "openclash" "openclash"' >/dev/null 2>&1; then
echo "start_service does not check the openclash core instance explicitly" >&2
exit 1
fi

if grep -F '@.openclash.instances.*.running' "$WATCHDOG" >/dev/null 2>&1; then
echo "watchdog still treats any openclash instance as the core process" >&2
exit 1
fi

if ! grep -F '@.openclash.instances.openclash.running' "$WATCHDOG" >/dev/null 2>&1; then
echo "watchdog does not check the openclash core instance explicitly" >&2
exit 1
fi

echo "openclash_core_instance_state_test.sh: PASS"