1616#
1717""" HTTP Server that serves roundup.
1818
19- $Id: roundup_server.py,v 1.6 2002-08-30 08:33:28 richard Exp $
19+ $Id: roundup_server.py,v 1.7 2002-09-04 07:32:55 richard Exp $
2020"""
2121
2222# python version check
@@ -168,10 +168,12 @@ def usage(message=''):
168168 if message :
169169 message = _ ('Error: %(error)s\n \n ' )% {'error' : message }
170170 print _ ('''%(message)sUsage:
171- roundup-server [-n hostname] [-p port] [name=instance home]*
171+ roundup-server [-n hostname] [-p port] [-l file] [-d file] [ name=instance home]*
172172
173173 -n: sets the host name
174174 -p: sets the port to listen on
175+ -l: sets a filename to log to (instead of stdout)
176+ -d: daemonize, and write the server's PID to the nominated file
175177
176178 name=instance home
177179 Sets the instance home(s) to use. The name is how the instance is
@@ -186,10 +188,12 @@ def usage(message=''):
186188def run ():
187189 hostname = ''
188190 port = 8080
191+ pidfile = None
192+ logfile = None
189193 try :
190194 # handle the command-line args
191195 try :
192- optlist , args = getopt .getopt (sys .argv [1 :], 'n:p:u:' )
196+ optlist , args = getopt .getopt (sys .argv [1 :], 'n:p:u:d:l: ' )
193197 except getopt .GetoptError , e :
194198 usage (str (e ))
195199
@@ -198,6 +202,8 @@ def run():
198202 if opt == '-n' : hostname = arg
199203 elif opt == '-p' : port = int (arg )
200204 elif opt == '-u' : user = arg
205+ elif opt == '-d' : pidfile = arg
206+ elif opt == '-l' : logfile = arg
201207 elif opt == '-h' : usage ()
202208
203209 if hasattr (os , 'getuid' ):
@@ -238,6 +244,19 @@ def run():
238244 # we don't want the cgi module interpreting the command-line args ;)
239245 sys .argv = sys .argv [:1 ]
240246 address = (hostname , port )
247+
248+ # fork?
249+ if pidfile :
250+ pid = os .fork ()
251+ if pid :
252+ print 'forking' , pid
253+ open (pidfile , 'w' ).write (str (pid ))
254+ return
255+
256+ # redirect stdout/stderr
257+ if logfile :
258+ sys .stdout = sys .stderr = open (logfile , 'a' )
259+
241260 httpd = BaseHTTPServer .HTTPServer (address , RoundupRequestHandler )
242261 print _ ('Roundup server started on %(address)s' )% locals ()
243262 httpd .serve_forever ()
@@ -247,6 +266,9 @@ def run():
247266
248267#
249268# $Log: not supported by cvs2svn $
269+ # Revision 1.6 2002/08/30 08:33:28 richard
270+ # new CGI frontend support
271+ #
250272# Revision 1.5 2002/03/14 23:59:24 richard
251273# . #517734 ] web header customisation is obscure
252274#
0 commit comments