* 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 134b44a..96b9625 100755 (executable)
@@ -34,15 +34,18 @@ 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
 from sfa.util.config import Config
 from sfa.util.report import trace
+from sfa.plc.api import SfaAPI
+from sfa.server.registry import Registries
+from sfa.server.aggregate import Aggregates
 
 # after http://www.erlenstar.demon.co.uk/unix/faq_2.html
 def daemon():
@@ -54,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)
 
@@ -144,8 +147,18 @@ 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(server_key_file, server_cert_file):
+    """
+    Attempt to install missing trusted gids and db records for 
+    our federated interfaces
+    """
+    api = SfaAPI(key_file = server_key_file, cert_file = server_cert_file)
+    registries = Registries(api)
+    aggregates = Aggregates(api)
+    registries.sync_interfaces()
+    aggregates.sync_interfaces()
 
 def main():
     # xxx get rid of globals - name consistently CamelCase or under_score
@@ -171,17 +184,17 @@ def main():
          help="Run as daemon.", default=False)
     (options, args) = parser.parse_args()
 
-    if (options.daemon):  daemon()
 
     config = Config()
     hierarchy = Hierarchy()
-    trusted_roots = TrustedRootList(config.get_trustedroots_dir())
     server_key_file = os.path.join(hierarchy.basedir, "server.key")
     server_cert_file = os.path.join(hierarchy.basedir, "server.cert")
 
     init_server_key(server_key_file, server_cert_file, config, hierarchy)
-    init_server(options, config)   
+    init_server(options, config)
+    sync_interfaces(server_key_file, server_cert_file)   
  
+    if (options.daemon):  daemon()
     # start registry server
     if (options.registry):
         from sfa.server.registry import Registry
@@ -206,4 +219,7 @@ def main():
         c.start()
 
 if __name__ == "__main__":
-    main()
+    try:
+        main()
+    except:
+        sfa_logger.log_exc_critical("SFA server is exiting")