Exemplo n.º 1
0
def StartAdminLoop(config, op='start'):
  """Start AdminRunner Loop as well as Loop for initial_config_Server"""

  install_state = install_utilities.install_state(config.VERSION)

  logging.info("Starting the AdminRunner")
  ar_args = []
  ar_args.append("--port=2100")
  ar_args.append("--enthome=%s" % config.ENTERPRISE_HOME)
  ar_args.append("--installstate=%s" % install_state)
  ar_args.append("--reset_status_cache_timeout=60")

  restart_loop_AdminRunner = 0
  if op == 'babysit':
    pidfile = E.GetPidFileName('loop_AdminRunner')
    pid = E.ReadPidFile(pidfile)
    if os_utils.GetAttr('pid', pid=pid, fallback_to_ps=0) == None:
      restart_loop_AdminRunner = 1

  if op == 'start' or restart_loop_AdminRunner:
    E.su_exe_or_fail(
      config.ENTERPRISE_USER,
      """ ps axwwwww | fgrep AdminRunner | fgrep -v fgrep | \
      colrm 7 | xargs kill -9 2> /dev/null; \
      . %(eb)s; \
      cd %(eh)s/local/google3/enterprise/legacy/scripts/ &&  \
      ENT_ID=%(v)s_crawl ./loop_AdminRunner.py \
      %(eh)s %(args)s >> \
      /%(ld)s/loop_AdminOut_`whoami` 2>&1 &""" % {
      'eh' : config.ENTERPRISE_HOME,
      'eb' : config.ENTERPRISE_BASHRC,
      'v' : config.VERSION,
      'ld' : config.LOGDIR,
      'args' : string.join(map(commands.mkarg, ar_args))
      })

  restart_loop_webserver_config = 0
  if op == 'babysit':
    pidfile = E.GetPidFileName('loop_webserver_config')
    pid = E.ReadPidFile(pidfile)
    if os_utils.GetAttr('pid', pid=pid, fallback_to_ps=0) == None:
      restart_loop_webserver_config = 1

  if (install_state != "INSTALL" and
      (op == 'start' or restart_loop_webserver_config)):
    logging.info("Starting webserver_config")
    E.su_exe_or_fail(
      config.ENTERPRISE_USER,
      """ ps axwwwww | fgrep webserver_config.py | fgrep -v fgrep \
      | colrm 7 | xargs kill -9 2> /dev/null; \
      . %s; \
      cd %s/enterprise/legacy/scripts/ && \
      ENT_ID=%s_crawl ./loop_webserver_config.py %s \
      >> /%s/loop_WebserverConfig_`whoami` 2>&1 &""" % (
      config.ENTERPRISE_BASHRC,
      config.MAIN_GOOGLE3_DIR, config.VERSION,
      config.GetConfigFileName(), config.LOGDIR))
Exemplo n.º 2
0
def StartAdminLoop(config, op='start'):
    """Start AdminRunner Loop as well as Loop for initial_config_Server"""

    install_state = install_utilities.install_state(config.VERSION)

    logging.info("Starting the AdminRunner")
    ar_args = []
    ar_args.append("--port=2100")
    ar_args.append("--enthome=%s" % config.ENTERPRISE_HOME)
    ar_args.append("--installstate=%s" % install_state)
    ar_args.append("--reset_status_cache_timeout=60")

    restart_loop_AdminRunner = 0
    if op == 'babysit':
        pidfile = E.GetPidFileName('loop_AdminRunner')
        pid = E.ReadPidFile(pidfile)
        if os_utils.GetAttr('pid', pid=pid, fallback_to_ps=0) == None:
            restart_loop_AdminRunner = 1

    if op == 'start' or restart_loop_AdminRunner:
        E.su_exe_or_fail(
            config.ENTERPRISE_USER,
            """ ps axwwwww | fgrep AdminRunner | fgrep -v fgrep | \
      colrm 7 | xargs kill -9 2> /dev/null; \
      . %(eb)s; \
      cd %(eh)s/local/google3/enterprise/legacy/scripts/ &&  \
      ENT_ID=%(v)s_crawl ./loop_AdminRunner.py \
      %(eh)s %(args)s >> \
      /%(ld)s/loop_AdminOut_`whoami` 2>&1 &""" % {
                'eh': config.ENTERPRISE_HOME,
                'eb': config.ENTERPRISE_BASHRC,
                'v': config.VERSION,
                'ld': config.LOGDIR,
                'args': string.join(map(commands.mkarg, ar_args))
            })

    restart_loop_webserver_config = 0
    if op == 'babysit':
        pidfile = E.GetPidFileName('loop_webserver_config')
        pid = E.ReadPidFile(pidfile)
        if os_utils.GetAttr('pid', pid=pid, fallback_to_ps=0) == None:
            restart_loop_webserver_config = 1

    if (install_state != "INSTALL"
            and (op == 'start' or restart_loop_webserver_config)):
        logging.info("Starting webserver_config")
        E.su_exe_or_fail(
            config.ENTERPRISE_USER,
            """ ps axwwwww | fgrep webserver_config.py | fgrep -v fgrep \
      | colrm 7 | xargs kill -9 2> /dev/null; \
      . %s; \
      cd %s/enterprise/legacy/scripts/ && \
      ENT_ID=%s_crawl ./loop_webserver_config.py %s \
      >> /%s/loop_WebserverConfig_`whoami` 2>&1 &""" %
            (config.ENTERPRISE_BASHRC, config.MAIN_GOOGLE3_DIR, config.VERSION,
             config.GetConfigFileName(), config.LOGDIR))
