108.3. mosquitto-2.1.2
MQTT broker and the mosquitto_pub and mosquitto_sub clients
| Version | 2.1.2, release 1 |
| Shelf | servers — Daemons that serve other machines: remote shell, web, mail, XMPP, IRC, CalDAV/CardDAV, SMB and DLNA |
| Phase | 41_system (System), 941 of 1047 in build order |
| Licence | EPL-2.0 OR BSD-3-Clause |
| Homepage | https://mosquitto.org/ |
| Build time | 0.5 SBU |
| Installed size | 2.5 MiB in 80 files |
| Recipe | ports/core/servers/mosquitto/kpkgbuild |
About
Eclipse Mosquitto is an MQTT broker, the publish-and-subscribe message server that sensors, microcontrollers and home-automation devices report to, with the mosquitto_pub and mosquitto_sub clients, libmosquitto, and mosquitto_ctrl for administering a running broker. A broker on the machine makes a sensor network testable with no cloud account. The package adds a service script, 73_mosquitto, which runs the broker under the supervisor once /etc/mosquitto/mosquitto.conf exists and is not empty; see Services.
Why it is in KDOS
The comment above it in script/phases/41_system/packages.d/servers.txt:
A broker on the machine is what makes a sensor network testable without a cloud account, which is the whole point on a distro that builds offline.
Sources
mosquitto-2.1.2.tar.gz(2.6 MiB)
sha25620e998aae86d1629e787a924c044bb912d21ac8f5d1c1b707f2af06eb4c6016d
upstream: https://github.com/eclipse-mosquitto/mosquitto/archive/refs/tags/v2.1.2.tar.gz
archive copy: sources-4/servers--mosquitto-2.1.2.tar.gz
Dependencies
Depends on: cmake, openssl, cjson, libxslt, docbook-xsl, libmicrohttpd, sqlite, libedit.
Required by: no port names it.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install mosquitto'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/servers/mosquitto.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/servers/mosquitto
echo '20e998aae86d1629e787a924c044bb912d21ac8f5d1c1b707f2af06eb4c6016d mosquitto-2.1.2.tar.gz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/mosquitto
SRC=$SRC_ROOT/mosquitto-2.1.2
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf mosquitto-2.1.2.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
mkdir -p build && cd build
cmake .. -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib \
-DCMAKE_INSTALL_SYSCONFDIR=/etc \
-DWITH_WEBSOCKETS=ON -DWITH_WEBSOCKETS_BUILTIN=ON \
-DWITH_DOCS=ON -DWITH_TESTS=OFF \
-DWITH_TLS=ON \
-DWITH_HTTP_API=ON -DHTTP_API_DIR= \
-DWITH_PLUGIN_PERSIST_SQLITE=ON \
-DWITH_CTRL_SHELL=ON \
-DWITH_PLUGIN_EXAMPLES=OFF \
-DWITH_SYSTEMD=OFF -DWITH_SRV=OFF -DWITH_DLT=OFF
make
make DESTDIR=$PKG install
install -dm755 "$PKG/var/lib/mosquitto"
install -d "$PKG/etc/init.d"
cat > "$PKG/etc/init.d/73_mosquitto.sh" <<'KDOS_SH'
#!/bin/bash
. /etc/init.d/service_helper
NAME="mosquitto"
DAEMON="/usr/sbin/mosquitto"
CONF="/etc/mosquitto/mosquitto.conf"
case "$1" in
start)
[ ! -x "$DAEMON" ] && { echo "[SKIP] $NAME: $DAEMON not found"; exit 0; }
if [ ! -s "$CONF" ]; then
echo "[SKIP] $NAME: no $CONF"
exit 0
fi
echo "[KDOS] Starting $NAME..."
supervise "$NAME" "$DAEMON" -c "$CONF"
;;
stop) stop_service "$NAME" ;;
status) check_status "$NAME" ;;
*) echo "Usage: $0 {start|stop|status}"; exit 1 ;;
esac
KDOS_SH
chmod 755 "$PKG/etc/init.d/73_mosquitto.sh"
The switches, and why each is set:
-DCMAKE_INSTALL_SYSCONFDIR=/etc— Install the example configuration under/etc/mosquittorather than/usr/etc.-DWITH_WEBSOCKETS=ON,-DWITH_WEBSOCKETS_BUILTIN=ON— MQTT over WebSockets, with Mosquitto’s own WebSocket code rather than libwebsockets; both are upstream’s defaults. It listens only where a listener is configured withprotocol websockets.-DWITH_DOCS=ON— Build the manual pages from DocBook withxsltproc, which is why libxslt and docbook-xsl are independs. Upstream’s default.-DWITH_TESTS=OFF— Build no tests, which upstream builds by default against GoogleTest.-DWITH_TLS=ON— TLS listeners and clients, on openssl; upstream’s default.-DWITH_HTTP_API=ON— The broker’s HTTP API listener, on libmicrohttpd. The library is found by a silentfind_library, and the listener is dropped without a word when it misses, which is why libmicrohttpd is independs.-DHTTP_API_DIR=— Empty the directory the HTTP API serves files from by default. Its cache default is the literal string “Default http_api directory”, and anhttp_apilistener with nohttp_dirof its own wouldrealpath()that, fail, and refuse to start.-DWITH_PLUGIN_PERSIST_SQLITE=ON— Build the plugin that keeps the broker’s persistent state (messages, retained messages, client sessions) in sqlite; upstream’s default. It is a requiredfind_package, so a missing sqlite stops configure.-DWITH_CTRL_SHELL=ON—mosquitto_ctrl’s interactive shell, upstream’s default. It needs a line-editing library, found silently and dropped when missing; with both installed it takes libedit’seditline/readline.hahead of readline.-DWITH_PLUGIN_EXAMPLES=OFF— Build none of the example plugins, which are on by default.-DWITH_SYSTEMD=OFF— No systemd notification; KDOS has no systemd (see No systemd).-DWITH_SRV=OFF— The clients do no DNS SRV lookup of the broker; upstream’s default.-DWITH_DLT=OFF— No logging to the GENIVI Diagnostic Log and Trace daemon; upstream’s default.
The common switches of each build system are explained in the Flag glossary.
postinstall.sh runs on the installed system after the package is adopted:
# The broker started as root drops to this account; without it mosquitto
# falls back to `nobody`, which every other daemon asking for an unprivileged
# account shares.
#
# Everything is written under PKG_ROOT, the root kpkgadd is installing into:
# --root and an A/B update install into a tree that is not the running one, and
# an account made in / instead would be missing from the system that needs it.
#
# The guard reads PKG_ROOT's files: getent answers for the running root, not
# the tree being installed, and would let useradd run against an account the
# target already has.
root="${PKG_ROOT:-/}"
grep -q '^mosquitto:' "$root/etc/group" 2>/dev/null || groupadd -R "$root" -r mosquitto
grep -q '^mosquitto:' "$root/etc/passwd" 2>/dev/null || \
useradd -R "$root" -r -g mosquitto -d /var/lib/mosquitto -s /sbin/nologin mosquitto
# chown resolves a name against the running root's passwd, so the ids are read
# out of PKG_ROOT's. The account's home is where a configuration that turns
# persistence on keeps the broker's state, and the broker writes it as this
# account.
while IFS=: read -r n _ uid gid _; do
[ "$n" = mosquitto ] || continue
chown "$uid:$gid" "$root/var/lib/mosquitto"
done < "$root/etc/passwd"
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/mosquitto, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf mosquitto-2.1.2-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/mosquitto, and runs the triggers its paths call for.
Contents
Installed programs: mosquitto, mosquitto_ctrl, mosquitto_db_dump, mosquitto_passwd, mosquitto_pub, mosquitto_rr, mosquitto_signal, mosquitto_sub.
Installed libraries: libmosquitto.so, libmosquittopp.so.
Installed directories: /etc/mosquitto, /usr/include/mosquitto, /usr/share/licenses/mosquitto, /var/lib/mosquitto.
Short descriptions
mosquitto |
an MQTT broker |
mosquitto_ctrl |
a tool for initialising/configuring a Mosquitto broker instance |
mosquitto_passwd |
manage password files for mosquitto |
mosquitto_pub |
an MQTT version 5/3.1.1/3.1 client for publishing simple messages |
mosquitto_rr |
an MQTT version 5/3.1.1 client for request/response messaging |
mosquitto_signal |
a utility for sending signal events to Mosquitto brokers running on the local computer. |
mosquitto_sub |
an MQTT version 5/3.1.1/3.1 client for subscribing to topics |
libmosquitto.pc |
mosquitto MQTT library (C bindings) |
libmosquittopp.pc |
mosquitto MQTT library (C++ bindings) |
Notes
The install writes only examples into /etc/mosquitto: mosquitto.conf.example, and aclfile.example, pskfile.example and pwfile.example for access lists, TLS pre-shared keys and passwords. With no configuration at all the broker listens on loopback alone, and for that a person can simply run mosquitto by hand, so the service skips itself until /etc/mosquitto/mosquitto.conf exists and is not empty. Writing that file is how an administrator says devices on the LAN are meant to reach the broker: a listener 1883 line in it, and the firewall’s mqtt name switched on.
postinstall.sh creates the mosquitto group and system account (home /var/lib/mosquitto, no login shell) unless they exist. Started as root, the broker drops to that account; without it Mosquitto falls back to nobody, which every other daemon asking for an unprivileged account shares. Everything is written under PKG_ROOT, so an install into another root, such as an A/B update, gets the account too, and the guard reads that root’s /etc/group and /etc/passwd itself: getent would answer for the running system instead. The package carries the home directory and postinstall.sh gives it to the account, so a configuration that turns persistence on can name persistence_location /var/lib/mosquitto/.
cJSON is a required dependency with no option of its own (find_package(cJSON REQUIRED)); cjson is in depends.