예제 #1
0
파일: format.py 프로젝트: NBSW/slapos.core
    def take_action(self, args):
        configp = self.fetch_config(args)

        conf = FormatConfig(logger=self.app.log)

        conf.mergeConfig(args, configp)

        # Parse if we have to check if running from root
        # XXX document this feature.
        if string_to_boolean(getattr(conf, 'root_check', 'True').lower()):
          check_root_user(self)

        if not self.app.options.log_file and conf.log_file:
            # no log file is provided by argparser,
            # we set up the one from config
            file_handler = logging.FileHandler(conf.log_file)
            formatter = logging.Formatter(self.app.LOG_FILE_MESSAGE_FORMAT)
            file_handler.setFormatter(formatter)
            self.app.log.addHandler(file_handler)

        try:
            conf.setConfig()
        except UsageError as err:
            sys.stderr.write(err.message + '\n')
            sys.stderr.write("For help use --help\n")
            sys.exit(1)

        tracing_monkeypatch(conf)

        do_format(conf=conf)
예제 #2
0
    def take_action(self, args):
        configp = self.fetch_config(args) # read the options in .cfg

        conf = FormatConfig(logger=self.app.log)

        conf.mergeConfig(args, configp) # commandline options overwrite .cfg options

        # Parse if we have to check if running from root
        # XXX document this feature.
        if string_to_boolean(getattr(conf, 'root_check', 'True').lower()):
          check_root_user(self)

        if len(self.app.log.handlers) == 0 and not self.app.options.log_file and conf.log_file:
            # This block is called again if "slapos node boot" failed.
            # Don't add a handler again, otherwise the output becomes double.
            #
            # no log file is provided by argparser,
            # we set up the one from config
            file_handler = logging.FileHandler(conf.log_file)
            formatter = logging.Formatter(self.app.LOG_FILE_MESSAGE_FORMAT)
            file_handler.setFormatter(formatter)
            self.app.log.addHandler(file_handler)

        try:
            conf.setConfig()
        except UsageError as err:
            sys.stderr.write(err.message + '\n')
            sys.stderr.write("For help use --help\n")
            sys.exit(1)

        tracing_monkeypatch(conf)

        do_format(conf=conf)
예제 #3
0
    def take_action(self, args):
        configp = self.fetch_config(args)
        options = merged_options(args, configp)

        # Parse if we have to check if running from root
        # XXX document this feature.
        if string_to_boolean(options.get('root_check', 'True').lower()):
          check_root_user(self)

        check_missing_parameters(options)
        check_missing_files(options)

        random_delay(options, logger=self.app.log)

        slapgrid_object = create_slapgrid_object(options, logger=self.app.log)

        pidfile = options.get('pidfile') or self.default_pidfile

        if pidfile:
            setRunning(logger=self.app.log, pidfile=pidfile)
        try:
            return getattr(slapgrid_object, self.method_name)()
        finally:
            if pidfile:
                setFinished(pidfile)
예제 #4
0
    def take_action(self, args):
        configp = self.fetch_config(args)

        # Parse if we have to check if running from root
        # XXX document this feature.
        if self._should_check_current_user_is_root(configp):
            check_root_user(self)

        instance_root = configp.get('slapos', 'instance_root')
        forbid_supervisord_launch = self._should_forbid_supervisord_launch(configp)
        do_supervisorctl(
            self.app.log, instance_root, args.supervisor_args,
            forbid_supervisord_launch
        )