3

I want to start a not existing timer which should start a not existing service at the time. This should be done via systemd transient unit like systemd-run.

When I execute the following code, I recieve an exception (see below). Can someone please tell me, what the exceptions wants to tell me?

import dbus
import time

proxy = dbus.SystemBus().get_object("org.freedesktop.systemd1", "/org/freedesktop/systemd1")
systemd = dbus.Interface(proxy, dbus_interface="org.freedesktop.systemd1.Manager")
future = time.time() + 15
job = systemd.StartTransientUnit( \
    "bla-foo.timer", "replace", \
        [ \
            ("Description", "Bla Foo Timer"), \
            ("RemainAfterElapse", False), \
            ("OnCalendar", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(future))) \
        ], \
        [("bla-foo.service", \
            [ \
                ("Description", "Bla Foo Service"), \
                ("ExecStart", ("/usr/bin/python3", ["-c", "import os; print(os.getcwd())"], False)), \
                ("Type", "oneshot"), \
                ("WorkingDirectory", "/usr/lib") \
            ] \
        )] \
    )
print(job)
Traceback (most recent call last):
  File "/usr/lib/swmanager/preinstaller/test.py", line 19, in <module>
    ("WorkingDirectory", "/usr/lib") \
  File "/usr/lib/python3.7/site-packages/dbus/proxies.py", line 72, in __call__
    return self._proxy_method(*args, **keywords)
  File "/usr/lib/python3.7/site-packages/dbus/proxies.py", line 147, in __call__
    **keywords)
  File "/usr/lib/python3.7/site-packages/dbus/connection.py", line 653, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: System.Error.ENXIO: No such device or address

1 Answer 1

5

The problem was, that the ExecStart parameter wasn't in the correct form.

Correct is: ("ExecStart", [("/usr/bin/python3", [ "/usr/bin/python3", "-c", "import os; print(os.getcwd())"], True)]),

Complete working code:

import dbus
import time

proxy = dbus.SystemBus().get_object("org.freedesktop.systemd1", "/org/freedesktop/systemd1")
systemd = dbus.Interface(proxy, dbus_interface="org.freedesktop.systemd1.Manager")
future = time.time() + 15
job = systemd.StartTransientUnit( \
    "bla-foo.timer", "replace", \
        [ \
            ("Description", "Bla Foo Timer"), \
            ("RemainAfterElapse", False), \
            ("OnCalendar", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(future))) \
        ], \
        [("bla-foo.service", \
            [ \
                ("Description", "Bla Foo Service"), \
                ("ExecStart", [("/usr/bin/python3", ["/usr/bin/python3", "-c", "import os; print(os.getcwd())"], True)]), \
                ("Type", "oneshot"), \
                ("WorkingDirectory", "/usr/lib") \
            ] \
        )] \
    )
print(job)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.