def SetInitState(cfg, state): """Sets system's initialization state. For oneway, it stores it in C.ENT_SYSTEM_INIT_STATE. For Clusters, it stores it in chubby file /ls/ent<version>/ENT_SYSTEM_INIT_STATE. @param cfg - of type configurator. @param state - string """ # oneway? if 1 == len(core_utils.GetNodes()): cfg.setGlobalParam(C.ENT_SYSTEM_INIT_STATE, state) return tmpfile = E.mktemp('/export/hda3/tmp') try: f = open(tmpfile, 'w') f.write(state) f.close() except IOError: logging.fatal('Cannot write to temp file %s' % tmpfile) return version = cfg.getGlobalParam('VERSION') lockserv_cmd_prefix = core_utils.GetLSClientCmd(version, is_test(version)) chubby_root_dir = '/ls/%s' % core_utils.GetCellName(version) write_cmd = '%s cp %s %s/%s' % (lockserv_cmd_prefix, tmpfile, chubby_root_dir, 'ENT_SYSTEM_INIT_STATE') logging.info('setting system init state to: %s', state) E.exe_or_fail(write_cmd) E.exe('rm -rf %s' % tmpfile)
def deactivate(self): """ deactivate this service and macke the cron script unexecutable """ E.exe_or_fail("/sbin/chkconfig --del %s_%s" % ( self.service_name, self.version)) E.exe_or_fail("chmod 644 /etc/cron.%s/cron_%s_%s" % ( self.service_cron_time, self.service_name, self.version))
def activate(self): """ activates this service and makes it's periodic cron script executable """ E.exe_or_fail("/sbin/chkconfig --add %s_%s" % ( self.service_name, self.version)) E.exe_or_fail("chmod 755 /etc/cron.%s/cron_%s_%s" % ( self.service_cron_time, self.service_name, self.version))
def deactivate(self): """ Override this for some extra cleanup""" ent_service.ent_service.deactivate(self) # Remove cronjobs relating to this install version ONLY... tmp_cron_file = "%s/tmp/nobody_cron_crawl_" % self.ent_home E.exe_or_fail("""if $(/usr/bin/crontab -lu %s &>/dev/null); then crontab -lu %s | grep -v %s > %s; crontab -u %s %s; fi""" % \ (self.ent_user, self.ent_user, self.entid_tag, tmp_cron_file, self.ent_user, tmp_cron_file)) return 1
def RunServeService(config, action, components=''): """Runs serve service with given parameters. The command template used for serve service has --ignore_init_state parameter passed. This will force the execution of serve service regardless of the initialization state of the system. @param config - entconfig @param action - any action supported by serve service like 'start', 'stop', ... @param components - If non empty, will be supplied to serve service command. """ cmd = C.SERVE_SERVICE_COMMAND % { 'bashrc' : config.var('ENTERPRISE_BASHRC'), 'home' : config.var('ENTERPRISE_HOME'), 'action' : action } if components: cmd = '%s %s' % (cmd, C.SERVE_SERVICE_COMPONENTS % components) logging.info('Executing %s' % cmd) E.exe_or_fail(cmd)
def activate(self): """ Override this for some extra links to be done / crontab""" ent_service.ent_service.activate(self) # remove any existing /root/google* symlinks and create new ones for link_name, target_fmt in [('/root/google', '%s/local/google'), ('/root/google2', '%s/local/google'), ('/root/google3', '%s/local/google3')]: E.exe_or_fail("rm -rf %s" % link_name) E.exe_or_fail("ln -sf %s %s" % (target_fmt % self.ent_home, link_name)) E.exe_or_fail("chown %s:%s %s" % (self.ent_user, self.ent_group, link_name)) # make sure /root is publicly readable so that we can run things under it E.exe_or_fail("chmod 755 /root") # set up standard crontab on each machine E.su_exe_or_fail( self.ent_user, ". %s; cd %s/local/google3/enterprise/legacy/util; " "%s ./set_standard_crontab.py %s" % (self.ent_bashrc, self.ent_home, self.entid_tag, self.ent_home)) return 1
def activate(self): """ Override this for some extra links to be done / crontab""" ent_service.ent_service.activate(self) # remove any existing /root/google* symlinks and create new ones for link_name, target_fmt in [('/root/google', '%s/local/google'), ('/root/google2', '%s/local/google'), ('/root/google3', '%s/local/google3')]: E.exe_or_fail("rm -rf %s" % link_name) E.exe_or_fail("ln -sf %s %s" % (target_fmt % self.ent_home, link_name)) E.exe_or_fail("chown %s:%s %s" % (self.ent_user, self.ent_group, link_name)) # make sure /root is publicly readable so that we can run things under it E.exe_or_fail("chmod 755 /root") # set up standard crontab on each machine E.su_exe_or_fail(self.ent_user, ". %s; cd %s/local/google3/enterprise/legacy/util; " "%s ./set_standard_crontab.py %s" % ( self.ent_bashrc, self.ent_home, self.entid_tag, self.ent_home)) return 1