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.
Linux – Monit network availability checking
interfacelinuxmonitnetworking
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:
UPDATE2: Bash script can be something like that (you need to put actual start script as an argument):