What's new

wan-start script also run on wan-stop

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

slytho

Regular Contributor
Hi!

I just found out that /jffs/scripts/wan-start is also run when the wan interface is stopped, e.g. by command 'halt'. I found out by letting this script email me a message when WAN starts (works great), but I also receive the email when I halt the router before power is turned off. A reboot, however, doesn't trigger the script. A minor thing, sure, but maybe there's still a chance to correct it. :) Thank you!
 
Hi!

I just found out that /jffs/scripts/wan-start is also run when the wan interface is stopped, e.g. by command 'halt'. I found out by letting this script email me a message when WAN starts (works great), but I also receive the email when I halt the router before power is turned off. A reboot, however, doesn't trigger the script. A minor thing, sure, but maybe there's still a chance to correct it. :) Thank you!

Similar to nat-start which is always called during a controlled shutdown and I have had to use a services-stop created semaphore for years.:rolleyes:

v384.15 introduces wan-event script, (wan-start will be deprecated in a future release.)
Code:
wan-event      {0 | 1} {stopping | stopped | disconnected | init | connecting | connected}
and I've already migrated to the new event script which will solve your issue.
 
Last edited:
Similar to nat-start which is always called during a controlled shutdown and I have had to use a services-stop created semaphore for years.:rolleyes:

v384.15 introduces wan-event script, (wan-start will be deprecated in a future release.)
Code:
wan-event      {0 | 1} {stopping | stopped | disconnected | init | connecting | connected}
and I've already migrated to the new event script which will solve your issue.
How are you passing your arguments so the wan-event script knows which type of wan-event to run on. Can you throw me a couple of applicable 1 liners as example?
 
How are you passing your arguments so the wan-event script knows which type of wan-event to run on.
The firmware passes the arguments.

I created

/jffs/scripts/wan-event
Code:
#!/bin/sh

#   v384.15 Introduced wan-event script, (wan-start will be deprecated in a future release.)

#          wan-event      {0 | 1} {stopping | stopped | disconnected | init | connecting | connected}
#
Say(){
   echo -e $$ $@ | logger -st "($(basename $0))"
}
SayT(){
   echo -e $$ $@ | logger -t "($(basename $0))"
}
#========================================================================================================================================
#Say "User wan-event running"

scr_name="$(basename $0)"
WAN_IF=$1
WAN_STATE=$2

# Call appropriate script based on script_type
SERVICE_SCRIPT_NAME="wan${WAN_IF}-$WAN_STATE"
SERVICE_SCRIPT_LOG="/tmp/WAN${WAN_IF}_state"

# Execute and log script state
if [[ -f "/jffs/scripts/$SERVICE_SCRIPT_NAME" ]] ; then
    Say "     Script executing.. for wan-event: "$SERVICE_SCRIPT_NAME
    echo "$SERVICE_SCRIPT_NAME" > $SERVICE_SCRIPT_LOG
    sh /jffs/scripts/$SERVICE_SCRIPT_NAME $*
else
    Say "     Script not defined for wan-event: "$SERVICE_SCRIPT_NAME
fi

##@Insert##
So I simply renamed the existing 'wan-start' to 'wan0-connected'

