From 39b1b4d8aafcf92bef4e7b86ac92e7760210d289 Mon Sep 17 00:00:00 2001 From: JanHuang Date: Tue, 28 Aug 2018 14:23:07 +0800 Subject: [PATCH] fixed runtime status --- helpers.php | 13 +++++++++++++ src/Server.php | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/helpers.php b/helpers.php index cf2b0c2..0a23337 100644 --- a/helpers.php +++ b/helpers.php @@ -152,3 +152,16 @@ function process_is_running($keyword) return empty($output) ? false : true; } +/** + * @param $port + * @return bool + */ +function port_is_running($port) +{ + $command = "lsof -i:{$port} | grep LISTEN"; + + exec($command, $output); + + return !empty($output); +} + diff --git a/src/Server.php b/src/Server.php index c6e59d0..2230de4 100755 --- a/src/Server.php +++ b/src/Server.php @@ -519,7 +519,8 @@ public function isRunning() if (file_exists($this->config['pid_file'])) { return posix_kill(file_get_contents($this->config['pid_file']), 0); } - return process_is_running("{$this->name} master"); + + return process_is_running("{$this->name} master") && port_is_running($this->port); } /**