Running a script as a daemon at boot time
Engel, Gregory
Gregory_Engel at csgsystems.com
Wed May 29 18:09:53 EDT 2002
I've a script which in part serves as an HTTP server. I can run this as a background process when logged on as myself. I need to find a way to have the script run as a daemon at boot time. I have written a script for /etc.rc.d/init.d and it responds well to start/stop commands. However, when a GET request arrives at the server, the process dies without generating an error (at least that I've been able to trap.) The do_GET is as follows:
def do_GET(self):
self.ServerLog('Requested GET')
htmlpage = '<html><head>'
htmlpage = htmlpage + '<title>Green Bar Queue Processor</title>'
htmlpage = htmlpage + '</hted><body>'
htmlpage = htmlpage + '<p style="font: Arial;">Green Bar Queue Processor - ' + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(time.time())) + '<hr></p>'
htmlpage = htmlpage + '</body></html>'
notfound = 'File not found.'
if self.path == "/":
self.ServerLog('Mark 1') # This line gets logged...
self.send_response(200)
self.ServerLog('Mark 1') # This line DOES NOT get logged...
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(htmlpage)
else:
self.send_error(404, notfound)
When the background process is initiated from the command line, this error does not occur and the daemon performs as needed. Why would this fail as a boot (inet.d) initiated script and not from the command line? The startup script is as follows:
---- start gbqp---
#!/bin/sh
#
# Startup script for GBQueueProcessor.py
#
# processname: python
# pidfile: /var/run/gbqp.pid
# config: GBQueueProcessor.conf
# Source function library.
. /etc/rc.d/init.d/functions
[ -f /usr/local/bin/GBQueueProcessor.py ] || exit 0
RETVAL=0
start() {
echo -n "Starting gbqpd: "
daemon /usr/local/bin/gbqpd
echo
touch /var/lock/subsys/gbqpd
return $RETVAL
}
stop() {
echo -n "Shutting down gbqpd: "
GBQPDPID=
GBQPDPID=$(cat /var/run/gbqpd.pid)
kill $GBQPDPID
echo
rm -f /var/lock/subsys/gbqpd /var/run/gbqpd.pid
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
GBQPDPID=
GBQPDPID=$(cat /var/run/gbqpd.pid)
echo -n "Checking for gbqpd, PID is : " $GBQPDPID
echo
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start | stop | restart | status}"
exit 1
esac
exit 0
---- end gbqp---
---- start gbqpd---
#!/bin/sh
exec python /usr/local/bin/GBQueueProcessor.py
---- end gbqpd---
C'ya,
Gregory Engel
Senior Software Engineer
Professional Services
CSG Systems, Inc.
9555 Maroon Circle
Englewood, CO 80112
Voice: 303-200-3426
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
My other computer is spongy gray matter.
More information about the Python-list
mailing list