self.__dict__[option] = value
except ConfigParser.Error, e:
- logging.critical("Error reading config file "+config_file+": " + str(e))
- logging.critical("Bailing out")
- sys.exit(1)
+ raise SystemExit("Error reading config file "+config_file+": " + str(e))
def create_pid_file(name):
try:
signal.signal(signal.SIGINT, stop_server)
options = parse_args()
- set_up_logging(options)
config_opts = VendConfigFile(options.config_file, config_options)
if options.daemon: become_daemon()
+ set_up_logging(options)
if options.pid_file != '': create_pid_file(options.pid_file)
return options, config_opts
def set_up_logging(options):
logger = logging.getLogger()
- stderr_logger = logging.StreamHandler(sys.stderr)
- stderr_logger.setFormatter(logging.Formatter('%(levelname)s: %(message)s'))
- logger.addHandler(stderr_logger)
+ if not options.daemon:
+ stderr_logger = logging.StreamHandler(sys.stderr)
+ stderr_logger.setFormatter(logging.Formatter('%(levelname)s: %(message)s'))
+ logger.addHandler(stderr_logger)
if options.log_file != '':
try:
os.dup2(fd, 0)
os.dup2(fd, 1)
os.dup2(fd, 2)
- if os.fork() != 0:
- sys.exit(0)
+ logging.debug('about to fork')
+ try:
+ if os.fork() != 0:
+ logging.debug('in parent process: dying')
+ sys.exit(0)
+ logging.debug('back from fork')
+ os.setsid()
+ except OSError, e:
+ logging.critical('failed to fork: '+e)
def do_vend_server(options, config_opts):
while True: