def quit(message="", exitCode=0): """Exit program displaying corresponding text message and returning appropiate errorcode. Cleanup before exiting. Input: (string) text mesasge, default: ""; (int) exit code, default: 0 Output: none """ # display info message if exiting normaly # otherwise consider it as error message if message: if exitCode == 0: info(message) else: error(message) info("--- Executing shutdown modules ---") if exitCode == 0: from bsdradius import modules modules.execShutdownModules() info("--- Bsdradiusd exiting ---") # disconnect from DB from bsdradius import DatabaseConnection if "bsdradius dbh1" in DatabaseConnection.DatabaseConnection.handlers: dbh1 = DatabaseConnection.DatabaseConnection.getHandler("bsdradius dbh1") if dbh1.isConnected(): info("Closing DB connections") dbh1.disconnect() info("--- Closing threads ---") threads = threading.enumerate() tCurrent = threading.currentThread() for th in threads: if th != tCurrent: th.exit() th.join() # close log file from bsdradius import logger if logger.logFile: if not logger.logFile.closed: info("--- Closing logfile ---") logger.logFile.close() logger.logFile = None # remove pidfile pidFilePath = main_config["PATHS"]["pid_file"] if os.path.exists(pidFilePath): info("--- Removing pidfile ---") os.remove(pidFilePath) else: error("Cannot remove pid file: ", pidFilePath) # exit without raising exception # os._exit(exitCode) sys.exit(exitCode)
def quit(message="", exitCode=0): """Exit program displaying corresponding text message and returning appropiate errorcode. Cleanup before exiting. Input: (string) text mesasge, default: ""; (int) exit code, default: 0 Output: none """ # display info message if exiting normaly # otherwise consider it as error message if message: if exitCode == 0: info(message) else: error(message) info('--- Executing shutdown modules ---') if exitCode == 0: from bsdradius import modules modules.execShutdownModules() info("--- Bsdradiusd exiting ---") # disconnect from DB from bsdradius import DatabaseConnection if 'bsdradius dbh1' in DatabaseConnection.DatabaseConnection.handlers: dbh1 = DatabaseConnection.DatabaseConnection.getHandler( 'bsdradius dbh1') if dbh1.isConnected(): info('Closing DB connections') dbh1.disconnect() info('--- Closing threads ---') threads = threading.enumerate() tCurrent = threading.currentThread() for th in threads: if th != tCurrent: th.exit() th.join() # close log file from bsdradius import logger if logger.logFile: if not logger.logFile.closed: info('--- Closing logfile ---') logger.logFile.close() logger.logFile = None # remove pidfile pidFilePath = main_config['PATHS']['pid_file'] if os.path.exists(pidFilePath): info('--- Removing pidfile ---') os.remove(pidFilePath) else: error('Cannot remove pid file: ', pidFilePath) # exit without raising exception #os._exit(exitCode) sys.exit(exitCode)