support running as daemon
diff --git a/planetstack/planetstack-backend.py b/planetstack/planetstack-backend.py
index 7d94b67..7fac3d6 100755
--- a/planetstack/planetstack-backend.py
+++ b/planetstack/planetstack-backend.py
@@ -1,10 +1,41 @@
 #!/usr/bin/env python
 import os
+import argparse
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "planetstack.settings")
-from observer.backend import Backend 
+from observer.backend import Backend
+from planetstack.config import Config 
 
-if __name__ == '__main__':
+config = Config()
+
+# after http://www.erlenstar.demon.co.uk/unix/faq_2.html
+def daemon():
+    """Daemonize the current process."""
+    if os.fork() != 0: os._exit(0)
+    os.setsid()
+    if os.fork() != 0: os._exit(0)
+    os.umask(0)
+    devnull = os.open(os.devnull, os.O_RDWR)
+    os.dup2(devnull, 0)
+    # xxx fixme - this is just to make sure that nothing gets stupidly lost - should use devnull
+    logdir=os.path.dirname(config.observer.logfile)
+    # when installed in standalone we might not have httpd installed
+    if not os.path.isdir(logdir): os.mkdir(logdir)
+    crashlog = os.open('%s'%config.observer.logfile, os.O_RDWR | os.O_APPEND | os.O_CREAT, 0644)
+    os.dup2(crashlog, 1)
+    os.dup2(crashlog, 2)
+
+def main():
+    # Generate command line parser
+    parser = argparse.ArgumentParser(usage='%(prog)s [options]')
+    parser.add_argument('-d', '--daemon', dest='daemon', action='store_true', default=False, 
+                        help='Run as daemon.')
+    args = parser.parse_args()
+       
+    if args.daemon: daemon()
 
     backend = Backend()
-    backend.run()
- 
+    backend.run()    
+
+if __name__ == '__main__':
+    
+    main() 
diff --git a/planetstack/plstackapi_config b/planetstack/plstackapi_config
index 6abdaaf..5d95231 100644
--- a/planetstack/plstackapi_config
+++ b/planetstack/plstackapi_config
@@ -19,6 +19,7 @@
 omf_enabled=0
 mail_support_address=support@localhost
 nova_enabled=True
+logfile=/var/log/planetstack.log
 
 [nova]
 admin_user=admin@domain.com
@@ -31,3 +32,4 @@
 
 [observer]
 dependency_graph=/opt/planetstack/model-deps
+logfile=/var/log/planetstack_backend.log