This commit is contained in:
2021-09-02 13:48:57 +08:00
parent dfd7ead466
commit 648e698d9e
+13 -8
View File
@@ -6,7 +6,6 @@ namespace Http;
use Annotation\Inject; use Annotation\Inject;
use Exception; use Exception;
use Kiri\Abstracts\Input;
use Kiri\Events\EventProvider; use Kiri\Events\EventProvider;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use Kiri\Exception\NotFindClassException; use Kiri\Exception\NotFindClassException;
@@ -16,6 +15,7 @@ use Server\Events\OnBeforeWorkerStart;
use Server\Events\OnWorkerStart; use Server\Events\OnWorkerStart;
use Server\Worker\OnServerWorker; use Server\Worker\OnServerWorker;
use Server\Worker\OnWorkerStart as WorkerDispatch; use Server\Worker\OnWorkerStart as WorkerDispatch;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@@ -44,8 +44,8 @@ class Command extends \Symfony\Component\Console\Command\Command
{ {
$this->setName('sw:server') $this->setName('sw:server')
->setDescription('server start|stop|reload|restart') ->setDescription('server start|stop|reload|restart')
->addOption('action') ->addArgument('action', InputArgument::REQUIRED)
->addOption('daemon'); ->addArgument('daemon', InputArgument::OPTIONAL, '', 0);
} }
@@ -58,19 +58,22 @@ class Command extends \Symfony\Component\Console\Command\Command
* @throws ReflectionException * @throws ReflectionException
* @throws Exception * @throws Exception
*/ */
public function execute(InputInterface $input, OutputInterface $output): string public function execute(InputInterface $input, OutputInterface $output): int
{ {
$manager = Kiri::app()->getServer(); $manager = Kiri::app()->getServer();
$manager->setDaemon($input->getArgument('daemon')); $manager->setDaemon($input->getArgument('daemon'));
if (!in_array($input->getArgument('action'), self::ACTIONS)) { if (!in_array($input->getArgument('action'), self::ACTIONS)) {
return $output->write('I don\'t know what I want to do.'); $output->write('I don\'t know what I want to do.');
return 1;
} }
if ($manager->isRunner() && $input->getArgument('action') == 'start') { if ($manager->isRunner() && $input->getArgument('action') == 'start') {
return $output->write('Service is running. Please use restart.'); $output->write('Service is running. Please use restart.');
return 1;
} }
$manager->shutdown(); $manager->shutdown();
if ($input->getArgument('action') == 'stop') { if ($input->getArgument('action') == 'stop') {
return $output->write('shutdown success'); $output->write('shutdown success');
return 1;
} }
return $this->generate_runtime_builder($manager); return $this->generate_runtime_builder($manager);
} }
@@ -89,7 +92,9 @@ class Command extends \Symfony\Component\Console\Command\Command
$this->eventProvider->on(OnBeforeWorkerStart::class, [di(OnServerWorker::class), 'setConfigure']); $this->eventProvider->on(OnBeforeWorkerStart::class, [di(OnServerWorker::class), 'setConfigure']);
$this->eventProvider->on(OnWorkerStart::class, [di(WorkerDispatch::class), 'dispatch']); $this->eventProvider->on(OnWorkerStart::class, [di(WorkerDispatch::class), 'dispatch']);
return $manager->start(); $manager->start();
return 0;
} }
} }