From 96b00b6f9c8809f2307dafe1492d6bee142857c7 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Fri, 3 Jul 2020 18:19:46 +0200 Subject: [PATCH] Handle APP_KEY and NODE_ID (#91 #93) --- doc/docker/environment-variables.md | 1 + examples/compose/docker-compose.yml | 12 ++++----- examples/pwd/librenms.yml | 30 +++++++++++++++++++-- examples/traefik/docker-compose.yml | 10 +++---- rootfs/etc/cont-init.d/02-fix-perms.sh | 1 + rootfs/etc/cont-init.d/03-config.sh | 12 ++++++++- rootfs/etc/cont-init.d/04-svc-main.sh | 4 +-- rootfs/etc/cont-init.d/05-svc-dispatcher.sh | 8 ++++++ 8 files changed, 60 insertions(+), 18 deletions(-) diff --git a/doc/docker/environment-variables.md b/doc/docker/environment-variables.md index 6906077..8de0c04 100644 --- a/doc/docker/environment-variables.md +++ b/doc/docker/environment-variables.md @@ -18,6 +18,7 @@ > :warning: Only used if you enable and run a [sidecar dispatcher container](../notes/dispatcher-service.md) * `SIDECAR_DISPATCHER`: Set to `1` to enable sidecar dispatcher mode for this container (default `0`) +* `LIBRENMS_SERVICE_NODE_ID`: Unique node ID for your dispatcher service * `LIBRENMS_SERVICE_POLLER_WORKERS`: Processes spawned for polling (default `24`) * `LIBRENMS_SERVICE_SERVICES_WORKERS`: Processes spawned for service polling (default `8`) * `LIBRENMS_SERVICE_DISCOVERY_WORKERS`: Processes spawned for discovery (default `16`) diff --git a/examples/compose/docker-compose.yml b/examples/compose/docker-compose.yml index ced679a..45cb4f7 100644 --- a/examples/compose/docker-compose.yml +++ b/examples/compose/docker-compose.yml @@ -61,7 +61,6 @@ services: librenms: image: librenms/librenms:latest container_name: librenms - domainname: example.com hostname: librenms ports: - target: 8000 @@ -90,8 +89,7 @@ services: dispatcher: image: librenms/librenms:latest container_name: librenms_dispatcher - domainname: example.com - hostname: librenms + hostname: librenms-dispatcher depends_on: - librenms - redis @@ -108,17 +106,17 @@ services: - "DB_USER=${MYSQL_USER}" - "DB_PASSWORD=${MYSQL_PASSWORD}" - "DB_TIMEOUT=60" + - "LIBRENMS_SERVICE_NODE_ID=dispatcher1" - "REDIS_HOST=redis" - "REDIS_PORT=6379" - "REDIS_DB=0" - "SIDECAR_DISPATCHER=1" restart: always - syslog-ng: + syslogng: image: librenms/librenms:latest - container_name: librenms_syslog - domainname: example.com - hostname: librenms + container_name: librenms_syslogng + hostname: librenms-syslogng depends_on: - librenms ports: diff --git a/examples/pwd/librenms.yml b/examples/pwd/librenms.yml index b938002..5dd15d4 100644 --- a/examples/pwd/librenms.yml +++ b/examples/pwd/librenms.yml @@ -109,7 +109,7 @@ services: dispatcher: image: librenms/librenms:edge - hostname: librenms + hostname: librenms-dispatcher-1234 depends_on: - librenms - redis @@ -125,6 +125,32 @@ services: DB_USER: *MYSQL_USER DB_PASSWORD: *MYSQL_PASSWORD DB_TIMEOUT: "60" + LIBRENMS_SERVICE_NODE_ID: "dispatcher1234" + REDIS_HOST: "redis" + REDIS_PORT: "6379" + REDIS_DB: "0" + SIDECAR_DISPATCHER: "1" + restart: always + + dispatcher2: + image: librenms/librenms:edge + hostname: librenms-dispatcher-5678 + depends_on: + - librenms + - redis + volumes: + - "librenms:/data" + environment: + <<: *envlibrenms + TZ: *TZ + PUID: *PUID + PGID: *PGID + DB_HOST: "db" + DB_NAME: *MYSQL_DATABASE + DB_USER: *MYSQL_USER + DB_PASSWORD: *MYSQL_PASSWORD + DB_TIMEOUT: "60" + LIBRENMS_SERVICE_NODE_ID: "dispatcher5678" REDIS_HOST: "redis" REDIS_PORT: "6379" REDIS_DB: "0" @@ -133,7 +159,7 @@ services: syslogng: image: librenms/librenms:edge - hostname: librenms + hostname: librenms-syslogng depends_on: - librenms volumes: diff --git a/examples/traefik/docker-compose.yml b/examples/traefik/docker-compose.yml index 8924007..df5c073 100644 --- a/examples/traefik/docker-compose.yml +++ b/examples/traefik/docker-compose.yml @@ -92,7 +92,6 @@ services: librenms: image: librenms/librenms:latest container_name: librenms - domainname: example.com hostname: librenms depends_on: - db @@ -122,8 +121,7 @@ services: dispatcher: image: librenms/librenms:latest container_name: librenms_dispatcher - domainname: example.com - hostname: librenms + hostname: librenms-dispatcher depends_on: - librenms - redis @@ -140,17 +138,17 @@ services: - "DB_USER=${MYSQL_USER}" - "DB_PASSWORD=${MYSQL_PASSWORD}" - "DB_TIMEOUT=60" + - "LIBRENMS_SERVICE_NODE_ID=dispatcher1" - "REDIS_HOST=redis" - "REDIS_PORT=6379" - "REDIS_DB=0" - "SIDECAR_DISPATCHER=1" restart: always - syslog-ng: + syslogng: image: librenms/librenms:latest container_name: librenms_syslog - domainname: example.com - hostname: librenms + hostname: librenms-syslogng depends_on: - librenms ports: diff --git a/rootfs/etc/cont-init.d/02-fix-perms.sh b/rootfs/etc/cont-init.d/02-fix-perms.sh index f1eefda..e0b290b 100644 --- a/rootfs/etc/cont-init.d/02-fix-perms.sh +++ b/rootfs/etc/cont-init.d/02-fix-perms.sh @@ -7,6 +7,7 @@ mkdir -p /data \ chown librenms. \ /data \ "${LIBRENMS_PATH}" \ + "${LIBRENMS_PATH}/.env" \ "${LIBRENMS_PATH}/html/plugins/Weathermap/output" chown -R librenms. \ /home/librenms \ diff --git a/rootfs/etc/cont-init.d/03-config.sh b/rootfs/etc/cont-init.d/03-config.sh index a2efac6..a9f4d8c 100644 --- a/rootfs/etc/cont-init.d/03-config.sh +++ b/rootfs/etc/cont-init.d/03-config.sh @@ -188,12 +188,22 @@ if [ ! -z "${LIBRENMS_DISTRIBUTED_POLLER_MEMCACHED_HOST}" -a ! -z "${RRDCACHED_H EOL fi - # Fix perms +# Fix perms echo "Fixing perms..." chown librenms. /data/config /data/monitoring-plugins /data/rrd /data/weathermap chown -R librenms. /data/logs ${LIBRENMS_PATH}/config.d ${LIBRENMS_PATH}/bootstrap ${LIBRENMS_PATH}/logs ${LIBRENMS_PATH}/storage chmod ug+rw /data/logs /data/rrd ${LIBRENMS_PATH}/bootstrap/cache ${LIBRENMS_PATH}/storage ${LIBRENMS_PATH}/storage/framework/* +# Handle .env +if [ ! -f "/data/.env" ]; then + artisan key:generate --no-interaction --force + sed -i "s|^NODE_ID=.*|NODE_ID=$(php -r "echo uniqid();")|g" "${LIBRENMS_PATH}/.env" + artisan optimize + cp -f "${LIBRENMS_PATH}/.env" /data/.env +fi +cp -f /data/.env "${LIBRENMS_PATH}/.env" +chown librenms. /data/.env "${LIBRENMS_PATH}/.env" + # Check additional Monitoring plugins echo "Checking additional Monitoring plugins..." mon_plugins=$(ls -l /data/monitoring-plugins | egrep '^-' | awk '{print $9}') diff --git a/rootfs/etc/cont-init.d/04-svc-main.sh b/rootfs/etc/cont-init.d/04-svc-main.sh index 3c7329a..fe332cb 100644 --- a/rootfs/etc/cont-init.d/04-svc-main.sh +++ b/rootfs/etc/cont-init.d/04-svc-main.sh @@ -62,8 +62,8 @@ echo "Updating database schema..." lnms migrate --force --no-ansi --no-interaction echo "Clear cache" -su-exec librenms:librenms php artisan cache:clear --no-interaction -su-exec librenms:librenms php artisan config:cache --no-interaction +artisan cache:clear --no-interaction +artisan config:cache --no-interaction if [ "${counttables}" -eq "0" ]; then echo "Creating admin user..." diff --git a/rootfs/etc/cont-init.d/05-svc-dispatcher.sh b/rootfs/etc/cont-init.d/05-svc-dispatcher.sh index 320efb6..08f3421 100644 --- a/rootfs/etc/cont-init.d/05-svc-dispatcher.sh +++ b/rootfs/etc/cont-init.d/05-svc-dispatcher.sh @@ -29,6 +29,7 @@ DB_USERNAME=${DB_USERNAME:-librenms} DB_TIMEOUT=${DB_TIMEOUT:-60} SIDECAR_DISPATCHER=${SIDECAR_DISPATCHER:-0} +#LIBRENMS_SERVICE_NODE_ID=${LIBRENMS_SERVICE_NODE_ID:-dispatcher1} LIBRENMS_SERVICE_POLLER_WORKERS=${LIBRENMS_SERVICE_POLLER_WORKERS:-24} LIBRENMS_SERVICE_SERVICES_WORKERS=${LIBRENMS_SERVICE_SERVICES_WORKERS:-8} @@ -81,6 +82,13 @@ while ! ${dbcmd} -e "show databases;" > /dev/null 2>&1; do done echo "Database ready!" +# Node ID +if [ -n "$LIBRENMS_SERVICE_NODE_ID" ]; then + echo "NODE_ID: $LIBRENMS_SERVICE_NODE_ID" + sed -i "s|^NODE_ID=.*|NODE_ID=$LIBRENMS_SERVICE_NODE_ID|g" "${LIBRENMS_PATH}/.env" + artisan optimize +fi + # Configuration cat > ${LIBRENMS_PATH}/config.d/dispatcher.php <