Exemplo n.º 3
0
def ResyncWithMaster(google_config_file, enterprise_home, enterprise_user,
                     master):

    scripts_dir = "%s/local/google3/enterprise/legacy/scripts" % enterprise_home

    enterprise_bashrc = "%s/local/conf/ent_bashrc" % enterprise_home
    E.su_exe_or_fail(
        enterprise_user,
        ". %s && cd %s && alarm 600 ./replicate_config.py %s %s" %
        (enterprise_bashrc, scripts_dir, master, google_config_file))
    SetNonMasterNTP(master)
Exemplo n.º 4
0
def ResyncWithMaster(google_config_file,
                     enterprise_home,
                     enterprise_user,
                     master) :

  scripts_dir = "%s/local/google3/enterprise/legacy/scripts" % enterprise_home

  enterprise_bashrc = "%s/local/conf/ent_bashrc" % enterprise_home
  E.su_exe_or_fail(
    enterprise_user,
    ". %s && cd %s && alarm 600 ./replicate_config.py %s %s" %
    (enterprise_bashrc, scripts_dir, master, google_config_file))
  SetNonMasterNTP(master)
Exemplo n.º 5
0
def MasterKillMyself(config):

  util_dir = "%s/local/google3/enterprise/legacy/util" % config.ENTERPRISE_HOME

  # Stop AdminRunner
  for script in ["loop_AdminRunner.py",
                 "adminrunner.py",
                 "loop_webserver_config.py",
                 "webserver_config.py"]:
    E.su_exe_or_fail(config.ENTERPRISE_USER,
                     ". %s && cd %s && ./python_kill.py --binname=%s "\
                     "--kill_by_group" %
                     (config.ENTERPRISE_BASHRC, util_dir, script))

  KillProcessIfNotMaster(config)
Exemplo n.º 6
0
def MasterKillMyself(config):

    util_dir = "%s/local/google3/enterprise/legacy/util" % config.ENTERPRISE_HOME

    # Stop AdminRunner
    for script in [
            "loop_AdminRunner.py", "adminrunner.py",
            "loop_webserver_config.py", "webserver_config.py"
    ]:
        E.su_exe_or_fail(config.ENTERPRISE_USER,
                         ". %s && cd %s && ./python_kill.py --binname=%s "\
                         "--kill_by_group" %
                         (config.ENTERPRISE_BASHRC, util_dir, script))

    KillProcessIfNotMaster(config)
Exemplo n.º 7
0
  def do_babysitter_op(self, op, components = None):
    assert op in ("kill", "start", "loop")

    mode = ""
    background = ""
    if op == 'loop':
      mode = 'loop'
      background = "&"
    else:
      if not components:
        if not self.components:
          ## HACK:
          # all:0,all:1 means all in level 1 / level 2
          # In testing mode the rtslaves are on 31400 which
          # makes the babysitter think they are level 1
          # which in fect they are not ..
          components = ["all:0,all:1"]
        else:
          components = self.components
      if len(components) == 0:
        logging.info("No components to kill...")
        return
      mode = "%s=%s" % (op, string.join(components, ","))

    # Don't send cryptic babysitter spam (see bug 85250).
    email_preference = "--nomail"

    cmd = ". %s; cd %s; python2 ./babysitter.py --batch --setpgrp \
      --%s %s --babyalias=localhost --useinvalidconfig --lockdir=%s --delay=0 \
      --nortsignals %s >> %s/babysitter_out_%s 2>&1 %s" % (
        self.ent_bashrc, self.babydir,
        mode,
        email_preference,
        self.version_tmpdir,
        self.configfile,
        self.logdir,
        time.strftime("%Y%m%d%H%M%S", time.localtime(time.time())),
        background)

    E.su_exe_or_fail(self.ent_user, cmd, set_ulimit = 1)
Exemplo n.º 8
0
    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
Exemplo n.º 9
0
  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
Exemplo n.º 10
0
    def do_babysitter_op(self, op, components=None):
        assert op in ("kill", "start", "loop")

        mode = ""
        background = ""
        if op == 'loop':
            mode = 'loop'
            background = "&"
        else:
            if not components:
                if not self.components:
                    ## HACK:
                    # all:0,all:1 means all in level 1 / level 2
                    # In testing mode the rtslaves are on 31400 which
                    # makes the babysitter think they are level 1
                    # which in fect they are not ..
                    components = ["all:0,all:1"]
                else:
                    components = self.components
            if len(components) == 0:
                logging.info("No components to kill...")
                return
            mode = "%s=%s" % (op, string.join(components, ","))

        # Don't send cryptic babysitter spam (see bug 85250).
        email_preference = "--nomail"

        cmd = ". %s; cd %s; python2 ./babysitter.py --batch --setpgrp \
      --%s %s --babyalias=localhost --useinvalidconfig --lockdir=%s --delay=0 \
      --nortsignals %s >> %s/babysitter_out_%s 2>&1 %s" % (
            self.ent_bashrc, self.babydir, mode, email_preference,
            self.version_tmpdir, self.configfile, self.logdir,
            time.strftime("%Y%m%d%H%M%S", time.localtime(
                time.time())), background)

        E.su_exe_or_fail(self.ent_user, cmd, set_ulimit=1)