Monit, docker and httpd port

Issue #133 resolved
Alberto Miorin created an issue

I use supervisor to start monit inside containers, but with docker --net=host I need to manage manually the httpd port with environment variable MONIT_PORT. I would be nice to have a unix socket file alternative to http for the command line tool.

Workaround creating monitrc before starting monit.

#!/usr/bin/env bash

cat <<EOF > /etc/monit/monitrc
set daemon 120
set init
set logfile /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state
set eventqueue
    basedir /var/lib/monit/events
    slots 100
set httpd port ${MONIT_PORT:-2812} and
   use address localhost
   allow localhost
include /etc/monit/conf.d/*

exec 2>&1

rm -f /var/run/
exec /usr/bin/monit -c /etc/monit/monitrc

Comments (8)

  1. Tildeslash repo owner

    Could you elaborate more? How would a Unix Socket solve your problem? A Unix Socket is a hard coded path so won't you need to change this also?

  2. Tildeslash repo owner

    If you bind Monit to localhost only then you should not expose the port, or am I missing something?

    set httpd port 2812 and use address

    Edit: Re-reading your post I guess the problem is, when sharing networking between containers the same localhost will be used by both containers and the port-number matters and also that a unix-socket would solve this. I see your point. If this is a common problem we should solve this. Optionally using unix-socket instead of TCP/localhost for the HTTP interface should not be too hard to implement either.

  3. Tildeslash repo owner

    Hello Alberto,

    we have implemented the unixsocket support for monit httpd, it will be part of next Monit release (5.12).

    Syntax example:

    set httpd
        unixsocket /var/run/monit.sock
        allow myuser:mypassword
  4. Log in to comment