改名
This commit is contained in:
@@ -13,7 +13,10 @@ class OnWorkerError
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Server $server
|
* @param Server $server
|
||||||
* @param int $workerId
|
* @param int $worker_id
|
||||||
|
* @param int $worker_pid
|
||||||
|
* @param int $exit_code
|
||||||
|
* @param int $signal
|
||||||
*/
|
*/
|
||||||
public function __construct(Server $server, int $worker_id, int $worker_pid, int $exit_code, int $signal)
|
public function __construct(Server $server, int $worker_id, int $worker_pid, int $exit_code, int $signal)
|
||||||
{
|
{
|
||||||
|
|||||||
+13
-12
@@ -79,7 +79,7 @@ class ServerManager
|
|||||||
*/
|
*/
|
||||||
public function addListener(string $type, string $host, int $port, int $mode, array $settings = [])
|
public function addListener(string $type, string $host, int $port, int $mode, array $settings = [])
|
||||||
{
|
{
|
||||||
if ($this->portIsAlready($port)) $this->stopServer($port);
|
if ($this->checkPortIsAlready($port)) $this->stopServer($port);
|
||||||
if (!$this->server) {
|
if (!$this->server) {
|
||||||
$this->createBaseServer($type, $host, $port, $mode, $settings);
|
$this->createBaseServer($type, $host, $port, $mode, $settings);
|
||||||
} else {
|
} else {
|
||||||
@@ -94,6 +94,7 @@ class ServerManager
|
|||||||
/**
|
/**
|
||||||
* @throws NotFindClassException
|
* @throws NotFindClassException
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @throws ConfigException
|
||||||
*/
|
*/
|
||||||
public function initBaseServer($configs, int $daemon = 0): void
|
public function initBaseServer($configs, int $daemon = 0): void
|
||||||
{
|
{
|
||||||
@@ -107,18 +108,18 @@ class ServerManager
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $port
|
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws Exception
|
* @throws ConfigException
|
||||||
*/
|
*/
|
||||||
private function checkPort($port): bool
|
public function isRunner(): bool
|
||||||
{
|
{
|
||||||
if (Kiri::getPlatform()->isLinux()) {
|
$configs = Config::get('server', [], true);
|
||||||
exec('netstat -tunlp | grep ' . $port, $output);
|
foreach ($this->sortService($configs['ports']) as $config) {
|
||||||
} else {
|
if ($this->checkPortIsAlready($config['port'])) {
|
||||||
exec('lsof -i :' . $port . ' | grep -i "LISTEN"', $output);
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return !empty($output);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -310,10 +311,10 @@ class ServerManager
|
|||||||
*/
|
*/
|
||||||
public function stopServer(int $port)
|
public function stopServer(int $port)
|
||||||
{
|
{
|
||||||
if (!($pid = $this->portIsAlready($port))) {
|
if (!($pid = $this->checkPortIsAlready($port))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while ($this->portIsAlready($port)) {
|
while ($this->checkPortIsAlready($port)) {
|
||||||
exec('kill ' . $pid, $execResult);
|
exec('kill ' . $pid, $execResult);
|
||||||
usleep(300);
|
usleep(300);
|
||||||
}
|
}
|
||||||
@@ -324,7 +325,7 @@ class ServerManager
|
|||||||
* @param $port
|
* @param $port
|
||||||
* @return bool|string
|
* @return bool|string
|
||||||
*/
|
*/
|
||||||
private function portIsAlready($port): bool|string
|
private function checkPortIsAlready($port): bool|string
|
||||||
{
|
{
|
||||||
if (!Kiri::getPlatform()->isLinux()) {
|
if (!Kiri::getPlatform()->isLinux()) {
|
||||||
exec("lsof -i :" . $port . " | grep -i 'LISTEN' | awk '{print $2}'", $output);
|
exec("lsof -i :" . $port . " | grep -i 'LISTEN' | awk '{print $2}'", $output);
|
||||||
|
|||||||
@@ -38,13 +38,11 @@ class Command extends \Console\Command
|
|||||||
if (!in_array($dtl->get('action'), self::ACTIONS)) {
|
if (!in_array($dtl->get('action'), self::ACTIONS)) {
|
||||||
return 'I don\'t know what I want to do.';
|
return 'I don\'t know what I want to do.';
|
||||||
}
|
}
|
||||||
|
if ($manager->isRunner() && $dtl->get('action') == 'start') {
|
||||||
/** @var Shutdown $shutdown */
|
|
||||||
$shutdown = Kiri::app()->get('shutdown');
|
|
||||||
if ($shutdown->isRunning() && $dtl->get('action') == 'start') {
|
|
||||||
return 'Service is running. Please use restart.';
|
return 'Service is running. Please use restart.';
|
||||||
}
|
}
|
||||||
$shutdown->shutdown();
|
|
||||||
|
$manager->shutdown();
|
||||||
if ($dtl->get('action') == 'stop') {
|
if ($dtl->get('action') == 'stop') {
|
||||||
return 'shutdown success.';
|
return 'shutdown success.';
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-6
@@ -6,16 +6,15 @@ namespace Http;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use Http\Abstracts\HttpService;
|
use Http\Abstracts\HttpService;
|
||||||
use JetBrains\PhpStorm\Pure;
|
use JetBrains\PhpStorm\Pure;
|
||||||
use ReflectionException;
|
|
||||||
use Rpc\Service;
|
|
||||||
use Server\Constant;
|
|
||||||
use Server\ServerManager;
|
|
||||||
use Kiri\Abstracts\Config;
|
use Kiri\Abstracts\Config;
|
||||||
use Kiri\Error\LoggerProcess;
|
use Kiri\Error\LoggerProcess;
|
||||||
use Kiri\Exception\ConfigException;
|
use Kiri\Exception\ConfigException;
|
||||||
use Kiri\Exception\NotFindClassException;
|
use Kiri\Exception\NotFindClassException;
|
||||||
use Kiri\Process\Biomonitoring;
|
use Kiri\Process\Biomonitoring;
|
||||||
use Kiri\Kiri;
|
use ReflectionException;
|
||||||
|
use Rpc\Service;
|
||||||
|
use Server\Constant;
|
||||||
|
use Server\ServerManager;
|
||||||
use Swoole\Runtime;
|
use Swoole\Runtime;
|
||||||
|
|
||||||
|
|
||||||
@@ -123,7 +122,20 @@ class Server extends HttpService
|
|||||||
*/
|
*/
|
||||||
public function shutdown()
|
public function shutdown()
|
||||||
{
|
{
|
||||||
$this->manager->stopServer(0);
|
$configs = Config::get('server', [], true);
|
||||||
|
foreach ($configs['ports'] ?? [] as $config) {
|
||||||
|
$this->manager->stopServer($config['port']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
* @throws ConfigException
|
||||||
|
*/
|
||||||
|
public function isRunner(): bool
|
||||||
|
{
|
||||||
|
return $this->manager->isRunner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user