Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion _docs/pystemd.run.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ but we will assume that this just another building block for your program.
* env: A dict with environment variables.
* extra: If you know what you are doing, you can pass extra configuration
settings to the start_transient_unit method.
machine: Machine name to execute the command, by default we connect to
* cwd: Working directory for the command. If not specified, systemd's
default working directory will be used.
* machine: Machine name to execute the command, by default we connect to
the host's dbus.
* wait: Wait for command completion before returning control, defaults
to False.
* wait_for_activation: If True, wait only for the service to reach the
'running' state, then return immediately without waiting for completion.
Defaults to False.
* remain_after_exit: If True, the transient unit will remain after cmd
has finished, also if true, this methods will return
pystemd.systemd1.Unit object. defaults to False and this method
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pystemd"
version = "0.15.0"
version = "0.15.1"
readme = "README.md"
description="A systemd binding for python"
requires-python=">=3.11"
Expand Down
2 changes: 1 addition & 1 deletion pystemd/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

# during development this version is always at least "one up" the
# latest release.
__version__ = "0.15.0"
__version__ = "0.15.1"

sys.modules[__name__] = __version__ # type: ignore
1 change: 1 addition & 0 deletions pystemd/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def start_unit(self) -> pystemd.systemd1.Unit:
self.main_process_cmd,
name=self.unit_name,
user_mode=self.user_mode,
wait_for_activation=True,
extra={
**self.properties,
"Delegate": True,
Expand Down
29 changes: 21 additions & 8 deletions pystemd/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def run(
cwd=None,
machine=None,
wait=False,
wait_for_activation=False,
remain_after_exit=False,
collect=False,
raise_on_fail=False,
Expand Down Expand Up @@ -96,10 +97,15 @@ def run(
env: A dict with environment variables.
extra: If you know what you are doing, you can pass extra configuration
settings to the start_transient_unit method.
cwd: Working directory for the command. If not specified, systemd's
default working directory will be used.
machine: Machine name to execute the command, by default we connect to
the host's dbus.
wait: Wait for command completion before returning control, defaults
to False.
wait_for_activation: If True, wait only for the service to reach the
'running' state, then return immediately without waiting for completion.
Defaults to False.
remain_after_exit: If True, the transient unit will remain after cmd
has finished, also if true, this methods will return
pystemd.systemd1.Unit object. defaults to False and this method
Expand Down Expand Up @@ -259,7 +265,7 @@ def bus_factory():
unit_properties = {k: v for k, v in unit_properties.items() if v is not None}

unit = Unit(name, bus=bus, _autoload=True)
if wait:
if wait or wait_for_activation:
mstr = (
(
"type='signal',"
Expand Down Expand Up @@ -289,7 +295,7 @@ def bus_factory():
name, b"fail", unit_properties
)

while wait:
while wait or wait_for_activation:
events = sel.select(timeout=_wait_polling)
_in = [key.fileobj for key, _ in events]

Expand Down Expand Up @@ -323,13 +329,20 @@ def bus_factory():
m.get_path() == unit.path
and m.body[0] == b"org.freedesktop.systemd1.Unit"
):
_, message_job_path = m.body[1].get(b"Job", (0, b"/"))

if (
message_job_path != unit_start_job
and m.body[1].get(b"SubState") in EXIT_SUBSTATES
):
break
_, message_job_path = m.body[1].get(b"Job", (0, b"/"))
if wait:
if (
message_job_path != unit_start_job
and m.body[1].get(b"SubState") in EXIT_SUBSTATES
):
break
elif wait_for_activation:
if (
message_job_path == unit_start_job
and m.body[1].get(b"SubState") in (b"running",)
):
break

if _wait_polling and not _in and unit.Service.MainPID == 0:
# on usermode the subscribe to events does not work that well
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

setup(
name="pystemd",
version="0.15.0",
version="0.15.1",
author="Alvaro Leiva Geisse",
author_email="aleivag@gmail.com",
packages=["pystemd", "pystemd.systemd1", "pystemd.machine1", "pystemd.DBus"],
Expand Down