]> git.llucax.com Git - software/pymin.git/blobdiff - pymind
Move logging module setup to pymind.
[software/pymin.git] / pymind
diff --git a/pymind b/pymind
index 37feab9243c9b201251f6add59aa7227c214dc68..22fb0923a838b082617a6cef265475214a429a37 100755 (executable)
--- a/pymind
+++ b/pymind
@@ -1,8 +1,49 @@
 #!/usr/bin/env python
 # vim: set encoding=utf-8 et sw=4 sts=4 :
 
-from pymindaemon import PyminDaemon
+import sys
+import logging ; log = logging.getLogger('pymind')
+# First of all, we need to setup the logging framework
+# FIXME: this should go in a configuration file
+logging.basicConfig(
+        level   = logging.DEBUG,
+        format  = '%(asctime)s %(name)-24s %(levelname)-8s %(message)s',
+        datefmt = '%a, %d %b %Y %H:%M:%S',
+)
+
+from pymin.pymindaemon import PyminDaemon
+from pymin.dispatcher import Handler
+from pymin.service import load_service, LoadError
 import config
 
-PyminDaemon(config.routes, config.bind_addr).run()
+# exit status
+EXIT_NO_SERVICE = 1
+
+class Root(Handler):
+    pass
+
+def build_root(config):
+    # TODO check services dependencies
+    services = dict()
+    for service in config.services:
+        try:
+            s = load_service(service, config.services_dirs)
+        except LoadError, e:
+            log.error("Can't find service called '%s'\n", service)
+            sys.exit(EXIT_NO_SERVICE)
+        services[service] = s
+    root = Root()
+    for name, service in services.items():
+        setattr(root, name, service.get_service(config))
+    return root
+
+# FIXME
+try:
+    f = file("/proc/sys/net/ipv4/ip_forward","w")
+    f.write("1")
+    f.close()
+except (IOError, OSError), e:
+    log.warning("Can't set ip_forward: %s", e)
+
+PyminDaemon(build_root(config), config.bind_addr).run()