def main(args): config_filename = args.config_filename debug = args.debug skip_pid_check = args.skip_pid_check first_time = True old_server_address = None sock = None while 1: # This is the main loop for the flup server. # Why is it a loop? A SIGHUP sent to the server # will shut down flup then reread the configuration # file, reload the extension modules, and start # the flup server again. try: settings, config = read_config.read_config(config_filename) except read_config.Error, err: logger.fatal(str(err)) if first_time: raise SystemExit("Cannot start Akara. Exiting.") else: raise SystemExit("Cannot restart Akara. Exiting.") akara.raw_config = config # Establish the global configuration module set_global_config(settings) # In debug mode (-X), display all log messages. # Otherwise, use the configuration level if debug: logger.setLevel(logging.DEBUG) else: logger.setLevel(settings["log_level"]) # Open this now, so any errors can be reported try: logger_config.set_logfile(settings["error_log"]) except IOError, err: # Only give the 'akara setup' text here because it's where # we get to with an empty/nonexistant configuration file. logger.fatal("""\ Could not open the Akara error log: %s Does that directory exist and is it writeable? You may want to use 'akara setup' to set up the directory structure.""" % err) sys.exit(1)
except IOError, err: # Only give the 'akara setup' text here because it's where # we get to with an empty/nonexistant configuration file. logger.fatal("""\ Could not open the Akara error log: %s Does that directory exist and is it writeable? You may want to use 'akara setup' to set up the directory structure.""" % err) sys.exit(1) # Configure the access log try: logger_config.set_access_logfile(settings["access_log"]) except IOError, err: logger.fatal("""\ Could not open the Akara access log: %s Does that directory exist and is it writeable?""" % err) sys.exit(1) # Don't start if the PID file already exists. pid_file = settings["pid_file"] if first_time and (not skip_pid_check) and os.path.exists(pid_file): msg = ("Akara PID file %r already exists. Is another Akara instance running?\n" "If not, remove the file or use the '-f' option to skip this check") logger.fatal(msg % (pid_file,)) raise SystemExit(1) if debug or not first_time: notify_parent = NoParent()
# Only give the 'akara setup' text here because it's where # we get to with an empty/nonexistant configuration file. logger.fatal("""\ Could not open the Akara error log: %s Does that directory exist and is it writeable? You may want to use 'akara setup' to set up the directory structure.""" % err) sys.exit(1) # Don't start if the PID file already exists. pid_file = settings["pid_file"] if first_time and (not skip_pid_check) and os.path.exists(pid_file): msg = ("Akara PID file %r already exists. Is another Akara instance running?\n" "If not, remove the file or use the '-f' option to skip this check") logger.fatal(msg % (pid_file,)) raise SystemExit(1) if debug or not first_time: notify_parent = NoParent() else: # Spawn off the actual listener. # The parent will always raise an exception, and never return. try: notify_parent = demonize() except Exception, err: # This can come from the parent or the child. logger.critical("Cannot spawn HTTP server", exc_info=True) raise SystemExit("Exiting - check the log file for details")