make Monit's "check process" work conditionally based on an env variable

Issue #180 new
dmitry babitsky created an issue
I would like to make Monit's "check process" work conditionally based on an env variable.

Here's the pseudo-code of what I would like to achieve(not a valid monit config syntax):

[ -n "$run_foo" ] && check process foo ....
My use case: I have a docker image that starts monit process like this:

CMD ["/bin/monit", "-c","/config/monit.conf"]
Monit then starts various daemons.

Now, I would like to be able to tell at run time which daemons I want to start in a particular container created from this image, like this:

docker run --env="run_foo=1;run_bar=1" ...
I am aware of monit unmonitor, and similar args, however I believe they don't serve my purpose.

Thought about something like this:

start program="/bin/bash -c '[ -n \"$run_foo\" ] && /bin/foo .."
However, seems like it will cause monit to spin continuously trying to start and monitor things that shouldn't be started.

I am aware of possibility of using different monit config files, or using different docker images - these don't qualify as an answer.

http://serverfault.com/questions/676227/how-to-make-monit-check-process-conditional-inside-docker-based-on-docker-run

Comments (2)

  1. dmitry babitsky reporter

    I use monit as the main process inside docker container. How would I use ansible for this purpose and what's ssh have to do in this context?

  2. dmitry babitsky reporter

    Aaron, based on your answers, I probably didnt explain properly what I'm trying to achieve because we are having miscommunication. I'm not trying to manage containers, which is what ansible does(look at their example). I'm trying to control what should run inside the container, out of several things, at the time I start it ( by docker run) I dont see how ansible could do it. Unless you suggest starting a container with nothing running, and then dynamically connect to it with ssh, edit monit config file (or create a new one) and reload it. But that would be a terrible solution, imho. Passing arguments at docker run time sounds a lot cleaner. Thanks, and apologies if I misunderstood.

  3. Log in to comment