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.
Asked
Active
Viewed 1,626 times
2 Answers
1
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
![](../../users/profiles/6767.webp)
David Mackintosh
- 14,223
- 6
- 46
- 77
![](../../users/profiles/4925.webp)
Mike
- 374
- 1
- 3
- 13
-
1Changed 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