comparison roundup/scripts/roundup_server.py @ 3111:e0aab0d08265 maint-0.8

fix roundup-server log and PID file paths to be absolute fix initialisation of roundup-server in daemon mode so initialisation errors are visible
author Richard Jones <richard@users.sourceforge.net>
date Sat, 15 Jan 2005 06:53:00 +0000
parents e4bac783c617
children 07f68dfab2c2
comparison
equal deleted inserted replaced
3110:3b03be557150 3111:e0aab0d08265
15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 15 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
16 # 16 #
17 17
18 """Command-line script that runs a server over roundup.cgi.client. 18 """Command-line script that runs a server over roundup.cgi.client.
19 19
20 $Id: roundup_server.py,v 1.74.2.1 2004-12-22 06:38:08 a1s Exp $ 20 $Id: roundup_server.py,v 1.74.2.2 2005-01-15 06:53:00 richard Exp $
21 """ 21 """
22 __docformat__ = 'restructuredtext' 22 __docformat__ = 'restructuredtext'
23 23
24 import errno, cgi, getopt, os, socket, sys, traceback, urllib 24 import errno, cgi, getopt, os, socket, sys, traceback, urllib
25 import ConfigParser, BaseHTTPServer, SocketServer, StringIO 25 import ConfigParser, BaseHTTPServer, SocketServer, StringIO
390 for option in self._get_section_options("trackers"): 390 for option in self._get_section_options("trackers"):
391 trackers.append((option, os.path.abspath( 391 trackers.append((option, os.path.abspath(
392 self["TRACKERS_" + option.upper()]))) 392 self["TRACKERS_" + option.upper()])))
393 return trackers 393 return trackers
394 394
395 def set_logging(self):
396 """Initialise logging to the configured file, if any."""
397 # appending, unbuffered
398 sys.stdout = sys.stderr = open(self["LOGFILE"], 'a', 0)
399
395 def get_server(self): 400 def get_server(self):
396 """Return HTTP server object to run""" 401 """Return HTTP server object to run"""
397 # redirect stdout/stderr to our logfile
398 # this is done early to have following messages go to this logfile
399 if self["LOGFILE"]:
400 # appending, unbuffered
401 sys.stdout = sys.stderr = open(self["LOGFILE"], 'a', 0)
402 # we don't want the cgi module interpreting the command-line args ;) 402 # we don't want the cgi module interpreting the command-line args ;)
403 sys.argv = sys.argv[:1] 403 sys.argv = sys.argv[:1]
404 # preload all trackers unless we are in "debug" mode 404 # preload all trackers unless we are in "debug" mode
405 tracker_homes = self.trackers() 405 tracker_homes = self.trackers()
406 if self["MULTIPROCESS"] == "debug": 406 if self["MULTIPROCESS"] == "debug":
476 servicemanager.LogMsg(servicemanager.EVENTLOG_ERROR_TYPE, 476 servicemanager.LogMsg(servicemanager.EVENTLOG_ERROR_TYPE,
477 servicemanager.PYS_SERVICE_STOPPED, 477 servicemanager.PYS_SERVICE_STOPPED,
478 (self._svc_display_name_, "\r\nMissing logfile option")) 478 (self._svc_display_name_, "\r\nMissing logfile option"))
479 self.ReportServiceStatus(win32service.SERVICE_STOPPED) 479 self.ReportServiceStatus(win32service.SERVICE_STOPPED)
480 return 480 return
481 config.set_logging()
481 self.server = config.get_server() 482 self.server = config.get_server()
482 self.running = 1 483 self.running = 1
483 self.ReportServiceStatus(win32service.SERVICE_RUNNING) 484 self.ReportServiceStatus(win32service.SERVICE_RUNNING)
484 servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, 485 servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
485 servicemanager.PYS_SERVICE_STARTED, (self._svc_display_name_, 486 servicemanager.PYS_SERVICE_STARTED, (self._svc_display_name_,
603 os._exit(0) 604 os._exit(0)
604 605
605 os.chdir("/") 606 os.chdir("/")
606 os.umask(0) 607 os.umask(0)
607 608
608 # close off sys.std(in|out|err), redirect to devnull so the file 609 # close off std(in|out|err), redirect to devnull so the file
609 # descriptors can't be used again 610 # descriptors can't be used again
610 devnull = os.open('/dev/null', 0) 611 devnull = os.open('/dev/null', 0)
611 os.dup2(devnull, 0) 612 os.dup2(devnull, 0)
612 os.dup2(devnull, 1) 613 os.dup2(devnull, 1)
613 os.dup2(devnull, 2) 614 os.dup2(devnull, 2)
687 688
688 # port number in function arguments overrides config and command line 689 # port number in function arguments overrides config and command line
689 if port is not undefined: 690 if port is not undefined:
690 config.PORT = port 691 config.PORT = port
691 692
693 if config["LOGFILE"]:
694 config["LOGFILE"] = os.path.abspath(config["LOGFILE"])
695 # switch logging from stderr/stdout to logfile
696 config.set_logging()
697 if config["PIDFILE"]:
698 config["PIDFILE"] = os.path.abspath(config["PIDFILE"])
699
692 # fork the server from our parent if a pidfile is specified 700 # fork the server from our parent if a pidfile is specified
693 if config["PIDFILE"]: 701 if config["PIDFILE"]:
694 if not hasattr(os, 'fork'): 702 if not hasattr(os, 'fork'):
695 print _("Sorry, you can't run the server as a daemon" 703 print _("Sorry, you can't run the server as a daemon"
696 " on this Operating System") 704 " on this Operating System")

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