Simple TCP Server || Daemonize || Continuous

Andrew Bennetts andrew-pythonlist at puzzling.org
Tue Feb 4 06:28:01 EST 2003


On Tue, Feb 04, 2003 at 05:57:18AM -0500, Metnetsky wrote:
> <posted & mailed>
> 
> Alex Martelli wrote:
> 
> > Metnetsky wrote:
> >    ...
> >> sure I can get).  The big thing here is the transformation into a daemon.
> >> How can I make this python script fork itself away from it's parent?
> > 
> > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012
> > 
> > 
> > Alex
> 
> Just about perfect, thank you.  It however raises the question: what needs 
> to be modified to allow this daemon to be started by INETD?  What should be 
> removed to make this capable of being an INETD daemon?  And how can I have 
> INETD start a python script on boot?  

Writing an inetd(8) daemon is much easier than this.

You simply write a program that reads from stdin and writes to stdout, as
usual.  inetd will arrange for those file descriptors to actually be the
socket (but you can just treat it like any other file descriptor).

Thus a simple shell script, which does 

    #/bin/sh
    echo "Content-Type: text/html"
    echo
    echo "<html>Look ma... I'm a webserver.</html>"

would work as a stupid webserver, if started from inetd.

In short, you can completely ignore daemonisation if you want to run your
server from inetd.

Refer to your inetd.conf(5) man page for details of configuring inetd to run
your program.  It's pretty simple.

-Andrew.






More information about the Python-list mailing list