Code:
Jan 20 12:14:02 RT-AC68U (wan-event): 3168 Script not defined for wan-event: wan0-stopping
Jan 20 12:14:06 RT-AC68U (wan-event): 3390 Script not defined for wan-event: wan0-stopped
Jan 20 12:14:06 RT-AC68U (wan-event): 3387 Script not defined for wan-event: wan0-disconnected
Jan 20 12:14:06 RT-AC68U (wan-event): 3388 Script not defined for wan-event: wan0-stopped
Jan 20 12:14:06 RT-AC68U (wan-event): 3423 Script not defined for wan-event: wan0-init
Jan 20 12:14:06 RT-AC68U (wan-event): 3425 Script not defined for wan-event: wan0-connecting
Jan 20 12:14:07 RT-AC68U (wan-event): 3447 Script not defined for wan-event: wan0-disconnected
Jan 20 12:14:08 RT-AC68U (wan-event): 3449 Script not defined for wan-event: wan0-stopped
Jan 20 12:14:09 RT-AC68U (wan-event): 3466 Script executing.. for wan-event: wan0-connected
Jan 20 12:14:09 RT-AC68U (wan0-connected): 3486 Attempting to identify if DUAL-WAN auto-recovery - VDSL Fibre or 3G
Jan 20 12:14:09 RT-AC68U (wan0-connected): 3486 Normal WAN-start event.
Jan 20 12:14:10 RT-AC68U (wan0-connected): 3486 Paused for 30 secs.....
Jan 20 12:14:11 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 29 secs
Jan 20 12:14:12 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 28 secs
<snip>
Jan 20 12:14:34 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 9 secs
Jan 20 12:14:36 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 8 secs
Jan 20 12:14:37 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 7 secs
Jan 20 12:14:38 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 6 secs
Jan 20 12:14:39 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 5 secs
Jan 20 12:14:40 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 4 secs
Jan 20 12:14:41 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 3 secs
Jan 20 12:14:42 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 2 secs
Jan 20 12:14:44 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 1 secs
Jan 20 12:15:38 RT-AC68U (wan0-connected): 3486 WAN Started email being sent.....
Jan 20 12:15:44 RT-AC68U (wan0-connected): 3486 Martineau customisation complete....
 
Last edited:
The firmware passes the arguments.

I created

/jffs/scripts/wan-event
Code:
#!/bin/sh

#   v384.15 Introduced wan-event script, (wan-start will be deprecated in a future release.)

#          wan-event      {0 | 1} {stopping | stopped | disconnected | init | connecting | connected}
#
Say(){
   echo -e $$ $@ | logger -st "($(basename $0))"
}
SayT(){
   echo -e $$ $@ | logger -t "($(basename $0))"
}
#========================================================================================================================================
#Say "User wan-event running"

scr_name="$(basename $0)"
WAN_IF=$1
WAN_STATE=$2

# Call appropriate script based on script_type
SERVICE_SCRIPT_NAME="wan${WAN_IF}-$WAN_STATE"
SERVICE_SCRIPT_LOG="/tmp/WAN${WAN_IF}_state"

# Execute and log script state
if [[ -f "/jffs/scripts/$SERVICE_SCRIPT_NAME" ]] ; then
    Say "     Script executing.. for wan-event: "$SERVICE_SCRIPT_NAME
    echo "$SERVICE_SCRIPT_NAME" > $SERVICE_SCRIPT_LOG
    sh /jffs/scripts/$SERVICE_SCRIPT_NAME $*
else
    Say "     Script not defined for wan-event: "$SERVICE_SCRIPT_NAME
fi

##@Insert##
So I simply renamed the existing 'wan-start' to 'wan0-connected'

Code:
Jan 20 12:14:02 RT-AC68U (wan-event): 3168 Script not defined for wan-event: wan0-stopping
Jan 20 12:14:06 RT-AC68U (wan-event): 3390 Script not defined for wan-event: wan0-stopped
Jan 20 12:14:06 RT-AC68U (wan-event): 3387 Script not defined for wan-event: wan0-disconnected
Jan 20 12:14:06 RT-AC68U (wan-event): 3388 Script not defined for wan-event: wan0-stopped
Jan 20 12:14:06 RT-AC68U (wan-event): 3423 Script not defined for wan-event: wan0-init
Jan 20 12:14:06 RT-AC68U (wan-event): 3425 Script not defined for wan-event: wan0-connecting
Jan 20 12:14:07 RT-AC68U (wan-event): 3447 Script not defined for wan-event: wan0-disconnected
Jan 20 12:14:08 RT-AC68U (wan-event): 3449 Script not defined for wan-event: wan0-stopped
Jan 20 12:14:09 RT-AC68U (wan-event): 3466 Script executing.. for wan-event: wan0-connected
Jan 20 12:14:09 RT-AC68U (wan0-connected): 3486 Attempting to identify if DUAL-WAN auto-recovery - VDSL Fibre or 3G
Jan 20 12:14:09 RT-AC68U (wan0-connected): 3486 Normal WAN-start event.
Jan 20 12:14:10 RT-AC68U (wan0-connected): 3486 Paused for 30 secs.....
Jan 20 12:14:11 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 29 secs
Jan 20 12:14:12 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 28 secs
<snip>
Jan 20 12:14:34 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 9 secs
Jan 20 12:14:36 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 8 secs
Jan 20 12:14:37 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 7 secs
Jan 20 12:14:38 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 6 secs
Jan 20 12:14:39 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 5 secs
Jan 20 12:14:40 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 4 secs
Jan 20 12:14:41 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 3 secs
Jan 20 12:14:42 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 2 secs
Jan 20 12:14:44 RT-AC68U (wan0-connected): 3486 Paused.....resuming in 1 secs
Jan 20 12:15:38 RT-AC68U (wan0-connected): 3486 WAN Started email being sent.....
Jan 20 12:15:44 RT-AC68U (wan0-connected): 3486 Martineau customisation complete....
Thank you! Working fine here :)
 
