* tried to put some sense in the way things get logged, at least on server-side for now
[sfa.git] / sfa / server / sfa-server.py
index 58bfdb9..96b9625 100755 (executable)
@@ -34,10 +34,10 @@ registry_port=12345
 aggregate_port=12346
 slicemgr_port=12347
 component_port=12346
-
 import os, os.path
 import sys
 from optparse import OptionParser
+from sfa.util.sfalogging import sfa_logger
 from sfa.trust.trustedroot import TrustedRootList
 from sfa.trust.certificate import Keypair, Certificate
 from sfa.trust.hierarchy import Hierarchy
@@ -57,7 +57,7 @@ def daemon():
     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
-    crashlog = os.open('/var/log/sfa.daemon', os.O_RDWR | os.O_APPEND | os.O_CREAT, 0644)
+    crashlog = os.open('/var/log/httpd/sfa_access_log', os.O_RDWR | os.O_APPEND | os.O_CREAT, 0644)
     os.dup2(crashlog, 1)
     os.dup2(crashlog, 2)
 
@@ -147,15 +147,14 @@ def init_server(options, config):
         try: manager = __import__(manager_module, fromlist=[manager_base])
         except: manager = None
         if manager and hasattr(manager, 'init_server'):
-            manager.init_server()    
-            
+            manager.init_server()
 
-def sync_interfaces():
+def sync_interfaces(server_key_file, server_cert_file):
     """
     Attempt to install missing trusted gids and db records for 
     our federated interfaces
     """
-    api = SfaAPI()
+    api = SfaAPI(key_file = server_key_file, cert_file = server_cert_file)
     registries = Registries(api)
     aggregates = Aggregates(api)
     registries.sync_interfaces()
@@ -185,7 +184,6 @@ def main():
          help="Run as daemon.", default=False)
     (options, args) = parser.parse_args()
 
-    if (options.daemon):  daemon()
 
     config = Config()
     hierarchy = Hierarchy()
@@ -194,8 +192,9 @@ def main():
 
     init_server_key(server_key_file, server_cert_file, config, hierarchy)
     init_server(options, config)
-    sync_interfaces()   
+    sync_interfaces(server_key_file, server_cert_file)   
  
+    if (options.daemon):  daemon()
     # start registry server
     if (options.registry):
         from sfa.server.registry import Registry
@@ -220,4 +219,7 @@ def main():
         c.start()
 
 if __name__ == "__main__":
-    main()
+    try:
+        main()
+    except:
+        sfa_logger.log_exc_critical("SFA server is exiting")