MartineauUK / wireguard

Manage/Install WireGuard on applicable ASUS routers
GNU General Public License v3.0
124 stars 22 forks source link

auto restart the server after internet is down and up again #17

Open luciandf opened 6 days ago

luciandf commented 6 days ago

Hello,

I have a weird one. I have been using this for a long time now. I have an asus ax88u and I am running it from a usb drive. It was working beautifully for years until the usb died and I had to start again. Well this time I notice a weird behavior: I have had the internet connection to the router drop a few times while using wg and when it came back the wg server had to be restarted with option 6 in order to make it work again.

My question is, how to automate this so that it comes back automatically?

MartineauUK commented 6 days ago

Have you tried using the WAN event script to call the [ICODE]wg_server[ICODE] management script?

/jffs/scripts/wan-event

`#!/bin/sh

if [ "$2" == "connected" ];then sleep 5

SERVER="wg21"

sh /jffs/addons/wireguard/wg_server $SERVER disable         # Tear down the appropriate WireGuard server

sh /jffs/addons/wireguard/wg_server $SERVER &           # Initialise the approriate WireGuard server

fi`

luciandf commented 6 days ago

there is no such script at that location! Should it be installed with wgm? I will try your example and see what happens. But I am a bit confused about $2 do I have to give an input to the script?

MartineauUK commented 6 days ago

There is a wealth of information on creating User scripts on the RMerlin wiki https://github.com/RMerl/asuswrt-merlin.ng/wiki to enhance the router functionality. These scripts are not present by default, but there are hints and tips on the various scripts that may be implemented. e.g. here is the Wiki description of the wan-event script https://github.com/RMerl/asuswrt-merlin.ng/wiki/User-scripts#wan-event

MartineauUK commented 6 days ago

"But I am a bit confused about $2 do I have to give an input to the script?"

NO the firmware will provide the appropriate $2 string value as shown in the wan-event Wiki entry

luciandf commented 6 days ago

There is a wealth of information on creating User scripts on the RMerlin wiki https://github.com/RMerl/asuswrt-merlin.ng/wiki to enhance the router functionality. These scripts are not present by default, but there are hints and tips on the various scripts that may be implemented. e.g. here is the Wiki description of the wan-event script https://github.com/RMerl/asuswrt-merlin.ng/wiki/User-scripts#wan-event

Sorry I am thick today but the links point nowhere! I'll keep searching

luciandf commented 6 days ago

RMerlin wiki

nevermind I found them! cheers

luciandf commented 6 days ago

i have added the ChkWAN.sh script and the wan-event which has added an entry in cron that runs the ChkWAN.sh and if there is no service it eventually reboots the router (which I don't like! because the problems I have are never because of the router).

however this has not solved the issue. this morning i tried to connect to wg from work and it didn't work. since I have another route to enter my network i looged into the router ran wgm and used option 6 to restart the wg server. then I could connect.

so my question is:

how can I check if the wg server is running ok and if it isn't use option 6 to make sure I can always connect to wg at home?

MartineauUK commented 4 days ago

Using ChkWAN.sh is a band-aid....meaning if you have a need to use it then you have bigger problems.

So I would suggest that you remove ChkWAN.sh since it clearly does not meet your requirements.

I would then test/debug the wan-event script that I provided above to prove that the script can actually restart the server from the command line.

sh -x /jffs/scripts/wan-event test connected

and post the output.

If the wan-event script does correctly restart the server then you can delve further into identifying if the router can accept incoming connections to the WireGuard server.