The past few months I've been suffering from an unreliable adsl line, with some prolonged outages. I've got a 3g stick to fall back onto, but that needed to be enabled manually, so I decided to automate the process (hopefully I'll also remember to top-up the 3g stick!) using ifstated. It turned out to be really simple, but there's a lack of simple examples, so I thought it might be worth publishing.
The config is such that ifstated pings my router address every 10 seconds to make sure it's alive. When ADSL is live this is just a single hop to the router. Should it not get an answer in 5 seconds it will fail over to the 3g connection, if it starts getting an answer form the router (this time over the internet) it will fail back to adsl.
Replace 127.0.0.1 with your adsl ip address and tweak the timings as you see fit.
ping = '( "ping -w 5 -q -c 1 127.0.0.1 > /dev/null" every 10 ) '
state one {
init {
run "logger -p daemon.notice -t ifstated 'Switching to adsl!'"
run "kill `cat /var/run/ppp0.pid`"
}
if ! ( $ping ) {
set-state two
}
}
state two {
init {
run "logger -p daemon.notice -t ifstated 'Switching to threeg!'"
run "pppd call threeg"
}
if ( $ping ) {
set-state one
}
}