Git Product home page Git Product logo

fphammerle / systemctl-mqtt Goto Github PK

View Code? Open in Web Editor NEW
11.0 4.0 3.0 529 KB

MQTT client triggering & reporting shutdown on systemd-based systems :house_with_garden: ๐Ÿณ

Home Page: https://pypi.org/project/systemctl-mqtt/

License: GNU General Public License v3.0

Python 95.06% Dockerfile 3.30% Makefile 1.64%
internet-of-things automation mqtt systemd shutdown poweroff home-assistant

systemctl-mqtt's People

Contributors

dependabot[bot] avatar fphammerle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

systemctl-mqtt's Issues

autostart?

how can I perform an autostart via systemd

Document how to set up on Ubuntu or similar system with proper background op and rights

First, thanks for your work on this. A useful tool if complete.

As highlighted in Issue request cited below. If you could make a solid set of documentation to install your tool so it can run in background and has proper security to allow operation it will be a winner. Below is what I am getting when I try to run you client as a non-root user (as is indicated by your current documentation) in a tmux session. It fails with the message :

  File "/usr/lib/python3/dist-packages/dbus/connection.py", line 652, in call_blocking
    reply_message = self.send_message_with_reply_and_block(
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.InteractiveAuthorizationRequired: Interactive authentication required.

#66

# on remote machine
mosquitto_pub -h 192.168.1.100 -t systemctl/target-machine/lock-all-sessions -n

# on target machine running in tmux session
user@target-machine:~$ systemctl-mqtt --mqtt-disable-tls --mqtt-host 192.168.1.100
2023-05-27T21:19:16-0700:INFO:connecting to MQTT broker 192.168.1.100:1883 (TLS disabled)
2023-05-27T21:19:16-0700:DEBUG:connected to MQTT broker 192.168.1.100:1883
2023-05-27T21:19:16-0700:DEBUG:acquired shutdown inhibitor lock
2023-05-27T21:19:16-0700:INFO:publishing 'false' on systemctl/target-machine/preparing-for-shutdown
2023-05-27T21:19:16-0700:DEBUG:publishing home assistant config on homeassistant/binary_sensor/target-machine/preparing-for-shutdown/config
2023-05-27T21:19:16-0700:INFO:subscribing to systemctl/target-machine/poweroff
2023-05-27T21:19:16-0700:DEBUG:registered MQTT callback for topic systemctl/target-machine/poweroff triggering _MQTTActionSchedulePoweroff
2023-05-27T21:19:16-0700:INFO:subscribing to systemctl/target-machine/lock-all-sessions
2023-05-27T21:19:16-0700:DEBUG:registered MQTT callback for topic systemctl/target-machine/lock-all-sessions triggering _MQTTActionLockAllSessions
2023-05-27T21:21:33-0700:DEBUG:received topic=systemctl/target-machine/lock-all-sessions payload=b''
2023-05-27T21:21:33-0700:DEBUG:executing action _MQTTActionLockAllSessions
2023-05-27T21:21:33-0700:INFO:instruct all sessions to activate screen locks
Exception in thread Thread-1 (_thread_main):
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 3452, in _thread_main
    self.loop_forever(retry_first_connection=True)
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1779, in loop_forever
    rc = self.loop(timeout, max_packets)
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1181, in loop
    rc = self.loop_read(max_packets)
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1572, in loop_read
    rc = self._packet_read()
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 2310, in _packet_read
    rc = self._packet_handle()
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 2936, in _packet_handle
    return self._handle_publish()
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 3216, in _handle_publish
    self._handle_on_message(message)
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 3429, in _handle_on_message
    callback(self, self._userdata, message)
  File "/home/user/.local/lib/python3.10/site-packages/systemctl_mqtt/__init__.py", line 217, in mqtt_message_callback
    self.trigger(state=state)
  File "/home/user/.local/lib/python3.10/site-packages/systemctl_mqtt/__init__.py", line 235, in trigger
    systemctl_mqtt._dbus.lock_all_sessions()
  File "/home/user/.local/lib/python3.10/site-packages/systemctl_mqtt/_dbus.py", line 105, in lock_all_sessions
    get_login_manager().LockSessions()
  File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 72, in __call__
    return self._proxy_method(*args, **keywords)
  File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 141, in __call__
    return self._connection.call_blocking(self._named_service,
  File "/usr/lib/python3/dist-packages/dbus/connection.py", line 652, in call_blocking
    reply_message = self.send_message_with_reply_and_block(
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.InteractiveAuthorizationRequired: Interactive authentication required.

mqtt connect enforces ssl

Hi

Even when starting it with --mqtt-host iot1 --mqtt-port 1883. It still tries to connect with ssl giving the error:

pi@octopi:~ $ systemctl-mqtt --mqtt-host 192.168.1.120 --mqtt-port 1883
2020-09-09T23:53:28+0100:INFO:connecting to MQTT broker 192.168.1.120:1883
Traceback (most recent call last):
  File "/home/pi/.local/bin/systemctl-mqtt", line 10, in <module>
    sys.exit(_main())
  File "/home/pi/.local/lib/python3.7/site-packages/systemctl_mqtt/__init__.py", line 369, in _main
    homeassistant_node_id=args.homeassistant_node_id,
  File "/home/pi/.local/lib/python3.7/site-packages/systemctl_mqtt/__init__.py", line 287, in _run
    mqtt_client.connect(host=mqtt_host, port=mqtt_port)
  File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py", line 937, in connect
    return self.reconnect()
  File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py", line 1100, in reconnect
    sock.do_handshake()
  File "/usr/lib/python3.7/ssl.py", line 1117, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [Errno 104] Connection reset by peer

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.