def execute(flag_config_file, flag_data, flag_servertype, flag_machineparam, flag_portparam, flag_no_extra_req): if not flag_servertype: sys.exit("Must specify a servertype") if not flag_machineparam: sys.exit("Invalid machine param") if not flag_portparam: sys.exit("Invalid port param") data = None try: exec("data = %s" % flag_data) except: sys.exit("data param cannot be interpreted") if type(data) != type({}): sys.exit("Invalid data param %s" % data) cp = config_factory.ConfigFactory().CreateConfig(flag_config_file) if not cp.Load(): sys.exit("Unable to load config file %s" % (cp.GetConfigFileName())) ret = [] servers = cp.GetServerMap(servertype.CollectTypes(flag_servertype, {})) for port, machines in servers.items(): for m in machines: # Compose the request with data req = autorunner.Request() req.SetData(data) req.SetValue(flag_machineparam, m) req.SetValue(flag_portparam, port) ret.append(req) if not flag_no_extra_req and not cp.WriteConfigManagerRequest(req): sys.exit("Error savig request") cp.DistributeAll() return ret
def execute(flag_config_file, flag_epoch_list, flag_server_types, flag_no_extra_req): if not flag_config_file: sys.exit("Must specify a config file") server_types = None epoch_list = None try: exec("server_types = %s" % flag_server_types) exec("epoch_list = %s" % flag_epoch_list) except: sys.exit("Invalid value %s or %s" % (flag_server_types, flag_epoch_list)) cp = config_factory.ConfigFactory().CreateConfig(flag_config_file) if not cp.Load(): sys.exit("Unable to load config file %s" % (cp.GetConfigFileName())) # Register requests per machine # Prepare adummy request to send server command req = server_requests.SendServerCommandRequest() req.Set("dummy", 1, "GET /update?%s HTTP/1.0\r\n\r\n" % \ (string.join(map(lambda e: "EpochDelete=%d" % e, epoch_list), "&")), "HTTP/1.0 200 OK", cp.GetConfigFileName()) requests = [] # The actual requests that registers req for each machine:port # for all server types for stype in server_types: the_req = configmgr_request.MultiRequestCreateRequest() the_req.Set(req.datadict, stype, server_requests.MACHINE, server_requests.PORT, cp.GetConfigFileName()) if not flag_no_extra_req and not cp.WriteConfigManagerRequest(the_req): sys.exit("Cannot save subsequent request to update param on machine") requests.append(the_req) cp.DistributeAll() return requests
def SetMasterNTP(config): """ Rewrite the content of the master-node /etc/ntp.conf file """ global_file = config.GetConfigFileName() # full_config contains all the Enterprise environment variables. full_config = config_factory.ConfigFactory().CreateConfig(global_file) if not full_config.Load(): logging.error("Cannot read file %s " % global_file) else: if full_config.var('NTP_SERVERS'): ntp_server_list = full_config.var('NTP_SERVERS') reconfigurenet_util.AddDefaultNTPServer(ntp_server_list) # combine list of NTP servers into a single comma-separated string. server_arg = ','.join(ntp_server_list) # Run a set-uid program to rewrite /etc/ntp.conf os.system("/usr/local/sbin/reconfigure_net NTP %s" % server_arg) else: logging.error( "Missing variable NTP_SERVERS. Can not set master NTP. ")
def main(argv): if len(argv) != 1: sys.exit(__doc__) pidfile = E.GetPidFileName('loop_webserver_config') E.WritePidFile(pidfile) config = config_factory.ConfigFactory().CreateConfig(argv[0]) if not config.Load(): logging.error("Cannot read file: %s " % argv[0]) bashrc = config.var('ENTERPRISE_HOME') + "/local/conf/ent_bashrc" # the loop while 1: cmd = (". %s; /usr/bin/python2.4 webserver_config.py %s" % (bashrc, config.var('ENTERPRISE_HOME'))) logging.info("Executing %s" % cmd) os.system(cmd) # sleep for a while time.sleep(5)
flags.DEFINE_boolean("kill_only", false, "Dont restart, just kill") flags.DEFINE_boolean("use_python2", false, "use python2 to invoke babysitter") def main(argv): try: argv = FLAGS(argv) # parse flags except flags.FlagsError, e: print "%s\nUsage: %s ARGS\n%s" % (e, sys.argv[0], FLAGS) sys.exit(1) if not FLAGS.machine: sys.exit("Must specify a machine") if not FLAGS.port: sys.exit("Must specify a port") if not FLAGS.config_file: sys.exit("Config file must be specified") cp = config_factory.ConfigFactory().CreateConfig(FLAGS.config_file) if not cp.Load(): sys.exit("Unable to load config file %s" % (cp.GetConfigFileName())) use_invalid_config = "" if FLAGS.useinvalidconfig: use_invalid_config = "--useinvalidconfig" python2_invoke_string = "" if FLAGS.use_python2: # we want to invoke using python2 python2_invoke_string = "python2 " action = "--start=all" if FLAGS.kill_only:
def execute(flag_config_file, flag_param, flag_value, flag_op, flag_force, flag_force_no_validate, flag_no_extra_req): """ Performs the actual operation. Params correponding to the flags Error is signalled on sys.exit. All return codes are OK and are different to be used by the unittest. The return is (exitcode, written_requests) """ if not flag_param: sys.exit("Must specify a paramter") # if the param name starts with a (, it's a tuple if flag_param[0] == '(': param = eval(flag_param, {}, {}) else: param = flag_param value = None try: value = eval(flag_value, {}, {}) except: sys.exit("Invalid value %s" % flag_value) cp = config_factory.ConfigFactory().CreateConfig(flag_config_file) if not cp.Load(): sys.exit("Unable to load config file %s" % (cp.GetConfigFileName())) # STEP 1. # First we get a list of changed params, which we will use later to take # care of restarting servers, etc.. We have to do it before we actually # set the value so we can see if the value changed. if flag_op == 'set_var': # a normal parameter; use GetChangedParams() to recurse any maps and return # all changed submaps. param_change_list = GetChangedParams(param, value, cp, flag_force) elif flag_op == 'set_file_var_content': # file content; just this parameter changed param_change_list = [(param, value)] else: # we don't do side effects for del_var, del_file_var_content param_change_list = [] # STEP 2. # Next we do as we were asked and set the parameter. We treat setting # file content specially. if flag_op == 'set_var': # If we don't force, don't update params that did not change if not flag_force and cp.has_var(param) and cp.var(param) == value: logging.info("New value for parameter [%s] unchanged." % (param, )) return (1, None) if (not cp.set_var(param, value, not flag_force_no_validate) in validatorlib.VALID_CODES): logging.info( "New value for parameter [%s] did not validate correctly" % (param, )) return (2, None) if not cp.Save(cp.GetConfigFileName()): sys.exit("Params saving failed") elif flag_op == 'del_var': cp.del_var(param) if not cp.Save(cp.GetConfigFileName()): sys.exit("Params saving failed") elif flag_op == 'del_file_var_content': cp.del_file_var_content(param) elif flag_op == 'set_file_var_content': try: value_to_set = open(value, "r").read() except IOError, e: sys.exit("Cannot open the file provided as value %s [%s]" % (value, e)) do_update = true if not flag_force: try: oldval = open(cp.var(param), "r").read() do_update = oldval != value_to_set except IOError: pass # we update if not do_update: logging.info("New value for file parameter [%s] unchanged." % (param, )) return (3, None) if (not cp.set_file_var_content(param, value_to_set, not flag_force_no_validate) in validatorlib.VALID_CODES): logging.info( "New value for file parameter [%s] did not validate correctly" % (param, )) return (4, None)
class InstallManager: def __init__(self): self.cp_ = None self.machines_ = None self.target_state_ = None self.version_ = None self.enthome_ = None self.core_only_ = None self.nonecore_only_ = None self.retry_ = None self.core_op_ = None self.reinitok_ = None def parse_cmd_line_args(self, argv): try: argv = FLAGS(argv) # parse flags except flags.FlagsError, e: sys.exit("%s\nUsage: %s ARGS\n%s" % (e, argv[0], FLAGS)) if ((FLAGS.enthome and FLAGS.config) or (not FLAGS.enthome and not FLAGS.config)): sys.exit("Please specify only one of --enthome and --config") if FLAGS.makeactive: self.target_state_ = "ACTIVE" elif FLAGS.makeserve: self.target_state_ = "SERVE" elif FLAGS.makeinactive: self.target_state_ = "INACTIVE" elif FLAGS.maketesting: self.target_state_ = "TEST" elif FLAGS.makeinstall: self.target_state_ = "INSTALL" elif FLAGS.list: self.target_state_ = "LIST" elif FLAGS.docoreop: self.core_op_ = FLAGS.docoreop if FLAGS.coreonly: self.core_only_ = 1 if FLAGS.nonecoreonly: self.nonecore_only_ = 1 if FLAGS.retry: self.retry = 1 if FLAGS.reinitok: self.reinitok_ = 1 if not self.target_state_ and not FLAGS.docoreop: sys.exit("Please specify one and only one of "\ "--makeactive --makeserve --makeinactive "\ "--maketesting --makeinstall --list or --docoreop") if self.core_only_ and self.nonecore_only_: sys.exit( "Please specify only one of --coreonly and --nonecoreonly") if FLAGS.enthome: self.cp_ = entconfig.EntConfig(FLAGS.enthome) else: cf = config_factory.ConfigFactory() self.cp_ = cf.CreateConfig(FLAGS.config) if not self.cp_.Load(): sys.exit("ERROR: Cannot load the config file") if FLAGS.machines: self.machines_ = map(string.strip, string.split(FLAGS.machines, ",")) else: self.machines_ = self.cp_.var("MACHINES") self.version_ = self.cp_.var('VERSION') self.enthome_ = self.cp_.GetEntHome() E.ENTERPRISE_HOME = self.enthome_
def main(argv): """ expects: argv[0] to be a machine name, argv[1] be a google_config file - copys google_config file from the machine specified into the local machine (by calling CopyFile() function) - calls ReplicateConfig() - which """ if len(argv) < 2: sys.exit(__doc__) machine = argv[0] global_file = argv[1] global_dir = os.path.dirname(global_file) if E.getCrtHostName() == machine: logging.info("I do not try to replicate to myself") sys.exit(0) config = config_factory.ConfigFactory().CreateConfig(global_file) if not config.Load(): sys.exit("ERROR: Cannot read file %s " % global_file) file_to_copy = [ C.ETC_SYSCONFIG, global_file, "%s/lic_counter" % global_dir, "%s/lic_counter.bck" % global_dir, "%s/passwd" % global_dir, "/export/hda3/versionmanager/vmanager_passwd", "%s/server.p12" % global_dir ] # Sync all the files for f in file_to_copy: CopyFile(machine, f, production_tmp) # sync apache certificate CopyFileAsRoot(machine, (ssl_cert.CERT_FILENAME % config.var('ENTERPRISE_HOME')), production_tmp, config) # sync private key CopyFileAsRoot(machine, (ssl_cert.KEY_FILENAME % config.var('ENTERPRISE_HOME')), production_tmp, config) # sync the support request repository directory # GRR: ReplicateDirectory(machine, SUPPORTREQUEST_RECORDS_DIR) # replicate config including per collection/frontend stuff # some dirs in conf don't need to be rsync'ed if core_utils.CanRunGSAMaster(E.getCrtHostName()): exclude_patterns = [ 'cmr_working/failure/', 'cmr_working/success/', 'cmr_working/statusz/' ] else: exclude_patterns = [ 'cmr_working/', 'cmr/', 'fixer/', 'fixer_cmr/', 'gems' ] ReplicateDirectory(machine, "%s/local/conf/" % config.var('ENTERPRISE_HOME'), exclude_patterns) # to replicate per frontend gws stuff (keymatches, gws bad urls) ReplicateDirectory(machine, "%s/gws/" % config.var('GOOGLEDATA')) # need to adjust NTP if master has changed # assumption : this machine is not the master if 'PILE' != config.var('ENT_CONFIG_TYPE'): ent_home = E.getEnterpriseHome() os.system("%s NTP %s" % (C.RECONFIGURE_COMMAND % ent_home, machine)) # also make sure DNS is up to date os.system( "%s DNS %s %s" % (C.RECONFIGURE_COMMAND % ent_home, config.var('BOT_DNS_SERVERS'), config.var('DNS_SEARCH_PATH')))