@@ -61,7 +61,6 @@ add_cron()
6161 config_foreach add_overwrite_cron " config_overwrite"
6262
6363 crontab $CRON_FILE
64- start_watchdog
6564}
6665
6766del_cron ()
@@ -677,16 +676,10 @@ check_mod()
677676
678677check_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
0 commit comments