Skip to main content

SystemD wrapper on Cython

Project description

Latest Version https://img.shields.io/pypi/wheel/cysystemd.svg https://img.shields.io/pypi/pyversions/cysystemd.svg https://img.shields.io/pypi/l/cysystemd.svg

Python systemd wrapper using Cython

Installation

All packages available on github releases.

Debian/Ubuntu

Install repository key

wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=bintray' | \
   apt-key add -

Install the repository file

Debian Jessie:

echo "deb http://dl.bintray.com/mosquito/cysystemd jessie main" > /etc/apt/sources.list.d/cysystemd.list
apt-get update
apt-get install python-cysystemd python3-cysystemd

Ubuntu Xenial:

echo "deb http://dl.bintray.com/mosquito/cysystemd xenial main" > /etc/apt/sources.list.d/cysystemd.list
apt-get update
apt-get install python-cysystemd python3-cysystemd

Ubuntu Bionic:

echo "deb http://dl.bintray.com/mosquito/cysystemd bionic main" > /etc/apt/sources.list.d/cysystemd.list
apt-get update
apt-get install python-cysystemd python3-cysystemd

Centos 7

yum localinstall \
   https://github.com/mosquito/cysystemd/releases/download/0.17.1/python-cysystemd-0.17.1-1.centos7.x86_64.rpm

Installation from sources

You should install systemd headers

For debian users:

apt-get install build-essential \
    libsystemd-journal-dev \
    libsystemd-daemon-dev \
    libsystemd-dev

For CentOS/RHEL

yum install gcc systemd-devel

And install it from pypi

pip install cysystemd

Usage examples

Systemd daemon notification

from cysystemd.daemon import notify, Notification

# Send READY=1
notify(Notification.READY)

# Send status
notify(Notification.STATUS, "I'm fine.")

# Send stopping
notify(Notification.STOPPING)

Write message into Systemd journal

from cysystemd import journal


journal.write("Hello Lennart")

# Or send structured data
journal.send(
    message="Hello Lennart",
    priority=journal.Priority.INFO,
    some_field='some value',
)

Or add logging handler to python logger

from cysystemd import journal
import logging
import uuid

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger()
logger.addHandler(journal.JournaldLogHandler())

try:
    log.info("Trying to do something")
    raise Exception('foo')
except:
    logger.exception("Test Exception %s", 1)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cysystemd-0.17.2.tar.gz (175.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page