Build a systemctl command line. Treat unit names without one of the valid suffixes as a service.
(
action, name=None, systemd_scope=False, no_block=False, root=None, extra_args=None
)
| 310 | |
| 311 | |
| 312 | def _systemctl_cmd( |
| 313 | action, name=None, systemd_scope=False, no_block=False, root=None, extra_args=None |
| 314 | ): |
| 315 | """ |
| 316 | Build a systemctl command line. Treat unit names without one |
| 317 | of the valid suffixes as a service. |
| 318 | """ |
| 319 | ret = [] |
| 320 | if ( |
| 321 | systemd_scope |
| 322 | and salt.utils.systemd.has_scope(__context__) |
| 323 | and __salt__["config.get"]("systemd.scope", True) |
| 324 | ): |
| 325 | if systemd_run_path := salt.utils.path.which("systemd-run"): |
| 326 | ret.extend([systemd_run_path, "--scope"]) |
| 327 | else: |
| 328 | raise CommandExecutionError( |
| 329 | "systemd-run is required for running systemctl with --scope, but it was not found on the system. " |
| 330 | "Make sure systemd-run is installed and in the system's PATH " |
| 331 | "or disable it using the 'systemd.scope' config option." |
| 332 | ) |
| 333 | ret.append(salt.utils.path.which("systemctl")) |
| 334 | if no_block: |
| 335 | ret.append("--no-block") |
| 336 | if root: |
| 337 | ret.extend(["--root", root]) |
| 338 | if isinstance(action, str): |
| 339 | action = shlex.split(action) |
| 340 | ret.extend(action) |
| 341 | if name is not None: |
| 342 | ret.append(_canonical_unit_name(name)) |
| 343 | if "status" in ret: |
| 344 | ret.extend(["-n", "0"]) |
| 345 | if isinstance(extra_args, list): |
| 346 | ret.extend(extra_args) |
| 347 | return ret |
| 348 | |
| 349 | |
| 350 | def _systemctl_status(name): |
no test coverage detected