def entry(): """ Parses arguments and deamonizes process if requested """ # NOTE: Resist the temptation to add other parameters here! Most container config options # should be in the config file (pyon.yml), which can also be specified on the command-line via the extra args parser = argparse.ArgumentParser(description=description) parser.add_argument('-c', '--config', type=str, help='Additional config files to load or dict config content.', default=[]) parser.add_argument('-D', '--config_from_directory', action='store_true') parser.add_argument('-d', '--daemon', action='store_true') parser.add_argument('-fc', '--force_clean', action='store_true', help='Force clean system datastores before starting the container') parser.add_argument('-bc', '--broker_clean', action='store_true', help='Force clean broker of queues/exchanges belonging to sysname') parser.add_argument('-i', '--immediate', action='store_true', help='Will exit the container if the only procs started are immediate proc types. Sets CFG system.immediate flag.') parser.add_argument('-l', '--logcfg', type=str, help='Path to logging configuration file or dict config content.') parser.add_argument('-m', '--mx', action='store_true', help='Start a management web UI') parser.add_argument('-n', '--noshell', action='store_true') parser.add_argument('-o', '--nomanhole', action='store_true', help="Do not start a shell or a remote-able manhole shell. Implies -n") parser.add_argument('-p', '--pidfile', type=str, help='PID file to use when --daemon specified. Defaults to cc-<rand>.pid') parser.add_argument('-r', '--rel', type=str, help='Path to a rel file to launch.') parser.add_argument('-s', '--sysname', type=str, help='System name') parser.add_argument('-sp', '--signalparent', action='store_true', help='Signal parent process after service start up complete') parser.add_argument('-v', '--version', action='version', version='pyon v%s' % (version)) parser.add_argument('-x', '--proc', type=str, help='Qualified name of process to start and then exit.') parser.add_argument('-X', '--no_container', action='store_true', help='Perform pre-initialization steps and stop before starting a container.') opts, extra = parser.parse_known_args() args, kwargs = parse_args(extra) print "pycc: ION Container starter with command line options:" , str(opts) # -o or --nomanhole implies --noshell if opts.nomanhole: opts.noshell = True if opts.daemon: # TODO: The daemonizing code may need to be moved inside the Container class (so it happens per-process) from daemon import DaemonContext from lockfile import FileLock print "pycc: Deamonize process" # TODO: May need to generate a pidfile based on some parameter or cc name pidfile = opts.pidfile or 'cc-%s.pid' % str(uuid4())[0:4] with DaemonContext(pidfile=FileLock(pidfile)):#, stdout=logg, stderr=slogg): main(opts, *args, **kwargs) else: main(opts, *args, **kwargs)
def entry(): """ Parses arguments and deamonizes process if requested """ # NOTE: Resist the temptation to add other parameters here! Most container config options # should be in the config file (pyon.yml), which can also be specified on the command-line via the extra args parser = argparse.ArgumentParser(description=description) parser.add_argument( '-c', '--config', type=str, help='Additional config files to load or dict config content.', default=[]) parser.add_argument('-D', '--config_from_directory', action='store_true') parser.add_argument('-d', '--daemon', action='store_true') parser.add_argument( '-fc', '--force_clean', action='store_true', help='Force clean system datastores before starting the container') parser.add_argument( '-bc', '--broker_clean', action='store_true', help='Force clean broker of queues/exchanges belonging to sysname') parser.add_argument( '-i', '--immediate', action='store_true', help= 'Will exit the container if the only procs started are immediate proc types. Sets CFG system.immediate flag.' ) parser.add_argument( '-l', '--logcfg', type=str, help='Path to logging configuration file or dict config content.') parser.add_argument('-m', '--mx', action='store_true', help='Start a management web UI') parser.add_argument('-n', '--noshell', action='store_true') parser.add_argument( '-o', '--nomanhole', action='store_true', help="Do not start a shell or a remote-able manhole shell. Implies -n") parser.add_argument( '-p', '--pidfile', type=str, help= 'PID file to use when --daemon specified. Defaults to cc-<rand>.pid') parser.add_argument('-r', '--rel', type=str, help='Path to a rel file to launch.') parser.add_argument('-s', '--sysname', type=str, help='System name') parser.add_argument( '-sp', '--signalparent', action='store_true', help='Signal parent process after service start up complete') parser.add_argument('-v', '--version', action='version', version='pyon v%s' % (version)) parser.add_argument( '-x', '--proc', type=str, help='Qualified name of process to start and then exit.') parser.add_argument( '-X', '--no_container', action='store_true', help= 'Perform pre-initialization steps and stop before starting a container.' ) opts, extra = parser.parse_known_args() args, kwargs = parse_args(extra) print "pycc: ION Container starter with command line options:", str(opts) # -o or --nomanhole implies --noshell if opts.nomanhole: opts.noshell = True if opts.daemon: # TODO: The daemonizing code may need to be moved inside the Container class (so it happens per-process) from daemon import DaemonContext from lockfile import FileLock print "pycc: Deamonize process" # TODO: May need to generate a pidfile based on some parameter or cc name pidfile = opts.pidfile or 'cc-%s.pid' % str(uuid4())[0:4] with DaemonContext( pidfile=FileLock(pidfile)): #, stdout=logg, stderr=slogg): main(opts, *args, **kwargs) else: main(opts, *args, **kwargs)
def main(): ''' Store configuration and interfaces into the datastore How to run this from command line: bin/store_interfaces -s system name [ -of filename | -sf filename | -fc true|false] -of Load object definition file -sf Load service definition file -fc Force clean the database Example: Load all object and service definitions bin/python bin/store_interfaces -s mysysname Load all object and service definitions with force clean the database bin/python bin/store_interfaces -s mysysname -fc Load object definition from a file bin/python bin/store_interfaces -s mysysname -of obj/data/coi/org.yml Load service definition from a file bin/python bin/store_interfaces -s mysysname -sf obj/services/coi/datastore_service.yml ''' parser = argparse.ArgumentParser() parser.add_argument('-c', '--config', type=str, help='Additional config files to load or dict config content.', default=[]) parser.add_argument('-fc', '--force_clean', action='store_true', help='Force clean.') parser.add_argument("-of", "--object", dest="fobject", help="Load object definition from a file") parser.add_argument("-s", "--sysname", dest="sysname", help="System name") parser.add_argument("-sf", "--service", dest="fservice", help="Load service definition from a file") options, extra = parser.parse_known_args() args, command_line_config = parse_args(extra) print "store_interfaces: Storing ION config and interfaces in datastore, with options:" , str(options) # ------------------------------------------------------------------------- # Store config and interfaces # Set global testing flag to False. We are running as standalone script. This is NO TEST. bootstrap.testing = False # Set sysname if provided in startup argument if options.sysname: bootstrap.set_sys_name(options.sysname) # Load config override if provided. Supports variants literal and list of paths config_override = None if options.config: if '{' in options.config: # Variant 1: Dict of config values try: eval_value = ast.literal_eval(options.config) config_override = eval_value except ValueError: raise Exception("Value error in config arg '%s'" % options.config) else: # Variant 2: List of paths from pyon.util.config import Config config_override = Config([options.config]).data # bootstrap_config - Used for running this store_interfaces script bootstrap_config = config.read_local_configuration(['res/config/pyon_min_boot.yml']) config.apply_local_configuration(bootstrap_config, pyon.DEFAULT_LOCAL_CONFIG_PATHS) if config_override: config.apply_configuration(bootstrap_config, config_override) config.apply_configuration(bootstrap_config, command_line_config) # Override sysname from config file or command line if not options.sysname and bootstrap_config.get_safe("system.name", None): new_sysname = bootstrap_config.get_safe("system.name") bootstrap.set_sys_name(new_sysname) # Delete sysname datastores if option "force_clean" is set if options.force_clean: from pyon.datastore import clear_couch_util from pyon.util.file_sys import FileSystem print "store_interfaces: force_clean=True. DROP DATASTORES for sysname=%s" % bootstrap.get_sys_name() pyon_config = config.read_standard_configuration() # Initial pyon.yml + pyon.local.yml clear_couch_util.clear_couch(bootstrap_config, prefix=bootstrap.get_sys_name()) FileSystem._clean(pyon_config) # ion_config - Holds the new CFG object for the system (independent of this tool's config) ion_config = config.read_standard_configuration() if config_override: config.apply_configuration(ion_config, config_override) config.apply_configuration(ion_config, command_line_config) # ------------------------------------------------------------------------- # Store config and interfaces iadm = InterfaceAdmin(bootstrap.get_sys_name(), config=bootstrap_config) # Make sure core datastores exist iadm.create_core_datastores() # Store system CFG properties iadm.store_config(ion_config) # Store system interfaces iadm.store_interfaces(options.fobject, options.fservice) iadm.close()
def main(): ''' Store configuration and interfaces into the datastore How to run this from command line: bin/store_interfaces -s system name [ -of filename | -sf filename | -fc true|false] -of Load object definition file -sf Load service definition file -fc Force clean the database Example: Load all object and service definitions bin/python bin/store_interfaces -s mysysname Load all object and service definitions with force clean the database bin/python bin/store_interfaces -s mysysname -fc Load object definition from a file bin/python bin/store_interfaces -s mysysname -of obj/data/coi/org.yml Load service definition from a file bin/python bin/store_interfaces -s mysysname -sf obj/services/coi/datastore_service.yml ''' parser = argparse.ArgumentParser() parser.add_argument('-fc', '--force_clean', action='store_true', help='Force clean.') parser.add_argument("-of", "--object", dest="fobject", help="Load object definition from a file") parser.add_argument("-s", "--sysname", dest="sysname", help="System name") parser.add_argument("-sf", "--service", dest="fservice", help="Load service definition from a file") options, extra = parser.parse_known_args() args, command_line_config = parse_args(extra) print "store_interfaces: Storing ION config and interfaces in datastore, with options:" , str(options) # ------------------------------------------------------------------------- # Store config and interfaces # Set global testing flag to False. We are running as standalone script. This is NO TEST. bootstrap.testing = False # Set sysname if provided in startup argument if options.sysname: bootstrap.set_sys_name(options.sysname) # Load minimal bootstrap config bootstrap_config = config.read_local_configuration(['res/config/pyon_min_boot.yml']) config.apply_local_configuration(bootstrap_config, pyon.DEFAULT_LOCAL_CONFIG_PATHS) config.apply_configuration(bootstrap_config, command_line_config) # Delete sysname datastores if option "force_clean" is set if options.force_clean: from pyon.datastore import clear_couch_util print "store_interfaces: force_clean=True. DROP DATASTORES for sysname=%s" % bootstrap.get_sys_name() clear_couch_util.clear_couch(bootstrap_config, prefix=bootstrap.get_sys_name()) # This holds the new CFG object for the system # @TODO: Could add command line --config ion_config = config.read_standard_configuration() config.apply_configuration(ion_config, command_line_config) # ------------------------------------------------------------------------- # Store config and interfaces iadm = InterfaceAdmin(bootstrap.get_sys_name(), config=bootstrap_config) # Make sure core datastores exist iadm.create_core_datastores() # Store system CFG properties iadm.store_config(ion_config) # Store system interfaces iadm.store_interfaces(options.fobject, options.fservice) iadm.close()