Did you see in /tmp there is a:
/tmp/WAN0_state file with content: wan0-connected

@Martineau
 
Did you see in /tmp there is a:
/tmp/WAN0_state file with content: wan0-connected

@Martineau
No I wasn't aware that a physical file is created.
Not sure if there is any additional advantage in also having the ability to use say inotifywait to trigger a script based on the existence of the state file(s), but that is the reason why we love the @RMerlin firmware - a cornucopia of features :) - roll on 2-factor GUI logon authentication! ;)
 
v384.15 introduces wan-event script

Fantastic news, I was thinking about this on the bus home as I arrived home to find that again my connection had dropped after the modem dropped the connection and the router doesn't reconnect (argh). Installing the beta now! Probably the first time I've ever really used a beta because I'm so desperate to resolve this issue (my modem drops out every day or so and I lose a day of monitoring data from weather stations and the like each time).
 
Fantastic news, I was thinking about this on the bus home as I arrived home to find that again my connection had dropped after the modem dropped the connection and the router doesn't reconnect (argh). Installing the beta now! Probably the first time I've ever really used a beta because I'm so desperate to resolve this issue (my modem drops out every day or so and I lose a day of monitoring data from weather stations and the like each time).
see my legacy Check WAN script

With v384.15Beta then you can exploit the new wan-event triggers to achieve the same.
 
Awesome - so I should install this script which can hook in to the 384.15 beta FW embedded wan_event script to restart WAN when it detects it's down?
I haven't updated Github (yet) to include information regarding v384.15 compatibility.

However as per the Github page (pre v384.15), you would add the call to Chk_WAN.sh in

/jffs/scripts/wan-start

e.g. to initiate a restart of the WAN if a WAN DOWN condition is detected (rather than initiate a REBOOT).
Code:
sh /jffs/scripts/ChkWAN.sh  wan &

For firmware v384.15+, if/when wan-start is finally deprecated, if you opt to create script wan-event based on my template in post #4 then you would simply add the same call to

/jffs/scripts/wan0-connected
 
I'm sorry I'm so new to this and not a dev, so if I do that the router will reconnect when it detects the WAN is down.
 
I'm sorry I'm so new to this and not a dev, so if I do that the router will reconnect when it detects the WAN is down.
Yes, the WAN interface will be restarted but isn't guaranteed to re-establish the connection.

If restarting the WAN doesn't work, then the script has the option to perform a router REBOOT (beware RT-AC86 users ;))

So currently, whenever the modem drops the connection (cause unknown?) can it always be fixed by REBOOTing the router only?

If the answer is NO, i.e. both the modem and the router need to be rebooted manually, then unfortunately the script will not help, as it cannot alter/reset the state of the modem.
 
I have the RT-86, l only ever need to reset the router the modem seems fine.

So how exactly do I add this to the router. I assume I can just follow your instructions when I get home.
 
The firmware passes the arguments.

I created

/jffs/scripts/wan-event

I'm having issues with VPN which when toggled off, wan disconnects. Reboot fixes but found from here that I can get internet connection back using GUI so saves the hassle to reboot & long wait. Looks like this script may be the solution. Sorry for dumb question but how do I use this script? copy and save as wan-event on jffs. create wan0-connected file but what code to put there?
 
bump any help would help :cool:. Looks like the issue is vpn provider using port 53/80. I've tried another provider using port 1194 and no issues. Any workaround to this?
 

Similar threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top