Turkmenbashi

A library to write UNIX daemons
Download

Turkmenbashi Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Hagar El Vikingo
  • Publisher web site:
  • http://github.com/hagarelvikingo/

Turkmenbashi Tags


Turkmenbashi Description

A library to write UNIX daemons Turkmenbashi is a daemon creator, a helpful resource to write an UNIX daemon in Python, by providing functions to start, stop and restart, a quick and easily configurable logging facility and defined functions to control every aspect on daemon execution.Why the nameThis piece of code is part of a proprietary project. One night, after a long conversation about modern history with some friends, I tried to explain how it works in the same “historical” terms, just making fun about it.This class is like a “dictator” who does a “coup d’etat”, “daemonizes” other citizens (who are the processes under his control) and throws them away from “their city” (the process collection) closing access to basic resources (“file descriptors”), and the “daemonized citizens” are known to be alive because there is no defunction and they still can write logs about their lives.Basically, in that conversation I found out that the Turkmenbashi lived like a rock star during his dictatorship. He even made a golden image of himself that is always looking at the sun!. Despite the fact that he was a dictator, his sense of humour deserves .How it worksAccording to PEP 3143, a UNIX daemon process should close all open file descriptors, change the current working directory to something helpful, reset the file access creation mask to something more appropriate, detach from process group and control terminal and stop receiving I/O signals. However, it does not create childrens when getting SIGCLD signals and it does not provide System V init startup management.How to implement itWhat this class do is to provide a collection of methods that are needed to convert a class into a daemon. This class must extend the Turkmenbashi class (correctly kept in the Python Library Path) and use some methods to configure the instance.This is an implementation of a daemon that does nothing but print debugs.from Turkmenbashi import Turkmenbashiclass Daemon (Turkmenbashi.DaemonCreator):def __init__(self): # startup definition Turkmenbashi.__init__(self)def config(self): # config definition self.turk_set_pid_file('/var/run/daemon.pid') self.turk_set_log_file('/var/log/daemon.log') self.turk_set_temp_dir('/tmp') self.turk_set_log_level('debug') self.turk_set_log_msize(10485760)def turk_daemon_run(self): while True: # what should your daemon do self.turk_debug('a debug message') self.turk_info('an info message') self.turk_warning('a warning message') self.turk_error('an error message') self.turk_critical('a critical message')How to run itI created a small piece of code to start, stop and restart a daemon. You should modify it to suit your needs.#!/usr/bin/env python#-*- coding:utf-8 -*-import osimport sysfrom mydaemon import Daemondaemon = Daemon()daemon.turk_start() # starts the daemon.daemon.turk_restart() # stops and then starts the daemon.daemon.turk_stop() # stops the daemon. Requirements: · Python


Turkmenbashi Related Software