From 972002b5374d6f26ab740d1ac9ee2641bf89844b Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Fri, 18 Oct 2024 21:48:16 +0200 Subject: [PATCH] fix mosquitto --- templates/compose/mosquitto.yaml | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/templates/compose/mosquitto.yaml b/templates/compose/mosquitto.yaml index 5f21f395a..e985f3e2d 100644 --- a/templates/compose/mosquitto.yaml +++ b/templates/compose/mosquitto.yaml @@ -7,16 +7,21 @@ services: mosquitto: image: eclipse-mosquitto - restart: unless-stopped environment: - - SERVICE_FQDN_MOSQUITTO - - MQTT_USERNAME=${MQTT_USERNAME} - - MQTT_PASSWORD=${MQTT_PASSWORD} + - SERVICE_FQDN_MOSQUITTO_1883 + - MQTT_USERNAME=${SERVICE_USER_MOSQUITTO} + - MQTT_PASSWORD=${SERVICE_PASSWORD_MOSQUITTO} - REQUIRE_CERTIFICATE=${REQUIRE_CERTIFICATE:-false} - ALLOW_ANONYMOUS=${ALLOW_ANONYMOUS:-true} volumes: - - "./mosquitto/config:/mosquitto/config" - - "./certs:/certs" + - mosquitto-config:/mosquitto/config + - mosquitto-certs:/certs + healthcheck: + test: ["CMD-SHELL", "exit 0"] + interval: 30s + timeout: 10s + retries: 3 + entrypoint: 'sh -c " if [ ''$REQUIRE_CERTIFICATE'' = ''true'' ]; then echo ''listener 8883'' > /mosquitto/config/mosquitto.conf && @@ -28,17 +33,16 @@ services: fi && echo ''require_certificate ''$REQUIRE_CERTIFICATE >> /mosquitto/config/mosquitto.conf && echo ''allow_anonymous ''$ALLOW_ANONYMOUS >> /mosquitto/config/mosquitto.conf && - if [ -n ''$MQTT_USERNAME''] && [ -n ''$MQTT_USERNAME'' ]; then + if [ -n ''$SERVICE_USER_MOSQUITTO''] && [ -n ''$SERVICE_PASSWORD_MOSQUITTO'' ]; then echo ''password_file /mosquitto/config/passwords'' >> /mosquitto/config/mosquitto.conf && touch /mosquitto/config/passwords && chmod 0700 /mosquitto/config/passwords && chown root:root /mosquitto/config/passwords && - mosquitto_passwd -b -c /mosquitto/config/passwords $MQTT_USERNAME $MQTT_PASSWORD && + mosquitto_passwd -b -c /mosquitto/config/passwords $SERVICE_USER_MOSQUITTO $SERVICE_PASSWORD_MOSQUITTO && chown mosquitto:mosquitto /mosquitto/config/passwords; fi && exec mosquitto -c /mosquitto/config/mosquitto.conf "' labels: - - traefik.enable=true - traefik.tcp.routers.mqtt.entrypoints=mqtt - traefik.tcp.routers.mqtts.entrypoints=mqtts