X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=geni%2Fplc.py;h=a9322ad43c2cdd4871e806ab4e061fe6f361af0f;hb=7e4c8f954a9fec491537accb7b50ecf90ce48c9d;hp=a30225d5b9633ed9f0fe9d65d635b097d186929b;hpb=dbe99265ce616673e1c7f66f8ac4e19be8f68df2;p=sfa.git diff --git a/geni/plc.py b/geni/plc.py index a30225d5..a9322ad4 100644 --- a/geni/plc.py +++ b/geni/plc.py @@ -1,3 +1,4 @@ +#!/usr/bin/python ## # GENI PLC Wrapper # @@ -14,10 +15,10 @@ # is up to date and accurate. # # 1) Import the existing planetlab database, creating the -# appropriate geni records. This is done by running the "import.py" tool. +# appropriate geni records. This is done by running the "gimport.py" tool. # # 2) Create a "trusted_roots" directory and place the certificate of the root -# authority in that directory. Given the defaults in import.py, this +# authority in that directory. Given the defaults in gimport.py, this # certificate would be named "planetlab.gid". For example, # # mkdir trusted_roots; cp authorities/planetlab.gid trusted_roots/ @@ -40,6 +41,21 @@ from geni.registry import Registry from geni.aggregate import Aggregate from geni.slicemgr import SliceMgr + +# 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 + crashlog = os.open('/var/log/geni.daemon', os.O_RDWR | os.O_APPEND | os.O_CREAT, 0644) + os.dup2(crashlog, 1) + os.dup2(crashlog, 2) + def main(): global AuthHierarchy global TrustedRoots @@ -57,16 +73,28 @@ def main(): help="run aggregate manager", default=False) parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="verbose mode", default=False) + parser.add_option("-d", "--daemon", dest="daemon", action="store_true", + help="Run as daemon.", default=False) (options, args) = parser.parse_args() key_file = "server.key" cert_file = "server.cert" + + if (options.daemon): daemon() - # if no key is specified, then make one up - if (not os.path.exists(key_file)) or (not os.path.exists(cert_file)): + if (os.path.exists(key_file)) and (not os.path.exists(cert_file)): + # If private key exists and cert doesnt, recreate cert + key = Keypair(filename=key_file) + cert = Certificate(subject="registry") + cert.set_issuer(key=key, subject="registry") + cert.set_pubkey(key) + cert.sign() + cert.save_to_file(cert_file) + + elif (not os.path.exists(key_file)) or (not os.path.exists(cert_file)): + # if no key is specified, then make one up key = Keypair(create=True) key.save_to_file(key_file) - cert = Certificate(subject="registry") cert.set_issuer(key=key, subject="registry") cert.set_pubkey(key)