GithubHelp home page GithubHelp logo

cloudxtreme / python-systemd Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cmgc/python-systemd

0.0 1.0 0.0 144 KB

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

License: GNU Lesser General Public License v2.1

Python 100.00%

python-systemd's Introduction

python-systemd

python-systemd 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.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.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.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

python-systemd's People

Contributors

wiliamsouza avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.