Skip to content

Commit a9d7d8f

Browse files
committed
chore: use post-up for core start
1 parent b23c49d commit a9d7d8f

File tree

4 files changed

+35
-95
lines changed

4 files changed

+35
-95
lines changed

luci-app-openclash/po/es/openclash.es.po

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,8 +1796,8 @@ msgstr "Paso 3: modo de inicio rápido; omitiendo modificación del archivo."
17961796
msgid "Step 4: Start Running The Clash Core..."
17971797
msgstr "Paso 4: Iniciar el núcleo de Clash..."
17981798

1799-
msgid "Step 5: Add Cron Rules, Start Daemons..."
1800-
msgstr "Paso 5: Añadir tareas programadas e iniciar servicios..."
1799+
msgid "Step 5: Add Cron Rules..."
1800+
msgstr "Paso 5: Añadir tareas programadas..."
18011801

18021802
msgid "Step 6: Core Status Checking and Firewall Rules Setting..."
18031803
msgstr "Paso 6: Comprobar estado del núcleo y configurar reglas del firewall..."
@@ -2660,18 +2660,9 @@ msgstr "Google no China"
26602660
msgid "In Fake-ip Mode, Even If This Option is Turned Off, Domain Type Connections Still Pass Through The Core For The Availability"
26612661
msgstr "En modo Fake-IP, incluso desactivado, algunas conexiones de dominio seguirán pasando por el núcleo."
26622662

2663-
msgid "TUN Interface Start Failed, Please Check The Dependence or Try to Restart Again!"
2664-
msgstr "Fallo al iniciar la interfaz TUN; revisa dependencias o intenta reiniciar."
2665-
2666-
msgid "TUN Interface Start Failed, Try to Restart Again..."
2667-
msgstr "Inicio de TUN fallido; intentando reiniciar..."
2668-
26692663
msgid "Core Start Failed, Please Check The Log Infos!"
26702664
msgstr "Fallo al iniciar el núcleo. Revisa el registro de núcleo."
26712665

2672-
msgid "Core Initial Configuration Timeout, Please Check The Log Infos!"
2673-
msgstr "Tiempo de espera agotado en la configuración inicial del núcleo, ¡consulta la información del registro!"
2674-
26752666
msgid "Forced Sniff Pure IP Connections"
26762667
msgstr "Forzar sniffing de conexiones IP puras"
26772668

luci-app-openclash/po/zh-cn/openclash.zh-cn.po

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,7 @@ msgid "Step 4: Start Running The Clash Core..."
17951795
msgstr "第四步: 启动主程序..."
17961796

17971797
msgid "Step 5: Add Cron Rules, Start Daemons..."
1798-
msgstr "第五步: 添加计划任务,启动进程守护程序..."
1798+
msgstr "第五步: 添加计划任务..."
17991799

18001800
msgid "Step 6: Core Status Checking and Firewall Rules Setting..."
18011801
msgstr "第六步: 内核状态检查及防火墙规则设置..."
@@ -2658,18 +2658,9 @@ msgstr "Google 非送中"
26582658
msgid "In Fake-ip Mode, Even If This Option is Turned Off, Domain Type Connections Still Pass Through The Core For The Availability"
26592659
msgstr "在 Fake-IP 模式时,即使关闭此选项,域名类型的连接可能仍将通过核心以保证可用性"
26602660

2661-
msgid "TUN Interface Start Failed, Please Check The Dependence or Try to Restart Again!"
2662-
msgstr "TUN 接口启动失败,请检查依赖情况或稍后重试!"
2663-
2664-
msgid "TUN Interface Start Failed, Try to Restart Again..."
2665-
msgstr "TUN 接口启动失败,尝试重启内核..."
2666-
26672661
msgid "Core Start Failed, Please Check The Log Infos!"
26682662
msgstr "内核启动失败,请查看《内核日志》排查失败原因!"
26692663

2670-
msgid "Core Initial Configuration Timeout, Please Check The Log Infos!"
2671-
msgstr "内核加载配置超时,请查看《内核日志》排查原因!"
2672-
26732664
msgid "Forced Sniff Pure IP Connections"
26742665
msgstr "强制探测(嗅探)所有纯 IP 的连接"
26752666

luci-app-openclash/root/etc/init.d/openclash

Lines changed: 32 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ add_cron()
6161
config_foreach add_overwrite_cron "config_overwrite"
6262

6363
crontab $CRON_FILE
64-
start_watchdog
6564
}
6665

6766
del_cron()
@@ -677,16 +676,10 @@ check_mod()
677676

