Skip to content

python-systemd python wrapper for systemd system and session manager dbus interfaces

License

Notifications You must be signed in to change notification settings

guardicore/python-systemd

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-systemd-dbus

python-systemd-dbus python wrapper for systemd_ system and session manager dbus interfaces.

.. systemd: http://www.freedesktop.org/wiki/Software/systemd

Basic usage

Import and create a manager:

>>> from systemd_dbus.manager import Manager
>>> manager = Manager()

List all units:

>>> for unit in manager.list_units():
...    print(unit.properties.Id)
...    print(unit.properties.Description)
...
nfs-server.service
LSB: Kernel NFS server support
virtualbox.service
LSB: VirtualBox Linux kernel module
mandi.service
LSB: Network monitoring daemon
crond.service
LSB: run cron daemon
...

Get an unit:

>>> unit = manager.get_unit('crond.service')

crond is running:

>>> print(unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState)
loaded active running

Let's stop crond:

>>> unit.stop('fail')
<systemd_dbus.job.Job object at 0x7fa57ba03a90>

Is crond running? why I stop it!!:

>>> print(unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState)
loaded active running

We want o loop!:

>>> import gobject
>>> gobject.MainLoop().run()
...
KeyboardInterrupt

Now Unit properties is updated!:

>>> print(unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState)
loaded inactive dead

Let's start crond:

>>> unit.start('fail')
<systemd_dbus.job.Job object at 0x7fa57ba03950>

Remember we want o loop!:

>>> print(unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState)
loaded inactive dead

The loop!:

>>> gobject.MainLoop().run()
...
KeyboardInterrupt

Updated!:

>>> print(unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState)
loaded active running

About

python-systemd python wrapper for systemd system and session manager dbus interfaces

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%