question

mccrane avatar image
mccrane asked

dbus Python driver fails when started as service

I have implemented a dbus Python service which works fine within the terminal but starting it as a service fails.

  • dbus code from https://github.com/victronenergy/velib_python/blob/master/dbusdummyservice.py to file dbus-dummy.py at /data/dbus-dummy.
  • ve_utils.py and vedbus.py in /data/dbus-dummy
  • "run" start script in the /data/dbus-dummy/service folder (chmod 755).
  • symbolic link: "ln -s /data/dbus-dummy/service /service/dbus-dummy"

The service starts and is terminate within the same second;

"svstat /service/dbus-dummy" shows restarts every second with new PIDs:

root@raspberrypi2:~# svstat /service/dbus-dummy
/service/dbus-dummy: up (pid 24314) 0 seconds
root@raspberrypi2:~# svstat /service/dbus-dummy
/service/dbus-dummy: up (pid 24325) 0 seconds

....

The service works well when started in the terminal:

python /data/dbus-dummy/dbus-dummy.py

The dbus-spy shows a new service: com.victronenergy.dummyservice.ttyO1

Environment:

Venus/Raspberry v 2.89

I would be happy about any ideas or hints!

servicepython
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

5 Answers
pulquero avatar image
pulquero answered ·

What is the contents of your 'run' start script? if you are exec-ing your python, check you have the following as first line in your .py:

#!/usr/bin/env python
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

mccrane avatar image
mccrane answered ·

The first python environment code line in the "official" example is "python 3"-please see the attachement.

I currently have no access to the system(out on holidays), I can post it next weekend.

An additional remark - there are no infos in the logs.

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

mccrane avatar image
mccrane answered ·

Here the attachement with Python env statemen:

dummy-python-github.png

The /service/run bash script contains the right path and filename:

#!/bin/sh
python /data/dbus-dummy/dbus-dummy.py



2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

mccrane avatar image
mccrane answered ·

I was able to solve the issue...a trivial one - line feeds with CRLF in the run script!

I thought using "nano" to edit and renew all line feeds in the run script would prevent this.

But only:

> sed -i -e 's/\r$//' run

changes the CRLF to unix/bash style LF and the service starts imediately...

Thanks for your support!



2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

pulquero avatar image
pulquero answered ·

Ah that's annoying. Based on the other services, I personally use

#!/bin/sh
exec 2>&1
exec /data/BatteryProxy/battery_service.py

(which is what I assumed you were doing, hence my suggestion to check for a missing #!/usr/bin/env line)

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Related Resources

Additional resources still need to be added for this topic