def setup_the_app(options): """ Gets a lock on the app directory, sets up log manager and related files, runs the daemon, and then unlocks the app directory in a finally block. """ app_name = options.app_name lock_mgr = None access_log = None error_log = None try: lock_mgr = ProcLock(app_name) log_mgr = LogMgr(options.log_dir) options.log_mgr = log_mgr access_log = log_mgr.open('access') options.access_log = access_log alertz_log = log_mgr.open(app_name) options.alertz_log = alertz_log error_log = log_mgr.open('error') options.error_log = error_log actually_run_the_daemon(options) finally: if log_mgr is not None: log_mgr.close() if lock_mgr is not None: lock_mgr.unlock()
def invoke_the_daemon(options): """ Completes setting up the namespace; if this isn't a "just-show" run, gets a lock on u_path, invokes wrapped code, and releases u_path lock in a finally block. """ if options.verbose or options.show_version or options.just_show: print(options.pgm_name_and_version) if options.show_timestamp: print(('run at %s GMT' % options.timestamp)) # could be prettier else: print() # there's a comma up there if options.just_show or options.verbose: print(dump_options(options)) lock_mgr = None log_mgr = None if not options.just_show: try: lock_mgr = ProcLock(options.u_path) log_mgr = LogMgr(options.log_dir) options.log_mgr = log_mgr setup_u_server(options) finally: if log_mgr is not None: log_mgr.close() if lock_mgr is not None: lock_mgr.unlock()
def run_the_daemon(options): """ Completes setting up the namespace; if this isn't a "just-show" run, creates lock and log managers, creates the logs, and actually runs the daemon. """ if options.verbose or options.showVersion or options.justShow: print(options.pgm_name_and_version, end=' ') if options.showTimestamp: print('run at %s GMT' % options.timestamp) # could be prettier else: print() # there's a comma up there if options.justShow or options.verbose: print(dump_options(options)) if not options.justShow: lock_mgr = None access_log = None error_log = None try: lock_mgr = ProcLock('alertzd') options.lock_mgr = lock_mgr log_mgr = LogMgr(options.log_dir) options.log_mgr = log_mgr access_log = log_mgr.open('access') options.access_log = access_log alertz_log = log_mgr.open('alertz') options.alertz_log = alertz_log error_log = log_mgr.open('error') options.error_log = error_log _actually_run_the_daemon(options) except BaseException: traceback.print_exc() sys.exit(1) finally: lock_mgr.unlock()