I have a python script that runs a webserver which accepts requests to control video playback via omxplayer
and python-omxplayer-wrapper
. I would like to have my script run at startup. python-omxplayer-wrapper
communicates with omxplayer
over dbus.
I am running on a Raspberry Pi Zero W with raspbian stretch installed via NOOBS, and is configured as headless.
I have created a service in /lib/systemd/system/myservice.service
:
[Unit]
Description=My Service
After=multi-user.target
[Service]
User=root
Group=root
Type=idle
ExecStart=/home/pi/myscript/server/myserver.py
[Install]
WantedBy=multi-user.target
and enabled service via:
sudo chmod 644 /lib/systemd/system/myservice.service
sudo systemctl daemon-reload
sudo systemctl enable myservice.service
sudo reboot
Running my script manually, or manually starting the service with systemctld myservice start
after system boot works fine. When my script is run during init, it fails with the following error:
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NoServer: Failed to connect to socket /tmp/dbus-NxYs8GEMQz: Connection refused
My interpretation is that init is running my script before the dbus become available, even though I have my script as Type=idle
which should cause my script to run at the end of the boot sequence.
How can I enforce my service to start only once the dbus connections become available?