Skip to main content

Lightweight Python module for daemonizing

Project description

Travis build status image Coverage status

succubus

Description

succubus is a lightweight python module for a fast and easy creation of python daemons and init scripts.

Examples

#!/usr/bin/env python

import logging
import sys
import time

from logging.handlers import WatchedFileHandler

from succubus import Daemon


class MyDaemon(Daemon):
    def run(self):
        """Overwrite the run function of the Daemon class"""
        # TODO: don't log to /tmp except for example code
        handler = WatchedFileHandler('/tmp/succubus.log')
        self.logger = logging.getLogger('succubus')
        self.logger.addHandler(handler)
        while True:
            time.sleep(1)
            self.logger.warn('Hello world')


def main():
    daemon = MyDaemon(pid_file='succubus.pid')
    sys.exit(daemon.action())


if __name__ == '__main__':
    main()

Succubus implements the usual init script actions (start, stop, restart, status) in Python. So your init script can look like this:

#!/bin/bash
/usr/bin/my_succubus_daemon $1 --foo=42

If the init script is called as /etc/init.d/my_succubus_daemon start, this will translate into /usr/bin/my_succubus_daemon start --foo=42 being called. The start parameter is consumed by the succubus framework, i.e. when your code does the command line parsing, it looks as if /usr/bin/my_succubus_daemon --foo=42 was called. You can now parse the --foo=42 parameter as you please.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

succubus-1.0.post60.tar.gz (4.4 kB view details)

Uploaded Source

File details

Details for the file succubus-1.0.post60.tar.gz.

File metadata

  • Download URL: succubus-1.0.post60.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for succubus-1.0.post60.tar.gz
Algorithm Hash digest
SHA256 6e09783a2d07e4f500fb414be372d2697c42b6969cdde8bf80d5df56425da8f9
MD5 02feef624bb6be3a1e8d5e21df9173fd
BLAKE2b-256 7dbbf7a8688e503bd606d1e2d68956d6c6376004d40236edacb3fb6a243887eb

See more details on using hashes here.

Supported by

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