Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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
share|improve this answer
1  
Changed update2 script to check all interfaces and made test explicit, not a grep which can false-positive. –  David Mackintosh Dec 24 '09 at 15:45
    
Not perfect, but that's more or less what I'm doing right now. I just wanted monit to actually stop trying to run the process + log failures. –  viraptor Dec 24 '09 at 20:56
    
I wrote with just 'grep' because I have no access to linux machine to get an ifconfig output –  Mike Dec 25 '09 at 12:26
add comment

Old question is old, anyway: you can use guessnet+ifupdown for this.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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