Skip to content

Commit

Permalink
Merge pull request #1645 from matthewrmshin/fix-ssh-tail-follow-becom…
Browse files Browse the repository at this point in the history
…es-zombie

cylc.gui.tailer: fix SSH zombie tail
  • Loading branch information
hjoliver committed Oct 14, 2015
2 parents e53abdb + 89bb155 commit fedc844
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/cylc/gui/tailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,24 @@ class Tailer(threading.Thread):
logview -- A GUI view to display the content of the log file.
filename -- The name of the log file.
cmd_tmpl -- The command template use to follow the log file.
(default=Tailer.CMD_TMPL)
(default=Tailer.L_CMD_TMPL for local files, Tailer.R_CMD_TMPL
for remote files)
pollable -- If specified, it must implement a pollable.poll() method,
which is called at regular intervals.
"""

CMD_TMPL = "tail -n +1 -F %(filename)s"
# Template for tail commands on local files.
L_CMD_TMPL = "tail -n +1 -F %(filename)s"
# Template for tail commands on remote files.
# On signal to "ssh" client, a signal is sent to "sshd" on server.
# However, "sshd" cannot send a signal to the "tail" command, because it is
# not a terminal. Apparently, we can use "ssh -t" or "ssh -tt", but that
# just causes the command to hang here for some reason. The easiest
# solution is to use the "--pid=PID" option of the "tail" command, so it
# dies as soon as PID dies. Note: if remote login shell is bash/ksh, we can
# use $PPID instead of `ps ...` command, but we do have to support users
# whose login shell is "tcsh".
R_CMD_TMPL = "tail --pid=`ps h -o ppid $$` -n +1 -F %(filename)s"
READ_SIZE = 4096
TAGS = {
"CRITICAL": [re.compile(r"\b(?:CRITICAL|ERROR)\b"), "red"],
Expand Down Expand Up @@ -83,10 +95,11 @@ def run(self):
ssh = str(GLOBAL_CFG.get_host_item(
"remote shell template", host, owner)).replace(" %s", "")
command = shlex.split(ssh) + ["-n", user_at_host]
cmd_tmpl = self.R_CMD_TMPL
else:
filename = self.filename
cmd_tmpl = self.L_CMD_TMPL

cmd_tmpl = self.CMD_TMPL
if self.cmd_tmpl:
cmd_tmpl = self.cmd_tmpl
command += shlex.split(cmd_tmpl % {"filename": filename})
Expand Down

0 comments on commit fedc844

Please sign in to comment.