You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds health-check script to template.
Alters Dockerfile to import health-check script and adds `HEALTHCHECK`
directive.
Updates container documentation to explain behaviour of, and
configuration options for, the health-check agent.
Copy file name to clipboardExpand all lines: docs/Containers/Mosquitto.md
+116Lines changed: 116 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -298,6 +298,10 @@ Replace «username» and «password» with appropriate values, then execute the
298
298
```
299
299
$ docker exec mosquitto mosquitto_passwd -b /mosquitto/pwfile/pwfile hello world
300
300
```
301
+
302
+
Note:
303
+
304
+
* See also [customising health-check](#healthCheckCustom). If you are creating usernames and passwords, you may also want to create credentials for the health-check agent.
## <aname="healthCheck"> Container health check </a>
484
+
485
+
### <aname="healthCheckTheory"> theory of operation </a>
486
+
487
+
A script , or "agent", to assess the health of the Mosquitto container has been added to the *local image* via the *Dockerfile*. In other words, the script is specific to IOTstack.
488
+
489
+
The agent is invoked 30 seconds after the container starts, and every 30 seconds thereafter. The agent:
490
+
491
+
* Publishes a retained MQTT message to the broker running in the same container. The message payload is the current date and time, and the default topic string is:
492
+
493
+
```
494
+
iotstack/mosquitto/healthcheck
495
+
```
496
+
497
+
* Subscribes to the same broker for the same topic for a single message event.
498
+
* Compares the payload sent with the payload received. If the payloads (ie time-stamps) match, the agent concludes that the Mosquitto broker (the process running inside the same container) is functioning properly for round-trip messaging.
* This assumes you are running the command *outside* container-space on the *same* host as your Mosquitto container. If you run this command from *another* host, replace `localhost` with the IP address or domain name of the host where your Mosquitto container is running.
542
+
* The `-p 1883` is the *external* port. You will need to adjust this if you are using a different *external* port for your MQTT service.
543
+
* If you enable authentication for your Mosquitto broker, you will need to add `-u «user»` and `-P «password»` parameters to this command.
544
+
* You should expect to see a new message appear approximately every 30 seconds. That indicates the health-check agent is functioning normally. Use <kbd>control</kbd>+<kbd>c</kbd> to terminate the command.
You can customise the operation of the health-check agent by editing the `mosquitto` service definition in your *Compose* file:
549
+
550
+
1. By default, the mosquitto broker listens to **internal** port 1883. If you need change that port, you also need to inform the health-check agent via an environment variable. For example, suppose you changed the **internal** port to 12345:
551
+
552
+
```yaml
553
+
environment:
554
+
- HEALTHCHECK_PORT=12345
555
+
```
556
+
557
+
2. If the default topic string used by the health-check agent causes a name-space collision, you can override it. For example, you could use a Universally-Unique Identifier (UUID):
* You will also need to use the same topic string in the `mosquitto_sub` command shown at [monitoring health-check](#healthCheckMonitor).
567
+
568
+
3. If you have enabled authentication for your Mosquitto broker service, you will need to provide appropriate credentials for your health-check agent:
569
+
570
+
```yaml
571
+
environment:
572
+
- HEALTHCHECK_USER=healthyUser
573
+
- HEALTHCHECK_PASSWORD=healthyUserPassword
574
+
```
575
+
576
+
4. If the health-check agent misbehaves in your environment, or if you simply don't want it to be active, you can disable all health-checking for the container by adding the following lines to its service definition:
577
+
578
+
```yaml
579
+
healthcheck:
580
+
disable: true
581
+
```
582
+
583
+
Notes:
584
+
585
+
* The directives to disable health-checking are independent of the environment variables. If you want to disable health-checking temporarily, there is no need to remove any `HEALTHCHECK_` environment variables that may already be in place.
586
+
* Conversely, the mere presence of a `healthcheck:` clause in the `mosquitto` service definition overrides the supplied agent. In other words, the following can't be used to re-enable the supplied agent:
0 commit comments