""" GeventDaemon.__init__(self) # WSGI configuration from daemon config host = self.config("wsgi-server", "host", "0.0.0.0", str) port = self.config("wsgi-server", "port", 80, int) debug = self.config("wsgi-server", "debug", True, bool) # Get reference to the database we're using base = self.config("storage", "base", "/srv/imagerack", str) self.img_path = "%s/%s" % (base, self.config("storage", "img", "images", str)) self.web_path = "%s/%s" % (base, self.config("storage", "web", "web", str)) # Create WSGI server self.server = pywsgi.WSGIServer((host, port)) self.server.application = WsgiHandler(self.logger, self.img_path, self.web_path) def handle_run(self): """ Logic for starting the DMS management daemon. """ self.server.serve_forever() def handle_stop(self): """ Logic for stopping the DMS management daemon. """ self.server.stop() main = make_main(ImagerackDaemon)
def __init__(self): """ Initialize the management daemon. """ GeventDaemon.__init__(self) # WSGI configuration from /etc/<name>.conf host = self.config("server", "host", "0.0.0.0", str) port = self.config("server", "port", 80, int) # Set up logging log_level = self.config("logging", "level", 10, int) self.logger.setLevel(log_level) # Create WSGI server self.application = WsgiApplication(self.logger, self.config) def handle_run(self): """ Logic for starting the DMS management daemon. """ self.application.start() def handle_stop(self): """ Logic for stopping the DMS management daemon. """ self.application.stop() main = make_main(MyWsgiDaemon)
... mydaemon INFO: ping! somenewvalue Run the daemon in the foreground to get debug logging and respond to ctrl-c (SIGINT): $ sudo python example.py foreground """ name = "mydaemon" description = "I'm so cool" def handle_prerun(self): self.logger.info("handle_prerun always runs as root") self._shutdown = False def handle_run(self): self.logger.info("handle_run is run as a configured user (default is root)") while not self._shutdown: some_config_value = self.config("mydaemon", "somevalue", "defaultvalue") self.logger.info("ping! %r" % some_config_value) time.sleep(2) self.logger.warning("oh no I'm totally dead!") def handle_stop(self): self.logger.info("trying to shutdown") self._shutdown = True # Create a main function, with help and fancy option parsing main = make_main(MyDaemon) if __name__ == "__main__": main()