0

I have been creating a prototype using Pi Zeros, they work great at my house but are failing often at customer's site (other side of country).

I do not know if the Pi kernel is crashing or if it's ethernet related.

I have isolated things such as a deticated network, high end power supplies, sd cards but the same issues keeps causing the pi to crash after ~1day.

When the crash occurs I must call customer and ask them to power cycle the device.

I am currently configuring watchdog timer to reset after kernel crash.

But if it is a faulty ethernet driver then what would be a simple (reliable) way to also reset the pi if the ethernet becomes unreachable and/or it can no longer ping the main server?

I could imagine using cron so the pi will attempt to ping the main server every 30 seconds, but I don't know of any method to initiate a restart after ping fails a couple times in a row, and I would love to hear if anyone can suggest some approaches?

Thank you

  • 1
    not likely to be ethernet related - since the zero has no ethernet – Jaromanda X Feb 7 at 23:02
  • I have added a NIC. – Logic1 Feb 7 at 23:02
  • you may want to add some details about the external device if that is the cause of the failure then :p – Jaromanda X Feb 7 at 23:03
  • any method to initiate a restart - there's a command called reboot - that should do it - or you could ifdown eth0; sleep 1; ifup eth0 - see if that brings things up again – Jaromanda X Feb 7 at 23:04
  • 1
    well, you'll want to check periodically, but is every minute often enough? if you need more often then cron is out – Jaromanda X Feb 7 at 23:13
2

Here is a small bash script that you can call with cron, for example every 30 seconds.

#!/bin/bash

COUNT=3
INTERVAL=1

for ((i=COUNT; i>0; i--)); do
    /bin/ping -c1 -n 8.8.8.8 >/dev/null 2>&1
    [ $? -eq 0 ] && exit 0
    sleep $INTERVAL
done
/sbin/reboot

This will look $COUNT times if ping returns without error. If so the script exit immediately successful.

If ping fails $COUNT times in a row the script will reboot the RasPi.

0

Look at Monit which can be configured to monitor and do many things and runs well on the Pi. I've been using it for years on mine.

  • This look really cool, but I can't tell if it could be configured to reboot the pi if the Ethernet becomes unresponsive. Not sure if there would be any services that fail or what it would look for. But network traffic to/from the device definitely does stop and any pings would fail during this time. – Logic1 Feb 8 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.