Linux – Monit network availability checking

interfacelinuxmonitnetworking

I'd like to start a service with monit but only when I have the correct ip bound to the host. Can this be done somehow with the normal config? For example I want to start a process xxx with pidfile xxx.pid, but only if host currently has 10.0.0.1 bound to some interface.

Best Answer

Probably that cannot be done on pure monit.

You can write a shell script that checks if the IP is bound to some interface and only than start service but side effect is that monit will complain that program not started if pid file was not created after monit starts.

UPDATE: You can disable this warnings by adding local alert statement:

 check process myproc with pidfile /var/run/my.pid
   alert foo@bar only on { timeout } 

UPDATE2: Bash script can be something like that (you need to put actual start script as an argument):

#!/usr/bin/env bash

for i in `/sbin/ifconfig -a | grep 'inet addr:' | awk '{print $2}' | sed -e 's/^.*://'` ;do
  if [ "$i" == "10.0.0.1" ] ; then
    $1
  fi
done