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

Function get_running

salt/modules/systemd_service.py:439–475  ·  view source on GitHub ↗

Return a list of all running services, so far as systemd is concerned CLI Example: .. code-block:: bash salt '*' service.get_running

()

Source from the content-addressed store, hash-verified

437
438
439def get_running():
440 """
441 Return a list of all running services, so far as systemd is concerned
442
443 CLI Example:
444
445 .. code-block:: bash
446
447 salt '*' service.get_running
448 """
449 ret = set()
450 # Get running systemd units
451 out = __salt__["cmd.run"](
452 _systemctl_cmd("--full --no-legend --no-pager"),
453 python_shell=False,
454 ignore_retcode=True,
455 )
456 for line in salt.utils.itertools.split(out, "\n"):
457 try:
458 comps = line.strip().split()
459 fullname = comps[0]
460 if len(comps) > 3:
461 active_state = comps[3]
462 except ValueError as exc:
463 log.error(exc)
464 continue
465 else:
466 if active_state != "running":
467 continue
468 try:
469 unit_name, unit_type = fullname.rsplit(".", 1)
470 except ValueError:
471 continue
472 if unit_type in VALID_UNIT_TYPES:
473 ret.add(unit_name if unit_type == "service" else fullname)
474
475 return sorted(ret)
476
477
478def get_enabled(root=None):

Callers

nothing calls this directly

Calls 4

_systemctl_cmdFunction · 0.85
setFunction · 0.70
errorMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected