turkmenbashi-python

A library to write UNIX daemons
Download

turkmenbashi-python Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Rodrigo Fuentealba
  • Publisher web site:
  • http://github.com/rfc83/

turkmenbashi-python Tags


turkmenbashi-python Description

turkmenbashi-python is a helpful resource to write an UNIX daemon in Python, by providing functions to start, stop and restart 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 to be recognized.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 does 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:import turkmenbashiclass DebugDaemon (turkmenbashi.daemon_creator): def config(self): self.turk_state = True self.turk_state = "/var/run/daemon.pid" self.turk_state = "/tmp" self.turk_state = 60 def daemon(self): print "A debug message"if __name__=="__main__": d = DebugDaemon() d.config() d.turk_start(d.daemon)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:import osimport sysimport turkmenbashidaemon = turkmenbashi.daemoncreator()daemon.turk_start() # starts the daemon.daemon.turk_restart() # stops and then starts the daemon.daemon.turk_stop() # stops the daemon.SourceThe source can be browsed at (http://github.com/rfc83/Turkmenbashi "Turkmenbashi Daemon Creator")Product's homepage


turkmenbashi-python Related Software