Files
kiri-core/HttpServer/Command.php
T

66 lines
1.2 KiB
PHP
Raw Normal View History

2020-09-03 00:15:57 +08:00
<?php
2020-10-29 18:17:25 +08:00
declare(strict_types=1);
2020-09-03 00:15:57 +08:00
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
{
2021-04-13 17:27:27 +08:00
public string $command = 'sw:server';
public string $description = 'server start|stop|reload|restart';
const ACTIONS = ['start', 'stop', 'restart'];
/**
* @param Input $dtl
* @return string
* @throws Exception
* @throws ConfigException
*/
public function onHandler(Input $dtl): string
{
$manager = Snowflake::app()->getServer();
$manager->setDaemon($dtl->get('daemon', 0));
if (!in_array($dtl->get('action'), self::ACTIONS)) {
return 'I don\'t know what I want to do.';
}
2021-04-30 10:58:46 +08:00
2021-04-13 17:27:27 +08:00
/** @var Shutdown $shutdown */
$shutdown = Snowflake::app()->get('shutdown');
if ($shutdown->isRunning() && $dtl->get('action') == 'start') {
return 'Service is running. Please use restart.';
}
$shutdown->shutdown();
if ($dtl->get('action') == 'stop') {
return 'shutdown success.';
}
2021-04-30 11:15:57 +08:00
$this->generate_runtime_builder();
2021-04-13 17:27:27 +08:00
return $manager->start();
}
2020-09-03 00:15:57 +08:00
2021-04-30 11:15:57 +08:00
2021-04-30 11:21:53 +08:00
/**
*
*/
2021-04-30 11:15:57 +08:00
private function generate_runtime_builder()
{
2021-05-18 14:13:46 +08:00
exec(PHP_BINARY . ' ' . APP_PATH . 'snowflake runtime:builder');
2021-04-30 11:15:57 +08:00
}
2020-09-03 00:15:57 +08:00
}