Esempio n. 1
0
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.')
    parser.add_argument('-egb', '--enable_gbmonitor', action='store_true', help='Enable gevent block monitor.', default=False)
    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)
Esempio n. 2
0
    def arg_initialize(self):
        if bootstrap.pyon_initialized:
            raise BadRequest("Pyon already initalized")

        parser = argparse.ArgumentParser()
        parser.add_argument("-s",
                            "--sysname",
                            dest="sysname",
                            help="System name")

        options, extra = parser.parse_known_args()
        args, command_line_config = parse_args(extra)

        # -------------------------------------------------------------------------
        # 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)

        # 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)
        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)

        # ion_config - Holds the new CFG object for the system (independent of this tool's config)
        ion_config = config.read_standard_configuration()
        config.apply_configuration(ion_config, command_line_config)

        # Bootstrap pyon's core. Load configuration etc.
        bootstrap.bootstrap_pyon(pyon_cfg=ion_config)
Esempio n. 3
0
    def arg_initialize(self):
        if bootstrap.pyon_initialized:
            raise BadRequest("Pyon already initalized")

        parser = argparse.ArgumentParser()
        parser.add_argument("-s", "--sysname", dest="sysname", help="System name")

        options, extra = parser.parse_known_args()
        args, command_line_config = parse_args(extra)

        # -------------------------------------------------------------------------
        # 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)

        # 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)
        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)

        # ion_config - Holds the new CFG object for the system (independent of this tool's config)
        ion_config = config.read_standard_configuration()
        config.apply_configuration(ion_config, command_line_config)

        # Bootstrap pyon's core. Load configuration etc.
        bootstrap.bootstrap_pyon(pyon_cfg=ion_config)
Esempio n. 4
0
File: pycc.py Progetto: ooici/pyon
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.",
    )
    parser.add_argument(
        "-egb", "--enable_gbmonitor", action="store_true", help="Enable gevent block monitor.", default=False
    )
    opts, extra = parser.parse_known_args()
    args, kwargs = parse_args(extra)

    print "pycc: OOINet 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)
Esempio n. 5
0
def entry():
    """
    Parses arguments and daemonizes 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='Exits the container if the only procs started were of immediate type')
    parser.add_argument('-l', '--logcfg', type=str, help='Logging config file or config dict content')
    parser.add_argument('-mp', '--multiproc', type=str, help='Start n containers total in separate processes')
    parser.add_argument('-mx', '--mx', action='store_true', help='Start admin Web UI')
    parser.add_argument('-n', '--noshell', action='store_true', help="Do not start a shell")
    parser.add_argument('-o', '--nomanhole', action='store_true', help="Do not start remote-able manhole shell")
    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='Deploy file to launch')
    parser.add_argument('-ra', '--relall', action='store_true', help='Launch deploy file on all child processes')
    parser.add_argument('-s', '--sysname', type=str, help='System name')
    parser.add_argument('-sp', '--signalparent', action='store_true', help='Signal parent process after procs started')
    parser.add_argument('-v', '--version', action='version', version='ScionCC 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: SciON Container starter with command line options:", str(opts)

    # -o or --nomanhole implies --noshell
    if opts.nomanhole:
        opts.noshell = True

    if opts.multiproc:
        num_proc = int(opts.multiproc)
        if num_proc > 1:
            print "pycc: Starting %s child container processes" % (num_proc-1)
            global child_procs, childproc_go
            childproc_go = Event()
            for i in range(1, num_proc):
                pinfo = dict(procnum=i)
                pname = "Container-child-%s" % pinfo['procnum']
                p = Process(name=pname, target=start_childproc, args=(pinfo, opts, args, kwargs))
                p.start()
                child_procs.append(p)

    if opts.daemon:
        from daemon import DaemonContext
        from lockfile import FileLock

        print "pycc: Daemonize 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)
Esempio n. 6
0
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/core/org.yml

        Load service definition from a file
        bin/python bin/store_interfaces  -s mysysname -sf obj/services/core/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 SciON config and interfaces, 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_db_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_db_util.clear_db(bootstrap_config, prefix=bootstrap.get_sys_name(), sysname=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()
Esempio n. 7
0
def entry():
    """
    Parses arguments and daemonizes 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=
        'Exits the container if the only procs started were of immediate type')
    parser.add_argument('-l',
                        '--logcfg',
                        type=str,
                        help='Logging config file or config dict content')
    parser.add_argument('-mp',
                        '--multiproc',
                        type=str,
                        help='Start n containers total in separate processes')
    parser.add_argument('-mx',
                        '--mx',
                        action='store_true',
                        help='Start admin Web UI')
    parser.add_argument('-n',
                        '--noshell',
                        action='store_true',
                        help="Do not start a shell")
    parser.add_argument('-o',
                        '--nomanhole',
                        action='store_true',
                        help="Do not start remote-able manhole shell")
    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='Deploy file to launch')
    parser.add_argument('-ra',
                        '--relall',
                        action='store_true',
                        help='Launch deploy file on all child processes')
    parser.add_argument('-s', '--sysname', type=str, help='System name')
    parser.add_argument('-sp',
                        '--signalparent',
                        action='store_true',
                        help='Signal parent process after procs started')
    parser.add_argument('-v',
                        '--version',
                        action='version',
                        version='ScionCC 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: SciON Container starter with command line options:", str(opts)

    # -o or --nomanhole implies --noshell
    if opts.nomanhole:
        opts.noshell = True

    if opts.multiproc:
        num_proc = int(opts.multiproc)
        if num_proc > 1:
            print "pycc: Starting %s child container processes" % (num_proc -
                                                                   1)
            global child_procs, childproc_go
            childproc_go = Event()
            for i in range(1, num_proc):
                pinfo = dict(procnum=i)
                pname = "Container-child-%s" % pinfo['procnum']
                p = Process(name=pname,
                            target=start_childproc,
                            args=(pinfo, opts, args, kwargs))
                p.start()
                child_procs.append(p)

    if opts.daemon:
        from daemon import DaemonContext
        from lockfile import FileLock

        print "pycc: Daemonize 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)
Esempio n. 8
0
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/core/org.yml

        Load service definition from a file
        bin/python bin/store_interfaces  -s mysysname -sf obj/services/core/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)

    log.info("Storing SciON config and interfaces, with options: %s",
             str(options))

    from pyon.core import log as logutil
    logutil.configure_logging(logutil.DEFAULT_LOGGING_PATHS)

    # -------------------------------------------------------------------------
    # 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_db_util
        from pyon.util.file_sys import FileSystem
        log.info("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_db_util.clear_db(bootstrap_config,
                               prefix=bootstrap.get_sys_name(),
                               sysname=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()