This commit is contained in:
2021-03-01 15:07:11 +08:00
parent a3612194a2
commit 08b21aeb7b
3 changed files with 22 additions and 35 deletions
+22 -17
View File
@@ -48,23 +48,26 @@ trait Action
*/ */
private function _shutdown($server) private function _shutdown($server)
{ {
$socket = storage('socket.sock'); $content = file_get_contents($this->getPidFile());
if (!file_exists($socket)) { if (empty($content)) {
$this->close($server); $this->close($server);
} else { } else {
$pathId = file_get_contents($socket); exec("ps -ef $content | grep $content", $output);
@unlink($socket); if (!empty($output)) {
if (empty($pathId)) { exec("kill -15 $content");
$this->close($server);
} else {
exec("ps -ef $pathId | grep $pathId", $output);
if (!empty($output)) {
exec("kill -TERM $pathId");
}
$this->close($server);
} }
$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) private function closeByPid($pid)
{ {
exec("ps -ef $pid | grep $pid", $output); exec("ps -ef | grep $pid | grep -v grep | grep -v kill
if (!empty($output)) { if [ $? -eq 0 ];then
exec("kill -TERM $pid"); kill -9 `ps -ef | grep $pid | grep -v grep | grep -v kill | awk '{print $2}'`
} else
echo $pid' No Found Process'
fi");
} }
-2
View File
@@ -26,8 +26,6 @@ class OnManagerStop extends Callback
$this->warning('manager stop.'); $this->warning('manager stop.');
fire(Event::SERVER_MANAGER_STOP, [$server]); fire(Event::SERVER_MANAGER_STOP, [$server]);
Snowflake::clearWorkerId();
} }
} }
-16
View File
@@ -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 $fileName
* @param $content * @param $content