Return a list of all running services, so far as systemd is concerned CLI Example: .. code-block:: bash salt '*' service.get_running
()
| 437 | |
| 438 | |
| 439 | def 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 | |
| 478 | def get_enabled(root=None): |
nothing calls this directly
no test coverage detected