Files
kiri-core/HttpServer/Command.php
T

48 lines
829 B
PHP
Raw Normal View History

2020-09-03 00:15:57 +08:00
<?php
namespace HttpServer;
2020-09-07 18:11:36 +08:00
use Exception;
use Snowflake\Abstracts\Input;
2020-09-07 15:19:13 +08:00
use Snowflake\Exception\ConfigException;
2020-09-03 00:15:57 +08:00
use Snowflake\Snowflake;
/**
* Class Command
* @package HttpServer
*/
class Command extends \Console\Command
{
2020-09-08 15:59:15 +08:00
public $command = 'sw:server';
2020-09-03 00:15:57 +08:00
public $description = 'server start|stop|reload|restart';
/**
2020-09-07 18:11:36 +08:00
* @param Input $dtl
* @throws ConfigException
* @throws Exception
2020-09-11 14:22:44 +08:00
* @return mixed|void
2020-09-03 00:15:57 +08:00
*/
2020-09-07 18:11:36 +08:00
public function onHandler(Input $dtl)
2020-09-03 00:15:57 +08:00
{
2020-09-07 18:11:36 +08:00
$manager = Snowflake::app()->server;
$manager->setDaemon($dtl->get('daemon', 0));
2020-09-11 14:22:44 +08:00
if ($manager->isRunner()) {
$manager->shutdown();
2020-09-07 15:19:13 +08:00
}
2020-09-11 14:22:44 +08:00
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();
2020-09-03 00:15:57 +08:00
}
}