Skip to content

Instantly share code, notes, and snippets.

@FlorinAsavoaie
Last active October 6, 2017 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FlorinAsavoaie/0c04042099f3bdaf7326d0ed6d5f516e to your computer and use it in GitHub Desktop.
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.
#!/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