0

I'm trying to make a monit check that reboots my router if it looses network connection. But I do not want it to reboot withing the first 5 minutes after boot, no mater if net is up or down. So far I have this:

CHECK HOST ping-or-nuke ADDRESS 8.8.8.8
  start program = "/bin/sleep 300" with timeout 305 seconds
  if failed ping4 for 4 cycles then exec "/sbin/reboot"
  onreboot start

But it seems to fire the reboot very fast after boot if the net is not there, it "ignores" my attempt to add the 5 minute delay.

I think the check is already in start state when monit loads, but I'm not sure this is the cause.

mogul
  • 111
  • 3

1 Answers1

1

It sounds like you are searching for START DELAY in Deamon Mode. This delays the first checks. So if you can accept all other checks to also delay by this time, this could be used.

If that's not an option, you can write a bridge script to only reboot if uptime is big enough:

#!/bin/bash

if [[ $(awk -F'.' '{ print $1 }' /proc/uptime) -gt 300 ]]; then
  /sbin/reboot
  exit $?
fi

exit 0
boppy
  • 476
  • 2
  • 5
  • Good solution. Just wanted to add, that for the bridge script to work as expected the one may also want to add the `repeat every N cycles` clause, since by default the [exec command](https://mmonit.com/monit/documentation/monit.html#ACTION) is executed only once. – Alex Che Jan 21 '20 at 06:52