MCPcopy
hub / github.com/saltstack/salt / _systemctl_cmd

Function _systemctl_cmd

salt/modules/systemd_service.py:312–347  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

310
311
312def _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
350def _systemctl_status(name):

Callers 15

_systemctl_statusFunction · 0.85
systemctl_reloadFunction · 0.85
get_runningFunction · 0.85
get_enabledFunction · 0.85
get_disabledFunction · 0.85
get_staticFunction · 0.85
unmask_Function · 0.85
maskFunction · 0.85
startFunction · 0.85
stopFunction · 0.85
restartFunction · 0.85
reload_Function · 0.85

Calls 4

_canonical_unit_nameFunction · 0.85
extendMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected