111
This commit is contained in:
+41
-35
@@ -16,48 +16,54 @@ use Kiri\Kiri;
|
||||
class Command extends \Console\Command
|
||||
{
|
||||
|
||||
public string $command = 'sw:server';
|
||||
public string $command = 'sw:server';
|
||||
|
||||
|
||||
public string $description = 'server start|stop|reload|restart';
|
||||
public string $description = 'server start|stop|reload|restart';
|
||||
|
||||
|
||||
const ACTIONS = ['start', 'stop', 'restart'];
|
||||
const ACTIONS = ['start', 'stop', 'restart'];
|
||||
|
||||
|
||||
/**
|
||||
* @param Input $dtl
|
||||
* @return string
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function onHandler(Input $dtl): string
|
||||
{
|
||||
$manager = Kiri::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.';
|
||||
}
|
||||
if ($manager->isRunner() && $dtl->get('action') == 'start') {
|
||||
return 'Service is running. Please use restart.';
|
||||
}
|
||||
|
||||
$manager->shutdown();
|
||||
if ($dtl->get('action') == 'stop') {
|
||||
return 'shutdown success.';
|
||||
}
|
||||
|
||||
$this->generate_runtime_builder();
|
||||
return $manager->start();
|
||||
}
|
||||
/**
|
||||
* @param Input $dtl
|
||||
* @return string
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function onHandler(Input $dtl): string
|
||||
{
|
||||
$manager = Kiri::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.';
|
||||
}
|
||||
if ($manager->isRunner() && $dtl->get('action') == 'start') {
|
||||
return 'Service is running. Please use restart.';
|
||||
}
|
||||
$manager->shutdown();
|
||||
if ($dtl->get('action') == 'stop') {
|
||||
return 'shutdown success.';
|
||||
}
|
||||
return $this->generate_runtime_builder($manager);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function generate_runtime_builder()
|
||||
{
|
||||
exec(PHP_BINARY . ' ' . APP_PATH . 'snowflake runtime:builder');
|
||||
}
|
||||
/**
|
||||
* @param $manager
|
||||
* @return mixed
|
||||
* @throws \Kiri\Exception\NotFindClassException
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
private function generate_runtime_builder($manager)
|
||||
{
|
||||
exec(PHP_BINARY . ' ' . APP_PATH . 'kiri.php runtime:builder');
|
||||
if (is_enable_file_modification_listening()) {
|
||||
scan_directory(directory('app'), 'App');
|
||||
$loader = Kiri::app()->getRouter();
|
||||
$loader->_loader();
|
||||
}
|
||||
return $manager->start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user