comparison roundup/scripts/roundup_server.py @ 1047:1890c611de08

add daemonification
author Richard Jones <richard@users.sourceforge.net>
date Wed, 04 Sep 2002 07:32:55 +0000
parents 6003d6fa02a5
children 88ded00fa0e0
comparison
equal deleted inserted replaced
1046:483b60650524 1047:1890c611de08
14 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 14 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
16 # 16 #
17 """ HTTP Server that serves roundup. 17 """ HTTP Server that serves roundup.
18 18
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 $
20 """ 20 """
21 21
22 # python version check 22 # python version check
23 from roundup import version_check 23 from roundup import version_check
24 24
166 166
167 def usage(message=''): 167 def usage(message=''):
168 if message: 168 if message:
169 message = _('Error: %(error)s\n\n')%{'error': message} 169 message = _('Error: %(error)s\n\n')%{'error': message}
170 print _('''%(message)sUsage: 170 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]*
172 172
173 -n: sets the host name 173 -n: sets the host name
174 -p: sets the port to listen on 174 -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
175 177
176 name=instance home 178 name=instance home
177 Sets the instance home(s) to use. The name is how the instance is 179 Sets the instance home(s) to use. The name is how the instance is
178 identified in the URL (it's the first part of the URL path). The 180 identified in the URL (it's the first part of the URL path). The
179 instance home is the directory that was identified when you did 181 instance home is the directory that was identified when you did
184 sys.exit(0) 186 sys.exit(0)
185 187
186 def run(): 188 def run():
187 hostname = '' 189 hostname = ''
188 port = 8080 190 port = 8080
191 pidfile = None
192 logfile = None
189 try: 193 try:
190 # handle the command-line args 194 # handle the command-line args
191 try: 195 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:')
193 except getopt.GetoptError, e: 197 except getopt.GetoptError, e:
194 usage(str(e)) 198 usage(str(e))
195 199
196 user = ROUNDUP_USER 200 user = ROUNDUP_USER
197 for (opt, arg) in optlist: 201 for (opt, arg) in optlist:
198 if opt == '-n': hostname = arg 202 if opt == '-n': hostname = arg
199 elif opt == '-p': port = int(arg) 203 elif opt == '-p': port = int(arg)
200 elif opt == '-u': user = arg 204 elif opt == '-u': user = arg
205 elif opt == '-d': pidfile = arg
206 elif opt == '-l': logfile = arg
201 elif opt == '-h': usage() 207 elif opt == '-h': usage()
202 208
203 if hasattr(os, 'getuid'): 209 if hasattr(os, 'getuid'):
204 # if root, setuid to the running user 210 # if root, setuid to the running user
205 if not os.getuid() and user is not None: 211 if not os.getuid() and user is not None:
236 usage('%s: %s'%(exc_type, exc_value)) 242 usage('%s: %s'%(exc_type, exc_value))
237 243
238 # we don't want the cgi module interpreting the command-line args ;) 244 # we don't want the cgi module interpreting the command-line args ;)
239 sys.argv = sys.argv[:1] 245 sys.argv = sys.argv[:1]
240 address = (hostname, port) 246 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
241 httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler) 260 httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler)
242 print _('Roundup server started on %(address)s')%locals() 261 print _('Roundup server started on %(address)s')%locals()
243 httpd.serve_forever() 262 httpd.serve_forever()
244 263
245 if __name__ == '__main__': 264 if __name__ == '__main__':
246 run() 265 run()
247 266
248 # 267 #
249 # $Log: not supported by cvs2svn $ 268 # $Log: not supported by cvs2svn $
269 # Revision 1.6 2002/08/30 08:33:28 richard
270 # new CGI frontend support
271 #
250 # Revision 1.5 2002/03/14 23:59:24 richard 272 # Revision 1.5 2002/03/14 23:59:24 richard
251 # . #517734 ] web header customisation is obscure 273 # . #517734 ] web header customisation is obscure
252 # 274 #
253 # Revision 1.4 2002/02/21 07:02:54 richard 275 # Revision 1.4 2002/02/21 07:02:54 richard
254 # The correct var is "HTTP_HOST" 276 # The correct var is "HTTP_HOST"

Roundup Issue Tracker: http://roundup-tracker.org/