public function getScreenSessionDetails($sessionName)
{
// what are we doing?
$log = usingLog()->startAction("get details about screen session '{$sessionName}' on host '{$this->args[0]}' from Storyplayer");
// are there any details?
$cmd = "screen -ls";
$result = usingHost($this->args[0])->runCommandAndIgnoreErrors($cmd);
// NOTE:
//
// screen is not a well-behaved UNIX program, and its exit code
// can be non-zero when everything is good
if (empty($result->output)) {
$msg = "unable to get list of screen sessions";
return null;
}
// do we have the session we are looking for?
$lines = explode("\n", $result->output);
$lines = FilterForMatchingRegex::against($lines, "/[0-9]+\\.{$sessionName}\t/");
$lines = FilterColumns::from($lines, "0", '.');
if (empty($lines)) {
$msg = "screen session '{$sessionName}' is not running";
$log->endAction($msg);
return null;
}
// there might be
$processDetails = new BaseObject();
$processDetails->hostId = $this->args[0];
$processDetails->name = $sessionName;
$processDetails->type = 'screen';
$processDetails->pid = trim(rtrim($lines[0]));
// all done
$log->endAction("session is running as PID '{$processDetails->pid}'");
return $processDetails;
}