678677
check_core_status()
679678
{
680-
TUN_WAIT=0
681-
TUN_RESTART=1
682-
CORE_WAIT=0
683-
CORE_HTTP_CODE=0
684-
685-
while ( [ -z "$(pidof clash)" ] && [ "$CORE_WAIT" -le 10 ] )
686-
do
687-
sleep 1
688-
let CORE_WAIT++
689-
done
679+
if [ -z "$(pidof clash)" ]; then
680+
LOG_ERROR "Core Start Failed, Please Check The Log Infos!"
681+
start_fail
682+
fi
690683

691684
if [ -n "$en_mode_tun" ] || [ "$ipv6_mode" -eq 2 ] || [ "$ipv6_mode" -eq 3 ]; then
692685
check_mod "tun"
@@ -697,66 +690,24 @@ check_core_status()
697690
ip_="ip -6"
698691
fi
699692

700-
#wait 300s most for core start
701-
while ( [ -n "$(pidof clash)" ] && [ -z "$($ip_ route list |grep utun)" ] && [ "$TUN_WAIT" -le 300 ] )
693+
$ip_ link set utun up
694+
695+
while ( [ -n "$(ip -6 rule show |grep 2022)" ] )
702696
do
703-
$ip_ link set utun up
704-
let TUN_WAIT++
705-
sleep 1
697+
ip -6 rule del oif utun table 2022
698+
ip -6 route del default dev utun table 2022
706699
done
707700

708-
if [ -n "$(pidof clash)" ] && [ -z "$($ip_ route list |grep utun)" ] && [ "$TUN_WAIT" -gt 300 ]; then
709-
while ( [ -n "$(pidof clash)" ] && [ -z "$($ip_ route list |grep utun)" ] && [ "$TUN_RESTART" -le 3 ] )
710-
do
711-
LOG_WARN "TUN Interface Start Failed, Try to Restart Again..."
712-
start_run_core
713-
let TUN_RESTART++
714-
sleep 300
715-
done
716-
if [ -n "$(pidof clash)" ] && [ -z "$($ip_ route list |grep utun)" ] && [ "$TUN_RESTART" -gt 3 ]; then
717-
LOG_ERROR "TUN Interface Start Failed, Please Check The Dependence or Try to Restart Again!"
718-
LOG_ERROR "Core Initial Configuration Timeout, Please Check The Log Infos!"
719-
start_fail
720-
fi
701+
if [ "$ipv6_mode" -eq 2 ] || [ "$ipv6_mode" -eq 3 ]; then
702+
ip -6 route add default dev utun table "$PROXY_ROUTE_TABLE"
703+
ip -6 rule add fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" pref 1888
721704
fi
722705

723-
if [ -n "$(pidof clash)" ]; then
724-
while ( [ -n "$(pidof clash)" ] && [ -n "$(ip -6 rule show |grep 2022)" ] && [ "$CORE_WAIT" -le 10 ] )
725-
do
726-
ip -6 rule del oif utun table 2022
727-
ip -6 route del default dev utun table 2022
728-
let CORE_WAIT++
729-
done
730-
if [ "$ipv6_mode" -eq 2 ] || [ "$ipv6_mode" -eq 3 ]; then
731-
ip -6 route add default dev utun table "$PROXY_ROUTE_TABLE"
732-
ip -6 rule add fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" pref 1888
733-
fi
734-
if [ -n "$en_mode_tun" ]; then
735-
ip route add default dev utun table "$PROXY_ROUTE_TABLE"
736-
ip rule add fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" pref 1888
737-
fi
738-
fi
739-
else
740-
reg4='^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$'
741-
while ( [ -n "$(pidof clash)" ] && [ "$CORE_HTTP_CODE" != "200" ] && [ "$TUN_WAIT" -le 300 ] && [ -n "$(echo ${lan_ip} | grep -Eo ${reg4})" ] )
742-
do
743-
CORE_HTTP_CODE=$(curl -m 5 -o /dev/null -s -w '%{http_code}' -H 'Content-Type: application/json' -H "Authorization: Bearer ${da_password}" -XGET http://${lan_ip}:${cn_port}/group)
744-
let TUN_WAIT++
745-
sleep 1
746-
done
747-
if [ -z "$(echo ${lan_ip} | grep -Eo ${reg4})" ]; then
748-
LOG_ERROR "LAN IP Address Get Error, Please Check The LAN Interface Setting or Choose the Correct Interface in the Setting!"
749-
start_fail
750-
fi
751-
if [ -n "$(pidof clash)" ] && [ "$CORE_HTTP_CODE" != "200" ]; then
752-
LOG_ERROR "Core Initial Configuration Timeout, Please Check The Log Infos!"
753-
start_fail
706+
if [ -n "$en_mode_tun" ]; then
707+
ip route add default dev utun table "$PROXY_ROUTE_TABLE"
708+
ip rule add fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" pref 1888
754709
fi
755710
fi
756-
if [ -z "$(pidof clash)" ]; then
757-
LOG_ERROR "Core Start Failed, Please Check The Log Infos!"
758-
start_fail
759-
fi
760711

761712
# redirect dns setting after core started, prevent core dns lookup failure
762713
if [ "$1" == "start" ]; then
@@ -785,6 +736,7 @@ start_run_core()
785736
chown root:root "$CLASH"
786737
procd_open_instance "openclash"
787738
procd_set_param env SAFE_PATHS=/usr/share/openclash:/etc/ssl
739+
procd_append_param env CLASH_POST_UP="/etc/init.d/openclash reload start"
788740
procd_set_param command /bin/sh -c "$CLASH -d $CLASH_CONFIG -f \"$CONFIG_FILE\" >> $LOG_FILE 2>&1"
789741
procd_set_param user "root"
790742
procd_set_param group "nogroup"
@@ -3740,6 +3692,12 @@ get_config()
37403692
lan_ip=$(ip address show $lan_interface_name 2>/dev/null | grep -w "inet" 2>/dev/null | grep -Eo 'inet [0-9\.]+' | awk '{print $2}' | head -1 | tr -d '\n')
37413693
fi
37423694

3695+
reg4='^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$'
3696+
if [ -z "$(echo ${lan_ip} | grep -Eo ${reg4})" ]; then
3697+
LOG_ERROR "LAN IP Address Get Error, Please Check The LAN Interface Setting or Choose the Correct Interface in the Setting!"
3698+
start_fail
3699+
fi
3700+
37433701
wan_ip4s=$(/usr/share/openclash/openclash_get_network.lua "wanip" 2>/dev/null)
37443702
wan_ip6s=$(ifconfig | grep 'inet6 addr' | awk '{print $3}' 2>/dev/null)
37453703
log_level=$(uci_get_config "log_level")
@@ -3906,11 +3864,10 @@ start_service()
39063864
LOG_OUT "Step 4: Start Running The Clash Core..."
39073865
start_run_core
39083866

3909-
LOG_OUT "Step 5: Add Cron Rules, Start Daemons..."
3867+
LOG_OUT "Step 5: Add Cron Rules..."
39103868
add_cron
39113869

39123870
LOG_OUT "Step 6: Core Status Checking and Firewall Rules Setting..."
3913-
check_core_status "start" &
39143871

39153872
if [ "$ipv6_enable" -eq 0 ] && [ "$(uci -q get dhcp.lan.dhcpv6)" != "disabled" ] && [ -n "$(uci -q get dhcp.lan.dhcpv6)" ]; then
39163873
LOG_WARN "Please Note That Network May Abnormal With IPv6's DHCP Server"
@@ -4013,6 +3970,13 @@ reload_service()
40133970
{
40143971
get_config
40153972
MAX_RELOAD=10
3973+
3974+
if [ "$1" = "start" ]; then
3975+
check_core_status "start"
3976+
start_watchdog
3977+
return
3978+
fi
3979+
40163980
if pidof clash >/dev/null && [ "$enable" == "1" ] && [ "$1" == "firewall" ]; then
40173981
#sleep for avoiding system unready
40183982
sleep 5
@@ -4038,13 +4002,13 @@ reload_service()
40384002
LOG_OUT "${CUR_RELOAD_NUM}/$MAX_RELOAD】Reload OpenClash Firewall Rules..."
40394003
revert_firewall
40404004
do_run_mode
4041-
check_core_status &
4005+
check_core_status
40424006
fi
40434007
if pidof clash >/dev/null && [ "$enable" == "1" ] && [ "$1" == "manual" ]; then
40444008
LOG_OUT "Manually Reload Firewall Rules..."
40454009
revert_firewall
40464010
do_run_mode
4047-
check_core_status &
4011+
check_core_status
40484012
fi
40494013
if pidof clash >/dev/null && [ "$enable" == "1" ] && [ "$1" == "revert" ]; then
40504014
revert_firewall

luci-app-openclash/root/usr/share/openclash/openclash_watchdog.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,6 @@ do
173173
stream_auto_select_openai=$(uci_get_config "stream_auto_select_openai" || echo 0)
174174
upnp_lease_file=$(uci -q get upnpd.config.upnp_lease_file)
175175

176-
#wait for core start complete
177-
while ( [ -n "$(unify_ps_pids "/etc/init.d/openclash")" ] )
178-
do
179-
sleep 1
180-
done >/dev/null 2>&1
181-
182176
#check the clash service status
183177
if ! ubus call service list '{"name":"openclash"}' 2>/dev/null | jsonfilter -e '@.openclash.instances.*.running' | grep -q 'true'; then
184178
uci -q set openclash.config.enable=0

0 commit comments

Comments
 (0)