forked from wiliamsouza/python-systemd
-
Notifications
You must be signed in to change notification settings - Fork 2
/
README
70 lines (55 loc) · 1.66 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
==============
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
===========
>>> 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
...
>>> 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