Skip to content

Commit 2a8094d

Browse files
committed
fix mosquitto healthcheck
1 parent 44447e8 commit 2a8094d

4 files changed

Lines changed: 22 additions & 5 deletions

File tree

apps/mosquitto/.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
BACKUP_DATABASE_URLS=sqlite:///opt/lib/mosquitto/mosquitto.db
22
TZ=America/Los_Angeles
3+
4+
# Docker HEALTHCHECK: authenticated subscribe to $SYS/broker/uptime (required when allow_anonymous is false).
5+
# Create this user with apps/mosquitto/bin/mkuser.sh (or mosquitto_passwd). If you use acl_file, allow read to $SYS/# for this user.
6+
MOSQUITTO_HEALTHCHECK_USERNAME=
7+
MOSQUITTO_HEALTHCHECK_PASSWORD=

apps/mosquitto/README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@
22

33
Mosquitto provides MQTT service.
44

5-
Configuration file lives in `docker/mosquitto/config/mosquitto.conf`
5+
Configuration file lives in `apps/mosquitto/config/mosquitto.conf` (copy from `mosquitto.conf.example`).
66

7-
Password file lives in `lib/mosquitto/mos_passwd`
7+
Password file lives in `apps/mosquitto/config/mos_passwd` (see `.gitignore`; create with `bin/mkuser.sh`).
88

9-
You may use `docker/mosquitto/bin/mkuser.sh` to add a new user with a strong password to the broker, or run
9+
## Healthcheck (authenticated brokers)
10+
11+
The container healthcheck runs `mosquitto_sub` to `$SYS/broker/uptime`. When **`allow_anonymous false`** (or you use a `password_file` without anonymous access), set in **`.env`**:
12+
13+
- `MOSQUITTO_HEALTHCHECK_USERNAME`
14+
- `MOSQUITTO_HEALTHCHECK_PASSWORD`
15+
16+
Use a dedicated low-privilege MQTT user that exists in `mos_passwd`. If you use **`acl_file`**, that user must be allowed to **subscribe/read** topics under **`$SYS/#`** (or at least `$SYS/broker/uptime`).
17+
18+
Avoid shell metacharacters in the healthcheck password if possible (`$`, `` ` ``, `"`, `\`).
19+
20+
You may use `apps/mosquitto/bin/mkuser.sh` to add a new user with a strong password to the broker, or run
1021
```
1122
docker compose exec mosquitto mosquitto_passwd
1223
```

apps/mosquitto/docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ services:
1313
- 1883:1883
1414
env_file:
1515
- .env
16+
# Auth broker: use MOSQUITTO_HEALTHCHECK_* from .env (must match mos_passwd; needs $SYS read in ACLs if you use acl_file).
1617
healthcheck:
1718
test:
1819
[
1920
"CMD-SHELL",
20-
"mosquitto_sub -h localhost -p 1883 -t '$$SYS/broker/uptime' -C 1 -W 3 || exit 1",
21+
'mosquitto_sub -h localhost -p 1883 -u "$$MOSQUITTO_HEALTHCHECK_USERNAME" -P "$$MOSQUITTO_HEALTHCHECK_PASSWORD" -t "$$SYS/broker/uptime" -C 1 -W 5 || exit 1',
2122
]
2223
interval: 30s
2324
timeout: 10s

docs/apps-compose-healthchecks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This document complements the healthchecks defined under `apps/*/docker-compose.
1111
| App | Check type | Notes |
1212
|-----|------------|--------|
1313
| **postgresql** | `pg_isready` | Cluster accepting connections. |
14-
| **mosquitto** | `mosquitto_sub` on `$SYS/broker/uptime` | **Fails if anonymous subscribers are disabled**; adjust or disable healthcheck if you require auth for all clients. |
14+
| **mosquitto** | `mosquitto_sub` on `$SYS/broker/uptime` with **`MOSQUITTO_HEALTHCHECK_USERNAME` / `MOSQUITTO_HEALTHCHECK_PASSWORD`** from `.env` | Required when anonymous access is disabled; user must exist in `mos_passwd` and (if using ACLs) be allowed `$SYS/#`. |
1515
| **vaultwarden** | HTTP `/alive` | |
1616
| **home-assistant** | HTTP `:8123` | Long `start_period` for first boot. |
1717
| **jellyfin** | HTTP `:8096/health` | |

0 commit comments

Comments
 (0)