Пример #1
0
 def test_daemon_option(self):
     """ Test daemon option. """
     print("running service daemon option test")
     pidfile = "/path/to/pid.pid"
     start = "start command"
     service = Service("foo", daemon=pidfile, start=start, stop="stop command", status="status command")
     common = "%s --pidfile %s" % (which("simplevisor-loop"), pidfile)
     self.assertEqual("%s -c 1 --daemon %s" % (common, start), service._opts["start"])
     self.assertEqual("%s --quit" % (common,), service._opts["stop"])
     self.assertEqual("%s --status" % (common,), service._opts["status"])
     print("...service daemon option ok")
Пример #2
0
 def __init__(self, name, expected=DEFAULT_EXPECTED,
              timeout=DEFAULT_TIMEOUT,
              control=None, daemon=None, path=None, pattern=None,
              restart=None, start=None, status=None, stop=None,
              **kwargs):
     """ Service constructor. """
     self.name = name
     self._opts = {
         "name": name,
         "expected": expected,
         "control": control,
         "daemon": daemon,
         "path": path,
         "pattern": pattern,
         "restart": restart,
         "start": start,
         "status": status,
         "stop": stop,
         "timeout": get_int_or_die(
             timeout,
             "timeout value for %s is not a valid integer: %s" %
             (name, timeout)), }
     self._status = {
         "name": name,
         "log": list(), }
     for key in kwargs:
         if not key.startswith("var_"):
             raise ValueError(
                 "invalid property for service %s: %s" % (name, key))
     self._is_new = True
     try:
         self._validate_opts()
     except ValueError:
         error = sys.exc_info()[1]
         raise ValueError(
             "service %s is not properly configured: %s" %
             (self.name, error))
     if control is None and daemon is not None:
         si_loop = which("simplevisor-loop")
         if si_loop is None:
             raise RuntimeError(
                 "cannot find simplevisor-loop command in the "
                 "environment: %s" % (os.environ["PATH"], ))
         common_path = "%s --pidfile %s" % (si_loop, daemon, )
         self._opts["start"] = (
             "%s -c 1 --daemon %s" % (common_path, start))
         self._opts["stop"] = ("%s --quit" % (common_path, ))
         self._opts["status"] = ("%s --status" % (common_path, ))
     elif control is None and status is None:
         if sys.platform != "linux2":
             raise ValueError(
                 "don't know how to read process table, you must specify "
                 "a status command for service: %s" % (name, ))
         if pattern is not None:
             pat = pattern
         else:
             pat = " ".join(self.get_cmd("start"))
         try:
             self._opts["pattern_re"] = re.compile(pat)
             LOGGER.debug(
                 "using %s as pattern for service %s" % (pat, name))
         except re.error:
             error = sys.exc_info()[1]
             raise ValueError(
                 "%s service pattern not valid: %s" % (name, error))