Skip to content

Instantly share code, notes, and snippets.

@xenithorb
Last active February 23, 2017 04:23
Show Gist options
  • Save xenithorb/fe93512746099e2173e5d7f12e7c2527 to your computer and use it in GitHub Desktop.
Save xenithorb/fe93512746099e2173e5d7f12e7c2527 to your computer and use it in GitHub Desktop.
One-liner to enable Rasbperry Pi 3 watchdog timer
if [[ -c /dev/watchdog ]]; then if [[ -d /etc/systemd ]]; then mkdir /etc/systemd/system.conf.d &>/dev/null; else { echo "ERROR: No systemd"; exit; }; fi; echo -e "[Manager]\nRuntimeWatchdogSec=10\nShutdownWatchdogSec=3min" > /etc/systemd/system.conf.d/watchdog.conf; else { echo "No watchdog device present"; exit; }; fi && systemctl daemon-reload && systemctl daemon-reexec && systemctl show | grep Watchdog
@xenithorb
Copy link
Author

xenithorb commented Feb 23, 2017

After it's enabled you can test with a bash or perl forkbomb:

# DO NOT RUN THIS IT WILL CRASH YOUR SYSTEM
:(){ :|:& };:

# Or perl:
perl -e "fork while fork" &

The system at some point should reboot when the watchdog can no longer be contacted for 5 seconds

@xenithorb
Copy link
Author

xenithorb commented Feb 23, 2017

On some tests it took about 4 minutes from the start of the fork bomb as a normal user to hang the system ( this seems to go much quicker as root as I assume due to the fact of not having limits as root. )

Once the system became totally unresponsive to ping it was unreachable for 11 seconds, and came back up immediately. It then showed an uptime of 0min confirming that a reboot occurred.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment