示例#1
0
def start(config_loc, watch):
  """  Starts a watch on god given a configuration file. Deletes
       the configuration after it is used. 

  Args:
    config_loc: The location of the god configuration file
    watch: Name of the watch being started
  Returns:
    True on success, False otherwise
  """
  if not misc.is_string_secure(config_loc):
    logging.error("Configuration file location str (%s) is a possible security violation"%config_loc)
    return False

  if not misc.is_string_secure(watch):
    logging.error("Watch string (%s) is a possible security violation"%watch)
    return False

  return_status = subprocess.call(['god', 'load', config_loc])
  if return_status != 0:
    logging.error("God load command returned with status %d when setting up watch %s"%(int(return_status), str(watch)))
    return False

  return_status = subprocess.call(['god', 'start', watch])
  if return_status != 0:
    logging.error("God load command returned with status %d when setting up watch %s"%(return_status, watch))
    return False

  logging.info("Starting watch %s"%str(watch))

  file_io.delete(config_loc)
   
  return True
示例#2
0
def stop(watch):
    """ Stop a watch on god. 
 
  Args:
    watch: The god tag identifier 
  Returns:
    True on success, False otherwise.
  """
    if not misc.is_string_secure(watch):
        logging.error("Watch string (%s) is a possible security violation" %
                      watch)
        return False

    return_status = subprocess.call(['god', 'stop', watch])
    if return_status != 0:
        logging.error(
            "God stop command returned with status %d when stopping watch %s" %
            (return_status, watch))
        return False

    return_status = subprocess.call(['god', 'remove', watch])
    if return_status != 0:
        logging.error(
            "God remove command returned with status %d when removing watch %s"
            % (return_status, watch))
        return False

    return True
示例#3
0
def stop(watch, is_group=True):
  """ Shut down the named programs monit is watching, and stop monitoring it.
 
  Args:
    watch: The name of the group of programs that monit is watching, that should
      no longer be watched.
    is_group: A bool that indicates if we want to stop a group of programs, or
      only a single program.
  Returns:
    True if the named programs were stopped and no longer monitored, and False
    if either (1) the named watch is not valid, (2) the programs could not be
    stopped, or (3) the programs could not be unmonitored.
  """
  if not misc.is_string_secure(watch):
    logging.error("Watch string (%s) is a possible security violation" % watch)
    return False
  
  logging.info("Stopping watch {0}".format(watch))
  if is_group:
    stop_command = [MONIT, 'stop', '-g', watch]
  else:
    stop_command = [MONIT, 'stop', watch]
  if not run_with_retry(stop_command):
    return False

  logging.info("Unmonitoring watch {0}".format(watch))
  if is_group:
    unmonitor_command = [MONIT, 'unmonitor', '-g', watch]
  else:
    unmonitor_command = [MONIT, 'unmonitor', watch]
  return run_with_retry(unmonitor_command)
示例#4
0
def start(watch, is_group=True):
  """ Instructs monit to start the given program, assuming that a configuration
  file has already been written for it.

  Args:
    watch: A str representing the name of the program to start up and monitor.
    is_group: A bool that indicates if we want to stop a group of programs, or
      only a single program.
  Returns:
    True if the program was started, or False if (1) the named program is not a
    valid program name, (2) if monit could not be reloaded to read the new
    configuration file, or (3) monit could not start the new program.
  """
  if not misc.is_string_secure(watch):
    logging.error("Watch string [{0}] is a possible security violation".format(
      watch))
    return False

  logging.info("Reloading monit.")
  if not run_with_retry([MONIT, 'reload']):
    return False

  logging.info("Starting watch {0}".format(watch))
  if is_group:
    run_with_retry([MONIT, 'monitor', '-g', watch])
    return run_with_retry([MONIT, 'start', '-g', watch])
  else:
    run_with_retry([MONIT, 'monitor',  watch])
    return run_with_retry([MONIT, 'start', watch])
示例#5
0
def stop(watch, is_group=True):
  """ Shut down the named programs monit is watching, and stop monitoring it.
 
  Args:
    watch: The name of the group of programs that monit is watching, that should
      no longer be watched.
    is_group: A bool that indicates if we want to stop a group of programs, or
      only a single program.
  Returns:
    True if the named programs were stopped and no longer monitored, and False
    if either (1) the named watch is not valid, (2) the programs could not be
    stopped, or (3) the programs could not be unmonitored.
  """
  if not misc.is_string_secure(watch):
    logging.error("Watch string (%s) is a possible security violation" % watch)
    return False
  
  logging.info("Stopping watch {0}".format(watch))
  if is_group:
    stop_command = [MONIT, 'stop', '-g', watch]
  else:
    stop_command = [MONIT, 'stop', watch]
  if not run_with_retry(stop_command):
    return False

  logging.info("Unmonitoring watch {0}".format(watch))
  if is_group:
    unmonitor_command = [MONIT, 'unmonitor', '-g', watch]
  else:
    unmonitor_command = [MONIT, 'unmonitor', watch]
  return run_with_retry(unmonitor_command)
