a) downloaded an appropriate binary (linux_amd64 in my case) from here https://github.com/albertnis/mqcontrol/releases
b) and put it in /usr/local/bin
c) renamed it mqcontrol
d) chmod 755 to make it executable
This is the systemd unit file I used to have the screen lock on a machine. When mqcontrol is running, it listens to MQTT and awaits anything posted to the topic computercommands/lounge/lockscreen and will run the command we want.
-i is the MQTT client's ID (you can use anything)
-h is the MQTT server and port
-t is the topic you want to watch (anything at all posted to this topic will run the command, including)
-u and -p are the MQTT username/pass
dave is the local pc user that the command will be run as (see quirks below)
[Unit] Description=mqcontrol remote control [Service] Type=simple ExecStart=/usr/local/bin/mqcontrol -i mqcloungepc -c "su - dave -c\"gnome-screensaver-command -l\"" -h 192.168.x.x:1883 -t computercommands/lounge/lockscreen -u mqttuser -p mqttpassword [Install] WantedBy=multi-user.target
you need to make it active with systemctl enable mqcontrol
If you change the unit file you need to run systemctl daemon-reload it will warn you if you haven't.
Start and stop the daemon with systemctl start mqcontrol and systemctl stop mqcontrol
Check to see if the daemon is still running with ps aux |grep mqcontrol. If the EXEC command fails, the daemon will die.
You can check the systemd log for that particular daemon with journalctl -u mqcontrol
I'd be interested in suggestions anyone may have to lock the gnome screens of all users logged in, but in most cases I'll know who the users are.
Any other suggestions here would be useful... maybe I should just run the entire daemon as myself as the user?
Another planned use will be to shut down some raspberry pis then have them boot up when needed with external power control (I have some that only need to run when other actions are occurring, and power is controlled via tasmota).
2) Just watch when you are sending MQTT commands to the topic... anything at all to the topic will activate the script (including NULL). You will need to to do some rerouting if you are trying to tie it in with other on/off commands