Files
kiri-core/HttpServer/Command.php
T

55 lines
966 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-11 14:27:09 +08:00
const ACTIONS = ['start', 'stop', 'restart'];
2020-09-03 00:15:57 +08:00
/**
2020-09-07 18:11:36 +08:00
* @param Input $dtl
2020-09-11 14:22:44 +08:00
* @return mixed|void
2020-09-11 14:27:09 +08:00
* @throws Exception
* @throws ConfigException
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:27:09 +08:00
if (!in_array($dtl->get('action'), self::ACTIONS)) {
2020-09-11 14:42:52 +08:00
return 'I don\'t know what I want to do.';
2020-09-11 14:27:09 +08:00
}
if ($manager->isRunner() && $dtl->get('action') == 'start') {
2020-09-11 14:42:52 +08:00
return 'Service is running. Please use restart.';
2020-09-07 15:19:13 +08:00
}
2020-09-11 14:27:09 +08:00
$manager->shutdown();
2020-09-11 14:22:44 +08:00
if ($dtl->get('action') == 'stop') {
2020-09-11 14:42:52 +08:00
return 'shutdown success.';
2020-09-11 14:22:44 +08:00
}
$manager->start();
2020-09-03 00:15:57 +08:00
}
}