Skip to content

Commit

Permalink
修复执行php bin/swoft stop命令时master进程异常未退出的问题,以及停止失败后,pid文件被删除的问题 (#134)
Browse files Browse the repository at this point in the history
* 修复执行php bin/swoft stop命令时master进程异常未退出的问题;
修复执行php bin/swoft stop失败,但pid文件仍被删除的问题。

* Update AbstractServer.php
  • Loading branch information
xiangjihan authored and inhere committed Jul 20, 2018
1 parent a30bf58 commit b72e04c
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/Bootstrap/Server/AbstractServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,25 @@ public function reload($onlyTask = false)
*/
public function stop(): bool
{
//获取master进程ID
$masterPid = $this->serverSetting['masterPid'];
//使用swoole_process::kill代替posix_kill
$result = \swoole_process::kill($masterPid);
$timeout = 60;
$startTime = time();
$this->serverSetting['masterPid'] && posix_kill($this->serverSetting['masterPid'], SIGTERM);

$result = true;
while (1) {
$masterIslive = $this->serverSetting['masterPid'] && posix_kill($this->serverSetting['masterPid'], SIGTERM);
if ($masterIslive) {
if (time() - $startTime >= $timeout) {
$result = false;
break;
while (true) {
//检测进程是否退出
if(!\swoole_process::kill($masterPid, 0)) {
//判断是否超时
if(time() - $startTime >= $timeout) {
return false;
}
usleep(10000);
continue;
}

break;
return true;
}
return $result;
}

/**
Expand All @@ -159,7 +159,7 @@ public function isRunning(): bool
$pFile = $this->serverSetting['pfile'];

// Is pid file exist ?
if (file_exists($pFile)) {
if (\file_exists($pFile)) {
// Get pid file content and parse the content
$pidFile = file_get_contents($pFile);
$pids = explode(',', $pidFile);
Expand Down

0 comments on commit b72e04c

Please sign in to comment.