Last active
October 6, 2017 16:38
-
-
Save FlorinAsavoaie/0c04042099f3bdaf7326d0ed6d5f516e to your computer and use it in GitHub Desktop.
External Puppet fact listing running services on a SystemD machine. Depends on python-dbus.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# This is to be used as an external Puppet fact that can tell you what are the | |
# currently running services (not all units!) on a SystemD machine. | |
from dbus import SystemBus, Interface | |
import re | |
manager = Interface( | |
SystemBus().get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1'), | |
'org.freedesktop.systemd1.Manager') | |
print '%s: %s' % ('running_services', | |
[ str(re.search(r'^([^\.]+)\.service$', unit[0]).group(1)) | |
for unit in manager.ListUnits() | |
if unit[4] == 'running' and re.search(r'.service$', unit[0]) ]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment