T

improve documentation regarding headless/loginless dbus usage

The documentation/wiki are a little short on providing info how to run SaT as a background service without logging in.

I did the following, but this is probably not ideal. I don't know whether the system dbus could be used as well and this custom dbus-session service is necessary at all.

Anyhow, here goes:

cat > /etc/systemd/system/dbus-session.service << EOF
[Unit]
Description=D-Bus session bus for SaT
After=network.target

[Service]
ExecStart=dbus-daemon --session --address=unix:abstract=sat-dbus
Type=simple
User=sat
EOF

cat > /etc/systemd/system/saluteatoi.service << EOF
[Unit]
Description=Salute a toi backend
Documentation=man:sat(1)
Requires=dbus-sat-session.service

[Service]
Type=forking
PIDFile=/home/sat/.local/share/sat/sat.pid
Environment=DBUS_SESSION_BUS_ADDRESS=unix:abstract=sat-dbus
ExecStart=/usr/bin/sat
ExecStop=/usr/bin/sat stop
User=sat

[Install]
WantedBy=multi-user.target
EOF

Finally set up a wrapper around jp to sudo to user sat and use the session bus. I could not make this work with adapting dbus session bus policies alone - it seems they don't have anything preventing anyone from using session buses anyway, but I always got errors without sudo:

Failed to open connection to session bus: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.

Therefore, I use this:
cat > /usr/local/bin/send_xmpp_omemo << 'EOF'

!/bin/bash

rcpt=$1
shift
echo $@ | nice -n19 sudo -u sat DBUS_SESSION_BUS_ADDRESS=unix:abstract=sat-dbus /usr/bin/jp message send -c -e OMEMO $rcpt
EOF

(sudoers has to be setup to allow the calling user to sudo as sat)
(group messages with OMEMO are not supported yet (0.7.0), but that would be more elegant instead of sending to just one receiver)

This can be easily integrated into domoticz for example by using
script:///usr/local/bin/send_xmpp_omemo #TO #MESSAGE
as URL/Action
and your jid as #TO as "Custom HTTP/Action".

I think it would be best to provide a working .service file with the distribution and probably use the system bus if that is possible. I am not very knowledgeable about D-Bus however, I only thought other services also use the system bus, and their setup seems a lot easier.

I hope the provided info is complete!

id

335

author

Tbart

created

01/10/2019, 19:10

updated

01/10/2019, 19:10

labels
dbus jp headless command line cli
type
feature request
status
queued
priority
normal
milestone
0.7
severity
normal