diff --git a/Server.php b/Server.php index feba72a..b30273d 100644 --- a/Server.php +++ b/Server.php @@ -137,8 +137,9 @@ class Server extends HttpService /** * @return \Swoole\Http\Server|\Swoole\Server|\Swoole\WebSocket\Server|null + * @throws \ReflectionException */ - #[Pure] public function getServer(): \Swoole\Http\Server|\Swoole\Server|\Swoole\WebSocket\Server|null + public function getServer(): \Swoole\Http\Server|\Swoole\Server|\Swoole\WebSocket\Server|null { return $this->manager->getServer(); } diff --git a/ServerCommand.php b/ServerCommand.php index ad28960..f87b4eb 100644 --- a/ServerCommand.php +++ b/ServerCommand.php @@ -4,12 +4,13 @@ declare(strict_types=1); namespace Server; +use Note\Inject; use Exception; use Kiri\Abstracts\Config; use Kiri\Events\EventDispatch; use Kiri\Exception\ConfigException; use Kiri\Kiri; -use Note\Inject; +use Server\Events\OnServerBeforeStart; use Swoole\Coroutine; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -63,12 +64,12 @@ class ServerCommand extends Command if (!in_array($input->getArgument('action'), self::ACTIONS)) { throw new Exception('I don\'t know what I want to do.'); } - $action = $input->getArgument('action'); - if ($action == 'stop' || $action == 'restart') { - $manager->shutdown(); - if ($action == 'stop') { - return 0; - } + if ($manager->isRunner() && $input->getArgument('action') == 'start') { + throw new Exception('Service is running. Please use restart.'); + } + $manager->shutdown(); + if ($input->getArgument('action') == 'stop') { + return 0; } return $this->generate_runtime_builder($manager); } @@ -86,7 +87,7 @@ class ServerCommand extends Command Coroutine::set([ 'hook_flags' => SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_BLOCKING_FUNCTION, 'enable_deadlock_check' => FALSE, - 'exit_condition' => static function () { + 'exit_condition' => function () { return Coroutine::stats()['coroutine_num'] === 0; } ]);