diff --git a/.env b/.env index 628af78..dc59ad0 100644 --- a/.env +++ b/.env @@ -5,5 +5,5 @@ INFLUXDB_BUCKET=Temperaturen INFLUXDB_TOKEN=1wml0Wzrno-VPHxw0N4CSJh42aTAE-zCCAnAj8BLY_YxsmexXO6_8o7i1HDdAPzDUndCCsejWKq9GJXeYFDhpQ== # MQTT -MQTT_USER=dein_user -MQTT_PASS=dein_passwort +MQTT_USER=mqtt_user +MQTT_PASS=mqtt_pw diff --git a/docker-compose.yml b/docker-compose.yml index b309c32..f7c0e6e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,9 @@ version: "3.9" services: + # ------------------------------------------------- + # InfluxDB + # ------------------------------------------------- influxdb: image: influxdb:latest container_name: influxdb @@ -16,6 +19,10 @@ services: timeout: 3s retries: 20 + + # ------------------------------------------------- + # Grafana + # ------------------------------------------------- grafana: image: grafana/grafana:latest container_name: grafana @@ -35,10 +42,16 @@ services: influxdb: condition: service_healthy + + # ------------------------------------------------- + # Mosquitto (MQTT) – User wird beim Start angelegt + # ------------------------------------------------- mqtt5: image: eclipse-mosquitto:latest container_name: mqtt5 restart: unless-stopped + env_file: + - .env ports: - "1883:1883" - "9001:9001" @@ -46,12 +59,31 @@ services: - ./mosquitto/config:/mosquitto/config - ./mosquitto/data:/mosquitto/data - ./mosquitto/log:/mosquitto/log + + command: > + sh -c ' + if [ ! -f /mosquitto/config/passwd ]; then + echo "Creating MQTT user"; + mosquitto_passwd -b /mosquitto/config/passwd "$MQTT_USER" "$MQTT_PASS"; + chmod 600 /mosquitto/config/passwd; + fi && + exec mosquitto -c /mosquitto/config/mosquitto.conf + ' + healthcheck: - test: ["CMD-SHELL", "mosquitto_pub -h localhost -p 1883 -t healthcheck/ping -n >/dev/null 2>&1 || exit 1"] + test: + [ + "CMD-SHELL", + "mosquitto_pub -h localhost -p 1883 -u \"$MQTT_USER\" -P \"$MQTT_PASS\" -q 0 -t healthcheck/ping -n >/dev/null 2>&1 || exit 1" + ] interval: 10s timeout: 5s retries: 12 + + # ------------------------------------------------- + # Telegraf + # ------------------------------------------------- telegraf: image: telegraf:latest container_name: telegraf @@ -71,6 +103,7 @@ services: timeout: 3s retries: 12 + networks: default: name: mqtt5-network diff --git a/mosquitto/config/mosquitto.conf b/mosquitto/config/mosquitto.conf new file mode 100644 index 0000000..bc20e2a --- /dev/null +++ b/mosquitto/config/mosquitto.conf @@ -0,0 +1,5 @@ +listener 1883 +protocol mqtt + +allow_anonymous false +password_file /mosquitto/config/passwd