diff --git a/Dockerfile b/Dockerfile index 83265b1..f20d6c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,21 +7,27 @@ ARG mmonit_url=https://mmonit.com/dist/mmonit-${mmonit_version}-linux-${mmonit_a ENV \ MMONIT_VERSION=$mmonit_version \ - MMONIT_DATAABSE_URL= \ + MMONIT_DATABASE_URL= \ MMONIT_LICENSE_OWNER= \ MMONIT_LICENSE_KEY= \ MMOUNT_DATABASE_URL= \ MMONIT_LIMIT_FD=4096 \ MMONIT_TLS_VERSION= \ + MMONIT_DATABASE_MIN_CON= \ + MMONIT_DATABASE_MAX_CON= \ + MMONIT_PROXY_SCHEME= \ + MMONIT_PROXY_NAME= \ + MMONIT_PROXY_PORT= \ + MMONIT_SESSION_TIMEOUT= \ TZ=UTC WORKDIR /opt # Set up RUN \ -echo "*** install utilities needed ****" && \ + echo "*** install utilities needed ****" && \ apt-get update && \ - apt-get upgrade -y && \ + apt-get upgrade -y && \ apt-get -y install rsync xmlstarlet && \ rm -rf /var/lib/apt/lists/* && \ echo "*** install M/Monit ***" && \ diff --git a/README.md b/README.md index af5eef7..0ce1c0e 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Compatible with docker-compose v2 schemas. --- version: "2" services: - monit: + mmonit: image: jchonig/mmonit container_name: mmonit environment: @@ -53,17 +53,23 @@ services: ## Environment Variables (-e) -| Env | Function | -| --- | -------- | -| PUID=1000 | for UserID - see below for explanation | -| PGID=1000 | for GroupID - see below for explanation | -| TZ=UTC | Specify a timezone to use EG UTC | -| MMONIT_VERSION | The version of M\/Monit to build | -| MMONIT_LICENSE_OWNER | Owner name from M\/Monit license | -| MMONIT_LICENSE_KEY | Text of the M/Monit license | -| MMONIT_DATABASE_URL | URL to access the M\/Monit database | -| MMONIT_LIMIT_FD | Override the default of 4096 | -| MMONIT_TLS_VERSION | Override the TLS version | +| Env | Function | +| --- | -------- | +| PUID=1000 | for UserID - see below for explanation | +| PGID=1000 | for GroupID - see below for explanation | +| TZ=UTC | Specify a timezone to use EG UTC | +| MMONIT_VERSION | The version of M\/Monit to build | +| MMONIT_LICENSE_OWNER | Owner name from M\/Monit license | +| MMONIT_LICENSE_KEY | Text of the M/Monit license | +| MMONIT_DATABASE_URL | URL to access the M\/Monit database | +| MMONIT_DATABASE_MIN_CON | Minimum number of database connections to use | +| MMONIT_DATABASE_MAX_CON | Maximum number to database connections to use | +| MMONIT_LIMIT_FD | Override the default of 4096 | +| MMONIT_SESSION_TIMEOUT | Override the default session timeout of 1800 (in seconds) | +| MMONIT_TLS_VERSION | Override the TLS version | +| MMONIT_PROXY_SCHEME | Set HTTP scheme used by frontend reverse proxy (optional, "http" or "https") | +| MMONIT_PROXY_NAME | Set HTTP server DNS name used by frontend reverse proxy (optional) | +| MMONIT_PROXY_PORT | Set HTTP port used by frontend reverse proxy (optional) | ## Volume Mappings (-v) @@ -85,6 +91,35 @@ services: * The container will automatically run the M/Monit upgrade script if */config/version* indicates an older version was last run. +# Running behind a HTTP reverse proxy + +To run this docker image behind a HTTP reverse proxy like Apache or NGinx change the `expose` setting inside the +`docker-compose.yml` to `ports` to export these to be reachable by the docker host and (optionally) configure the +`MMONIT_PROXY_` env vars as needed. The desciption and some Apache/Nginx configuration examples are documented +in the M/Monit documentation available at https://mmonit.com/documentation/mmonit_manual.pdf - Chapter +"M/Monit behind a proxy". + +``` +--- +version: "2" +services: + mmonit: + image: jchonig/mmonit + container_name: mmonit + environment: + - PUID=1000 + - PGID=1000 + - TZ=Europe/London + - MMONIT_LICENSE_OWNER="Fred" + - MMONIT_LICENSE_KEY="" + - MMONIT_PROXY_SCHEME=https + volumes: + - :/config + ports: + - 8080:8080 + restart: unless-stopped +``` + ## TODO * Facilitate setup of a database other than sqlite3. diff --git a/root/etc/cont-init.d/50-config b/root/etc/cont-init.d/50-config index 049d87a..b222454 100644 --- a/root/etc/cont-init.d/50-config +++ b/root/etc/cont-init.d/50-config @@ -61,6 +61,43 @@ if [ -n "${MMONIT_DATABASE_URL}" ]; then xmlstarlet edit --inplace -u "/Server/Service/Engine/Realm/@url" -v "${MMONIT_DATABASE_URL}" /config/mmonit-${MMONIT_VERSION}/conf/server.xml fi +# minimum number of database connections to keep open +if [ -n "${MMONIT_DATABASE_MIN_CON}" ]; then + echo Setting database pool minimum connections count + xmlstarlet edit --inplace -u "/Server/Service/Engine/Realm/@minConnections" -v "${MMONIT_DATABASE_MIN_CON}" /config/mmonit-${MMONIT_VERSION}/conf/server.xml +fi + +# maximum number of database connections to use +if [ -n "${MMONIT_DATABASE_MAX_CON}" ]; then + echo Setting database pool maximum connenction count + xmlstarlet edit --inplace -u "/Server/Service/Engine/Realm/@maxConnections" -v "${MMONIT_DATABASE_MAX_CON}" /config/mmonit-${MMONIT_VERSION}/conf/server.xml +fi + +# Update http connector to add explicit "proxyScheme" if http scheme differs between reverse proxy and m/monit connector +if [ -n "${MMONIT_PROXY_SCHEME}" ]; then + echo Setting frontend proxy server scheme + xmlstarlet edit --inplace -a "/Server/Service/Connector" -t attr -n proxyScheme -v "${MMONIT_PROXY_SCHEME}" /config/mmonit-${MMONIT_VERSION}/conf/server.xml +fi + +# set explicit host name as used by frontend reverse proxy to create correct redirects +if [ -n "${MMONIT_PROXY_NAME}" ]; then + echo Setting frontend proxy server dns name + xmlstarlet edit --inplace -a "/Server/Service/Connector" -t attr -n proxyName -v "${MMONIT_PROXY_NAME}" /config/mmonit-${MMONIT_VERSION}/conf/server.xml +fi + +# set explicit http port as used by frontend reverse proxy to create correct redirects +if [ -n "${MMONIT_PROXY_PORT}" ]; then + echo Setting frontend proxy server port + xmlstarlet edit --inplace -a "/Server/Service/Connector" -t attr -n proxyPort -v "${MMONIT_PROXY_PORT}" /config/mmonit-${MMONIT_VERSION}/conf/server.xml +fi + +# Set session timeout (default 1800s) +if [ -n "${MMONIT_SESSION_TIMEOUT}" ]; then + echo Setting session timeout + xmlstarlet edit --inplace -u "/Server/Service/Engine/Host/Context/@sessionTimeout" -v "${MMONIT_SESSION_TIMEOUT}" /config/mmonit-${MMONIT_VERSION}/conf/server.xml +fi + + if [ -n "${MMONIT_TLS_VERSION}" ]; then echo Setting TLS version xmlstarlet edit --inplace \