MQTT client triggering & reporting shutdown on systemd-based systems
Project description
systemctl-mqtt
MQTT client triggering & reporting shutdown on systemd-based systems
Setup
Via Pip
$ pip3 install --user --upgrade systemctl-mqtt
On debian-based systems, a subset of dependencies can optionally be installed via:
$ sudo apt-get install --no-install-recommends python3-jeepney python3-paho-mqtt
Follow instructions in systemd-user.service to start systemctl-mqtt automatically via systemd.
Via Docker Compose 🐳
- Clone this repository.
- Load AppArmor profile:
sudo apparmor_parser ./docker-apparmor-profile
sudo docker-compose up --build
Pre-built docker image are available at https://hub.docker.com/r/fphammerle/systemctl-mqtt/tags
Annotation of signed tags docker/*
contains docker image digests: https://github.com/fphammerle/systemctl-mqtt/tags
Usage
$ systemctl-mqtt --mqtt-host HOSTNAME_OR_IP_ADDRESS
systemctl-mqtt --help
explains all available command-line options / parameters.
MQTT via TLS
TLS is enabled by default.
Run systemctl-mqtt --mqtt-disable-tls …
to disable TLS.
MQTT Authentication
systemctl-mqtt --mqtt-username me --mqtt-password-file /run/secrets/password …
# or for testing (unsafe):
systemctl-mqtt --mqtt-username me --mqtt-password secret …
Schedule Poweroff
Schedule poweroff by sending a MQTT message to topic systemctl/hostname/poweroff
.
$ mosquitto_pub -h MQTT_BROKER -t systemctl/hostname/poweroff -n
Adapt delay via: systemctl-mqtt --poweroff-delay-seconds 60 …
Shutdown Report
systemctl-mqtt
subscribes to logind's PrepareForShutdown
signal.
systemctl halt|poweroff|reboot
triggers a message with payload true
on topic systemctl/hostname/preparing-for-shutdown
.
Lock Screen
Lock screen by sending a MQTT message to topic systemctl/hostname/lock-all-sessions
.
$ mosquitto_pub -h MQTT_BROKER -t systemctl/hostname/lock-all-sessions -n
Suspend
$ mosquitto_pub -h MQTT_BROKER -t systemctl/hostname/suspend -n
Monitor ActiveState
of System Units
$ systemctl-mqtt --monitor-system-unit foo.service
enables reports on topic
systemctl/[hostname]/unit/system/[unit_name]/active-state
.
Restarting of System Units
$ systemctl-mqtt --control-system-unit <unit_name>
enables that a system unit can be restarted by a message on topic
systemctl/[hostname]/unit/system/[unit_name]/restart
.
Home Assistant 🏡
When MQTT Discovery is enabled (default in Home Assistant ≥0.117.0), the following entities will be added automatically:
binary_sensor.[hostname]_logind_preparing_for_shutdown
button.[hostname]_logind_lock_all_sessions
button.[hostname]_logind_poweroff
button.[hostname]_logind_suspend
sensor.[hostname]_unit_system_[unit_name]_active_state
for--monitor-system-unit [unit_name]
button.[hostname]_unit_system_[unit_name]_restart
for--control-system-unit [unit_name]
Pass --homeassistant-discovery-prefix custom-prefix
to systemctl-mqtt
when
using a custom discovery topic prefix.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file systemctl-mqtt-1.1.0.tar.gz
.
File metadata
- Download URL: systemctl-mqtt-1.1.0.tar.gz
- Upload date:
- Size: 84.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
245c74e4b408aab0365b6afbc333fb77058363b72eb4c19c4b8d83a4cd201acc
|
|
MD5 |
49b86704a8ed2d208bd7135655ddfd38
|
|
BLAKE2b-256 |
19ab0f50e8ddb3c734776130b6839d7e5d5a719fe4647ac70b8c0bd5c7b420ab
|
File details
Details for the file systemctl_mqtt-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: systemctl_mqtt-1.1.0-py3-none-any.whl
- Upload date:
- Size: 31.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
30e0635c1870d0d3dddf19f83b97c8fd016e92b1684fad9b55d78fc929c7ceeb
|
|
MD5 |
0aee9a3289069462e98b7d2627239daf
|
|
BLAKE2b-256 |
a1c197173c35660e202d3ee33b5109a01f136d09ddc8cb55524628871c409564
|