]> git.llucax.com Git - software/pymin.git/blobdiff - pymind
Shutdown logging properly when exiting pymind.
[software/pymin.git] / pymind
diff --git a/pymind b/pymind
index ee586a4e7a175c5259510d41b8dead3bd449ad7c..3857ef89288af301088b3dbcc4703aa339d3a5dd 100755 (executable)
--- a/pymind
+++ b/pymind
@@ -80,29 +80,29 @@ def activate_ip_forward():
         log.warning("Can't set ip_forward: %s", e)
 
 
+def die(status, msg, *args):
+    log.critical(msg, *args)
+    logging.shutdown()
+    sys.exit(status)
+
 def get_config(paths, version, desc, add_options, defaults):
     global config_file_paths
     try:
         (config, args) = load_config(paths, version, desc, add_options, defaults)
     except ConfigError, e:
-        log.critical(str(e))
-        sys.exit(EXIT_CONFIG_ERROR)
+        die(EXIT_CONFIG_ERROR, str(e))
     except MissingSectionHeaderError, e:
-        log.critical("%s:%s: missing section header near: %s", e.filename, e.lineno,
-                  e.line)
-        sys.exit(EXIT_CONFIG_ERROR)
+        dir(EXIT_CONFIG_ERROR, "%s:%s: missing section header near: %s",
+            e.filename, e.lineno, e.line)
     except ParsingError, e:
         for (lineno, line) in e.errors:
             log.critical("%s:%s: invalid syntax near: %s", e.filename, lineno, line)
-        log.critical(str(e.errors))
-        sys.exit(EXIT_CONFIG_ERROR)
+        die(EXIT_CONFIG_ERROR, str(e.errors))
     except Invalid, e:
-        log.critical(str(e.unpack_errors()))
-        sys.exit(EXIT_CONFIG_ERROR)
+        die(EXIT_CONFIG_ERROR, str(e.unpack_errors()))
     except LoadError, e:
-        log.critical("service '%s' not found (see option --services-dir)",
-                  e.service_name)
-        sys.exit(EXIT_NO_SERVICE)
+        die(EXIT_NO_SERVICE, "service '%s' not found (see option " \
+            "--services-dir)", e.service_name)
     return (config, args)
 
 
@@ -134,6 +134,7 @@ def main():
     root_handler = build_root(config, args, services.services)
     activate_ip_forward()
     PyminDaemon(root_handler, (config.bind_addr, config.bind_port)).run()
+    logging.shutdown()
 
 if __name__ == '__main__':
     main()