示例#6
0
def start(watch, is_group=True):
  """ Instructs monit to start the given program, assuming that a configuration
  file has already been written for it.

  Args:
    watch: A str representing the name of the program to start up and monitor.
    is_group: A bool that indicates if we want to stop a group of programs, or
      only a single program.
  Returns:
    True if the program was started, or False if (1) the named program is not a
    valid program name, (2) if monit could not be reloaded to read the new
    configuration file, or (3) monit could not start the new program.
  """
  if not misc.is_string_secure(watch):
    logging.error("Watch string [{0}] is a possible security violation".format(
      watch))
    return False

  logging.info("Reloading monit.")
  if not run_with_retry([MONIT, 'reload']):
    return False

  logging.info("Starting watch {0}".format(watch))
  if is_group:
    run_with_retry([MONIT, 'monitor', '-g', watch])
    return run_with_retry([MONIT, 'start', '-g', watch])
  else:
    run_with_retry([MONIT, 'monitor',  watch])
    return run_with_retry([MONIT, 'start', watch])
示例#7
0
 def test_is_string_secure(self):
   self.assertEqual(True, misc.is_string_secure("guestbook"))
   self.assertEqual(True, misc.is_string_secure("guestbook132"))
   self.assertEqual(True, misc.is_string_secure("guestbook_132"))
   self.assertEqual(True, misc.is_string_secure("guestbook-132"))
   self.assertEqual(False, misc.is_string_secure("asdf#"))
   self.assertEqual(False, misc.is_string_secure("%##;"))
   self.assertEqual(False, misc.is_string_secure("$78;"))
示例#8
0
def start(config_loc, watch):
    """  Starts a watch on god given a configuration file. Deletes
       the configuration after it is used. 

  Args:
    config_loc: The location of the god configuration file
    watch: Name of the watch being started
  Returns:
    True on success, False otherwise
  """
    if not misc.is_string_secure(config_loc):
        logging.error(
            "Configuration file location str (%s) is a possible security violation"
            % config_loc)
        return False

    if not misc.is_string_secure(watch):
        logging.error("Watch string (%s) is a possible security violation" %
                      watch)
        return False

    return_status = subprocess.call(['god', 'load', config_loc])
    if return_status != 0:
        logging.error(
            "God load command returned with status %d when setting up watch %s"
            % (int(return_status), str(watch)))
        return False

    return_status = subprocess.call(['god', 'start', watch])
    if return_status != 0:
        logging.error(
            "God load command returned with status %d when setting up watch %s"
            % (return_status, watch))
        return False

    logging.info("Starting watch %s" % str(watch))

    file_io.delete(config_loc)

    return True
示例#9
0
def restart(watch):
    """ Instructs monit to restart all processes hosting the given watch.

  Args:
    watch: A str representing the name of the programs to restart.
  Returns:
    True if the programs were restarted, or False if (1) the watch is not a
    valid program name, (2) monit could not restart the new program.
  """
    if not misc.is_string_secure(watch):
        logging.error("Watch string [{0}] is a possible security violation".format(watch))
        return False

    logging.info("Restarting watch {0}".format(watch))
    return run_with_retry([MONIT, "restart", "-g", watch])
示例#10
0
def restart(watch):
  """ Instructs monit to restart all processes hosting the given watch.

  Args:
    watch: A str representing the name of the programs to restart.
  Returns:
    True if the programs were restarted, or False if (1) the watch is not a
    valid program name, (2) monit could not restart the new program.
  """
  if not misc.is_string_secure(watch):
    logging.error("Watch string [{0}] is a possible security violation".format(
      watch))
    return False

  logging.info("Restarting watch {0}".format(watch))
  return run_with_retry([MONIT, 'restart', '-g', watch])
示例#11
0
def start(watch):
    """ Instructs monit to start the given program, assuming that a configuration
  file has already been written for it.

  Args:
    watch: A str representing the name of the program to start up and monitor.
  Returns:
    True if the program was started, or False if (1) the named program is not a
    valid program name, (2) if monit could not be reloaded to read the new
    configuration file, or (3) monit could not start the new program.
  """
    if not misc.is_string_secure(watch):
        logging.error("Watch string [{0}] is a possible security violation".format(watch))
        return False

    logging.info("Reloading monit.")
    if not run_with_retry([MONIT, "reload"]):
        return False

    logging.info("Starting watch {0}".format(watch))
    run_with_retry([MONIT, "monitor", "-g", watch])
    return run_with_retry([MONIT, "start", "-g", watch])
示例#12
0
def stop(watch):
  """ Stop a watch on god. 
 
  Args:
    watch: The god tag identifier 
  Returns:
    True on success, False otherwise.
  """
  if not misc.is_string_secure(watch):
    logging.error("Watch string (%s) is a possible security violation"%watch)
    return False
  
  return_status = subprocess.call(['god', 'stop', watch])
  if return_status != 0:
    logging.error("God stop command returned with status %d when stopping watch %s"%(return_status, watch))
    return False

  return_status = subprocess.call(['god', 'remove', watch])
  if return_status != 0:
    logging.error("God remove command returned with status %d when removing watch %s"%(return_status, watch)) 
    return False

  return True