Created
August 12, 2011 06:47
-
-
Save tchollingsworth/1141591 to your computer and use it in GitHub Desktop.
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/python2 | |
import dbus, os, subprocess | |
bus = dbus.SystemBus() | |
manager_proxy = bus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1') | |
manager = dbus.Interface(manager_proxy, 'org.freedesktop.systemd1.Manager') | |
restart = [] | |
for unit in manager.ListUnits(): | |
name = unit[0] | |
status = unit[3] | |
path = unit[6] | |
#does systemd think we're loaded and are we a service? | |
if status == 'active' and path.endswith("service"): | |
unit_proxy = bus.get_object('org.freedesktop.systemd1', path) | |
unit_if = dbus.Interface(unit_proxy, 'org.freedesktop.systemd1.Unit') | |
unit_props = dbus.Interface(unit_proxy, 'org.freedesktop.DBus.Properties') | |
type = unit_props.Get('org.freedesktop.systemd1.Service', 'Type') | |
#don't restart oneshot scripts | |
if type != 'oneshot': | |
#we need to restart them all in one transaction to prevent dependency issues | |
restart.append(name) | |
#just restart them with systemctl, dbus has given me enough of a headache for now | |
if restart: | |
subprocess.call(["/bin/systemctl", "restart"] + restart) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment