0

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?

2 Answers 2

1

Maybe it's an old question, but I was facing the same problem and this was the solution:

You have to add "bluetooth.target" after "After=multi-user.target", leaving that line like this -> "After=multi-user.target bluetooth.target"

Also, keep "Type=idle" because if you use "Type=simple" it will not work, even if your service starts after bluetooth service. I think this may be related to dbus service not starting, but didn't check it because this way already works...

0

I would run it from crontab to make sure the dbus is available before execution.

sudo crontab -e

then add this at the bottom

@reboot * * * * python /home/pi/myscript/server/myserver.py

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.