Перезагрузка pfSense при недоступности хоста

pfSense: Auto reboot if Internet connection lost

I use pfSense as both my router and my firewall.  If the ADSL line drops, normally it will come back up a minute later with no problem. But a few times per year, the ADSL line comes back up in a funny state, and I end up having to reboot the pfSense box manually to recover.  So, we can run a script from cron to fix that…
Based on a great post here on the pfSense forums…

1. Login to pfsense with serial console or SSH (you may need to enable SSH in the web GUI first). Then  select «8» for shell command.2. To remount file systems as read-write, run: /etc/rc.conf_mount_rw

3. Use vi editor to create /usr/local/bin/ping_check.sh  as follows…

#!/bin/sh
# First sleep for 6 mins so that we don’t run this code if box has only just booted and PPPoE not up yet.
/bin/sleep 360

# Try 12 mins worth of very short pings to googles DNS servers…
# Quit immediately if we get a single frame back.
# If neither server responds at all then reboot the firewall.
# Otherwise, flip WAN interface up and down again and try again.
# Use conservative timers so that we don’t reboot unless outage lasts more than 20 minutes.
# Also we don’t reboot more than a couple of times per hour.
# This is to counter risk of box getting in funny state during reboot cycle and needing power cycling…

counting=$(/sbin/ping -o -s 0 -c 360 8.8.8.8 | /usr/bin/grep ‘received’ | /usr/bin/awk -F’,’ ‘{ print $2 }’ | /usr/bin/awk ‘{ print $1 }’ )
if [ $counting -eq 0 ]; then

counting=$(/sbin/ping -o -s 0 -c 360 8.8.4.4 | /usr/bin/grep ‘received’ | /usr/bin/awk -F’,»{ print $2 }’ | /usr/bin/awk ‘{ print $1 }’ )
if [ $counting -eq 0 ]; then

# network down
# Try flipping WAN NIC in the hope that will trigger BT modem to reconnect properly …
/sbin/ifconfig vr3 down
/bin/sleep 10
/sbin/ifconfig vr3 up
/bin/sleep 60

counting=$(/sbin/ping -o -s 0 -c 360 8.8.8.8 | /usr/bin/grep ‘received’ | /usr/bin/awk -F’,’ ‘{ print $2 }’ | /usr/bin/awk ‘{ print $1 }’ )
if [ $counting -eq 0 ]; then

counting=$(/sbin/ping -o -s 0 -c 360 8.8.4.4 | /usr/bin/grep ‘received’ | /usr/bin/awk -F’,’ ‘{ print $2 }’ | /usr/bin/awk ‘{ print $1 }’ )
if [ $counting -eq 0 ]; then

# network STILL down
/etc/rc.stop_packages
/etc/rc.reboot

fi
fi
fi
fi

4. chmod +x /usr/local/bin/ping_check.sh

5. To mount as read-only again, run: /etc/rc.conf_mount_ro
Now you need to add a cron job to automatically run this every 10 minutes.

6. Go into pfSense web interface — and select:
— Packages (under System)
— Cron (0.1.8 is what I found when writing this)
— Select «+» and install Cron.

7. Then go into Cron (under Services)

8. Click «+» and add

minute:  */10      (if you want to run every 10 minutes)
hours:    *
mday:    *
month:   *
wday:     *
(who):   root
command:   /usr/local/bin/ping_check.sh

Click «Save»

Thats it!

Test by unplugging your ADSL line. The box should reboot after about 30 minutes or so.  You could adjust the timings but I didn’t want my box rebooting more than a few times per hour at most.  And I wanted the auto reboot to happen slowly enough that I have time to get in and administer the firewall, if the ADSL line is dead (and maybe I want to set up a 3G cellular backup connection).

Источник: http://blog.martinshouse.com/2014/06/pfsense-auto-reboot-if-internet.html
https://forum.netgate.com/topic/83591/перезагрузка-pfsense-при-недоступности-хоста