This commit is contained in:
2021-04-13 17:27:27 +08:00
parent fd47bad47f
commit 45c8496d88
+30 -28
View File
@@ -16,41 +16,43 @@ use Snowflake\Snowflake;
class Command extends \Console\Command 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 * @param Input $dtl
* @return string * @return string
* @throws Exception * @throws Exception
* @throws ConfigException * @throws ConfigException
*/ */
public function onHandler(Input $dtl): string public function onHandler(Input $dtl): string
{ {
$manager = Snowflake::app()->getServer(); $manager = Snowflake::app()->getServer();
$manager->setDaemon($dtl->get('daemon', 0)); $manager->setDaemon($dtl->get('daemon', 0));
if (!in_array($dtl->get('action'), self::ACTIONS)) { if (!in_array($dtl->get('action'), self::ACTIONS)) {
return 'I don\'t know what I want to do.'; return 'I don\'t know what I want to do.';
} }
if (!file_exists(storage('runtime.php'))) {
exec(PHP_BINARY . ' snowflake runtime:builder');
}
/** @var Shutdown $shutdown */
$shutdown = Snowflake::app()->get('shutdown');
if ($shutdown->isRunning() && $dtl->get('action') == 'start') {
return 'Service is running. Please use restart.';
}
/** @var Shutdown $shutdown */ $shutdown->shutdown();
$shutdown = Snowflake::app()->get('shutdown'); if ($dtl->get('action') == 'stop') {
if ($shutdown->isRunning() && $dtl->get('action') == 'start') { return 'shutdown success.';
return 'Service is running. Please use restart.'; }
} return $manager->start();
}
$shutdown->shutdown();
if ($dtl->get('action') == 'stop') {
return 'shutdown success.';
}
return $manager->start();
}
} }