def start(): lines = pluginsReader.lineReader() global lock plugins = [] try: # Read through the plugin list and load them with the indicated ports lock = threading.Lock() for key in lines: #first index is plugin name plugin = __import__(key) for port in lines[key]: try: plugins.append(plugin.server_plugin(lock, port)) except socket.error as msg: print 'Plugin not opened on port, error.' time.sleep(1) # wait 1 second so last plugin has time to bind if os.name == 'posix' and platform.dist()[0] == '': drop_privileges_Arch() # drops root privileges else: drop_privileges() while True: time.sleep(1) # Keeps the program running until keyboard interrupt closes. except KeyboardInterrupt: lock.acquire() print '\nexiting via KeyboardInterrupt' for plugin in plugins: plugin.tear_down() # Graceful closure of each plugin and its open sockets lock.release() sys.exit() except Exception as e: lock.acquire() print('ERROR: ' + str(e)) for plugin in plugins: plugin.tear_down() lock.release() sys.exit()
def start(): lines = pluginsReader.lineReader() global lock plugins = [] try: lock = threading.Lock() for line in lines: plug = line.pop(0) #first index is plugin name plugin = __import__(plug) for port in line: plugins.append(plugin.server_plugin(lock, port)) time.sleep(1) # wait 1 second so last plugin has time to bind if os.name == 'posix' and platform.dist()[0] == '': drop_privileges_Arch() else: drop_privileges() while True: time.sleep(1) except KeyboardInterrupt: lock.acquire() print '\nexiting via KeyboardInterrupt' for plugin in plugins: plugin.tear_down() lock.release() sys.exit() except Exception as e: lock.acquire() print('ERROR: ' + str(e)) for plugin in plugins: plugin.tear_down() lock.release() sys.exit()