Esempio n. 1
0
 def status(self):
     session = self.config["session"]
     self.out("Tmux session      :", Tmux.HasSession(session))
     self.out("Tmux webapp       :", Tmux.HasWindow(session, "webapp"))
     self.out("Webapp running    :",
              Process.FindLike(self.config["webapp"]) and True or False)
     self.out("Webapp responsive :", self.ping().isSuccess())
Esempio n. 2
0
 def stop(self):
     if self.Has(self.name):
         # This sends a Ctrl-C.
         Tmux.Write(self.name, "daemon", "C-c")
         # If the window does not become responsive after 5s, we kill the
         # window.
         if not Tmux.IsResponsive(self.name, "daemon", timeout=5):
             Tmux.KillWindow(self.name, "daemon")
         return True
     else:
         return False
Esempio n. 3
0
 def ensure(self):
     """Ensures that the service is running."""
     session = self.config["session"]
     path = os.path.abspath(self.config["path"])
     Tmux.EnsureWindow(session, "webapp")
     if Tmux.IsResponsive(session, "webapp"):
         # If the Tmux session is responsive, we start the process
         Tmux.Run(session, "webapp", "cd {0}".format(path))
         Tmux.Run(session, "webapp",
                  "./env.sh ./{webapp} {port} {host}".format(**self.config))
     elif not self.ping().isSuccess():
         # If the Tmux session is not responsive and the ping does not work
         # we kill and restart the process.
         self.reload()
     return self.process()
Esempio n. 4
0
 def stop(self):
     session = self.config["session"]
     Tmux.EnsureWindow(session, "webapp")
     p = Process.FindLike(self.config["webapp"])
     # We kill the whole process group
     if p: Process.Kill(p[0], children=True)
     return self.process()
Esempio n. 5
0
 def start(self, command=None):
     command = command or self.command
     if not self.Has(self.name):
         Tmux.EnsureSession(self.name)
         Tmux.EnsureWindow(self.name, "daemon")
     if Tmux.IsResponsive(self.name, "daemon"):
         if not command:
             command = Tmux.Run(self.name, "daemon", "echo $DAEMON_COMMAND")
         # We assume that the daemon's will not detach from tmux, so if
         # the shell is not responsive, it means the daemon is running
         Tmux.Write(
             self.name, "daemon", "export DAEMON_COMMAND=\"{0}\"".format(
                 command.replace('"', '\\"')))
         Tmux.Write(self.name, "daemon", command)
     return True
Esempio n. 6
0
 def Has(cls, name):
     return Tmux.HasSession(name) and Tmux.HasWindow(name, "daemon")
Esempio n. 7
0
 def reload(self):
     self.stop()
     session = self.config["session"]
     Tmux.Run(session, "webapp",
              "./env.sh ./{webapp} {port} {host}".format(**self.config))
     return self.process()