Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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, but only if host currently has bound to some interface.

share|improve this question
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/
   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" == "" ] ; then
share|improve this answer
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

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

share|improve this answer

Your Answer


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.