fphammerle / systemctl-mqtt

MQTT client triggering & reporting shutdown on systemd-based systems :house_with_garden: 🐳
https://pypi.org/project/systemctl-mqtt/
GNU General Public License v3.0
11 stars 3 forks source link

autostart? #66

Open Rothammel opened 1 year ago

Rothammel commented 1 year ago

how can I perform an autostart via systemd

fphammerle commented 1 year ago

rough untested(!) draft:

  1. install podman
  2. create file /etc/systemd/system/systemctl-mqtt-podman-container.service with following content:
    [Unit]
    After=dbus.socket
    Requires=dbus.socket
    [Service]
    Type=notify
    NotifyAccess=all
    ExecStartPre=/usr/sbin/apparmor_parser /somewhere/docker-apparmor-profile
    ExecStart=/usr/bin/podman run --cidfile %t/%n.ctr-id \
    --rm --detach --sdnotify conmon --log-driver journald \
    --name systemctl_mqtt \
    -v /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket:rw \
    --hostname %H --userns host --user 0 \
    --security-opt no-new-privileges --security-opt apparmor=systemctl-mqtt \
    docker.io/fphammerle/systemctl-mqtt:0.5.0-amd64@sha256:34dcb878dbd66315de6fbf97ceb29e8fec549b7269c6c828c4c889a54a091f14 \
    systemctl-mqtt ...
    ExecStop=/usr/bin/podman stop --cidfile %t/%n.ctr-id
    ExecStopPost=/usr/bin/podman rm --cidfile %t/%n.ctr-id 
    ExecStopPost=rm %t/%n.ctr-id
    [Install]
    WantedBy=multi-user.target
  3. sudo systemctl daemon-reload
  4. sudo systemctl enable systemctl-mqtt-podman-container.service
  5. sudo systemctl start systemctl-mqtt-podman-container.service