diff --git a/HttpServer/Command.php b/HttpServer/Command.php index e75e5f9c..e5e429f7 100644 --- a/HttpServer/Command.php +++ b/HttpServer/Command.php @@ -22,25 +22,32 @@ class Command extends \Console\Command public $description = 'server start|stop|reload|restart'; + const ACTIONS = ['start', 'stop', 'restart']; + + /** * @param Input $dtl - * @throws ConfigException - * @throws Exception * @return mixed|void + * @throws Exception + * @throws ConfigException */ public function onHandler(Input $dtl) { $manager = Snowflake::app()->server; $manager->setDaemon($dtl->get('daemon', 0)); - if ($manager->isRunner()) { - $manager->shutdown(); + + if (!in_array($dtl->get('action'), self::ACTIONS)) { + return $this->error('I don\'t know what I want to do.'); } + + if ($manager->isRunner() && $dtl->get('action') == 'start') { + return $this->error('Service is running. Please use restart.'); + } + + $manager->shutdown(); if ($dtl->get('action') == 'stop') { return; } - if (!in_array($dtl->get('action'), ['start', 'restart'])) { - return $this->error('I don\'t know what I want to do.'); - } $manager->start(); } diff --git a/HttpServer/Events/OnWorkerStart.php b/HttpServer/Events/OnWorkerStart.php index b82d5899..e0ef12ed 100644 --- a/HttpServer/Events/OnWorkerStart.php +++ b/HttpServer/Events/OnWorkerStart.php @@ -31,7 +31,7 @@ class OnWorkerStart extends Callback * @return mixed|void * @throws Exception */ - public function onHandler(Server $server, $worker_id) + public function onHandler(Server $server, int $worker_id) { Snowflake::setWorkerId($server->worker_pid); @@ -42,15 +42,14 @@ class OnWorkerStart extends Callback if ($worker_id >= $server->setting['worker_num']) { return; } - $this->setWorkerAction($server, $worker_id); + $this->setWorkerAction($worker_id); } /** * @param $worker_id - * @param $socket * @throws Exception */ - private function setWorkerAction($socket, $worker_id) + private function setWorkerAction($worker_id) { try { $this->debug(sprintf('Worker #%d is start.....', $worker_id)); @@ -58,7 +57,7 @@ class OnWorkerStart extends Callback if (!$event->exists(Event::SERVER_WORKER_START)) { return; } - $event->trigger(Event::SERVER_WORKER_START); + $event->trigger(Event::SERVER_WORKER_START, [$worker_id]); } catch (\Throwable $exception) { Snowflake::app()->getLogger()->write($exception->getMessage(), 'worker'); } diff --git a/Queue/Queue.php b/Queue/Queue.php index 304a1646..a7877f2e 100644 --- a/Queue/Queue.php +++ b/Queue/Queue.php @@ -48,10 +48,6 @@ class Queue extends \Snowflake\Process\Process $this->waiting = Snowflake::createObject(Waiting::class); $this->running = Snowflake::createObject(Running::class); $this->complete = Snowflake::createObject(Complete::class); - - Process::signal(9 | 15, function () { - $this->shutdown = true; - }); } diff --git a/System/Process/Process.php b/System/Process/Process.php index b0102596..19e23684 100644 --- a/System/Process/Process.php +++ b/System/Process/Process.php @@ -38,5 +38,4 @@ abstract class Process extends \Swoole\Process Snowflake::setWorkerId($this->pid); } - }