diff --git a/HttpServer/Action.php b/HttpServer/Action.php index 0d525931..f8499a62 100644 --- a/HttpServer/Action.php +++ b/HttpServer/Action.php @@ -48,23 +48,26 @@ trait Action */ private function _shutdown($server) { - $socket = storage('socket.sock'); - if (!file_exists($socket)) { + $content = file_get_contents($this->getPidFile()); + if (empty($content)) { $this->close($server); } else { - $pathId = file_get_contents($socket); - @unlink($socket); - if (empty($pathId)) { - $this->close($server); - } else { - exec("ps -ef $pathId | grep $pathId", $output); - if (!empty($output)) { - exec("kill -TERM $pathId"); - } - $this->close($server); + exec("ps -ef $content | grep $content", $output); + if (!empty($output)) { + exec("kill -15 $content"); } + $this->close($server); } - Snowflake::clearWorkerId(); + } + + + /** + * @return mixed + * @throws ComponentException + */ + private function getPidFile(): string + { + return Snowflake::app()->getSwoole()->setting['pid_file']; } @@ -144,10 +147,12 @@ trait Action */ private function closeByPid($pid) { - exec("ps -ef $pid | grep $pid", $output); - if (!empty($output)) { - exec("kill -TERM $pid"); - } + exec("ps -ef | grep $pid | grep -v grep | grep -v kill +if [ $? -eq 0 ];then + kill -9 `ps -ef | grep $pid | grep -v grep | grep -v kill | awk '{print $2}'` +else + echo $pid' No Found Process' +fi"); } diff --git a/HttpServer/Events/OnManagerStop.php b/HttpServer/Events/OnManagerStop.php index 146b3d62..8e6d4af0 100644 --- a/HttpServer/Events/OnManagerStop.php +++ b/HttpServer/Events/OnManagerStop.php @@ -26,8 +26,6 @@ class OnManagerStop extends Callback $this->warning('manager stop.'); fire(Event::SERVER_MANAGER_STOP, [$server]); - - Snowflake::clearWorkerId(); } } diff --git a/System/Snowflake.php b/System/Snowflake.php index e3a46ae7..a3c39329 100644 --- a/System/Snowflake.php +++ b/System/Snowflake.php @@ -169,22 +169,6 @@ class Snowflake } - /** - * @throws Exception - */ - public static function clearWorkerId() - { - $dir = storage(null, 'worker'); - foreach (glob($dir . '/*') as $file) { - clearstatcache(); - if (!file_exists($file)) { - continue; - } - @unlink($file); - } - } - - /** * @param $fileName * @param $content