mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-23 08:35:35 +08:00
update to 3.0.0-alpha2 (build 610): refactor driver
This commit is contained in:
@@ -8,7 +8,7 @@ use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use ZM\Exception\ZMKnownException;
|
||||
use ZM\Utils\Manager\ProcessManager;
|
||||
use ZM\Process\ProcessStateManager;
|
||||
|
||||
abstract class ServerCommand extends Command
|
||||
{
|
||||
@@ -19,11 +19,12 @@ abstract class ServerCommand extends Command
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$file = ProcessManager::getProcessState(ZM_PROCESS_MASTER);
|
||||
$file = ProcessStateManager::getProcessState(ZM_PROCESS_MASTER);
|
||||
/* @noinspection PhpComposerExtensionStubsInspection */
|
||||
if ($file === false || posix_getsid(intval($file['pid'])) === false) {
|
||||
$output->writeln('<comment>未检测到正在运行的守护进程或框架进程!</comment>');
|
||||
if (ProcessManager::isStateEmpty()) {
|
||||
ProcessManager::removeProcessState(ZM_PROCESS_MASTER);
|
||||
if (ProcessStateManager::isStateEmpty()) {
|
||||
ProcessStateManager::removeProcessState(ZM_PROCESS_MASTER);
|
||||
} else {
|
||||
$output->writeln('<comment>检测到可能残留的守护进程或框架进程,请使用命令关闭:server:stop --force</comment>');
|
||||
}
|
||||
|
||||
@@ -4,24 +4,24 @@ declare(strict_types=1);
|
||||
|
||||
namespace ZM\Command\Server;
|
||||
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use ZM\Exception\ConfigException;
|
||||
use ZM\Exception\InitException;
|
||||
use ZM\Exception\ZMKnownException;
|
||||
use ZM\Framework;
|
||||
use ZM\Utils\Manager\ProcessManager;
|
||||
use ZM\Process\ProcessStateManager;
|
||||
|
||||
class ServerStartCommand extends ServerCommand
|
||||
{
|
||||
protected static $defaultName = 'server';
|
||||
|
||||
public static function exportDefinition(): InputDefinition
|
||||
public static function exportOptionArray(): array
|
||||
{
|
||||
$cmd = new self();
|
||||
$cmd->configure();
|
||||
return $cmd->getDefinition();
|
||||
return array_map(function ($x) { return $x->getDefault(); }, $cmd->getDefinition()->getOptions());
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
@@ -29,7 +29,10 @@ class ServerStartCommand extends ServerCommand
|
||||
$this->setAliases(['server:start']);
|
||||
$this->setDefinition([
|
||||
new InputOption('debug-mode', 'D', null, '开启调试模式 (这将关闭协程化)'),
|
||||
new InputOption('config-dir', null, InputOption::VALUE_REQUIRED, '指定其他配置文件目录'),
|
||||
new InputOption('driver', null, InputOption::VALUE_REQUIRED, '指定驱动类型'),
|
||||
new InputOption('log-debug', null, null, '调整消息等级到debug (log-level=4)'),
|
||||
new InputOption('log-level', null, InputOption::VALUE_REQUIRED, '调整消息等级到debug (log-level=4)'),
|
||||
new InputOption('log-verbose', null, null, '调整消息等级到verbose (log-level=3)'),
|
||||
new InputOption('log-info', null, null, '调整消息等级到info (log-level=2)'),
|
||||
new InputOption('log-warning', null, null, '调整消息等级到warning (log-level=1)'),
|
||||
@@ -59,22 +62,26 @@ class ServerStartCommand extends ServerCommand
|
||||
|
||||
/**
|
||||
* @throws ZMKnownException
|
||||
* @throws ConfigException
|
||||
* @throws ConfigException|InitException
|
||||
* @noinspection PhpComposerExtensionStubsInspection
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
if (($opt = $input->getOption('env')) !== null) {
|
||||
// 这段用于config的环境解析,但显然不是很好的方式,应该改成一个独立的方法,不应该在这里检查,但暂时搁置,TODO
|
||||
/* if (($opt = $input->getOption('env')) !== null) {
|
||||
if (!in_array($opt, ['production', 'staging', 'development', ''])) {
|
||||
$output->writeln('<error> "--env" option only accept production, development, staging and [empty] ! </error>');
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
$state = ProcessManager::getProcessState(ZM_PROCESS_MASTER);
|
||||
if (!$input->getOption('no-state-check')) {
|
||||
if (is_array($state) && posix_getsid($state['pid'] ?? -1) !== false) {
|
||||
$output->writeln("<error>检测到已经在 pid: {$state['pid']} 进程启动了框架!</error>");
|
||||
$output->writeln('<error>不可以同时启动两个框架!</error>');
|
||||
return 1;
|
||||
}*/
|
||||
if (\OneBot\Driver\Process\ProcessManager::isSupportedMultiProcess()) {
|
||||
$state = ProcessStateManager::getProcessState(ZM_PROCESS_MASTER);
|
||||
if (!$input->getOption('no-state-check')) {
|
||||
if (is_array($state) && posix_getsid($state['pid'] ?? -1) !== false) {
|
||||
$output->writeln("<error>检测到已经在 pid: {$state['pid']} 进程启动了框架!</error>");
|
||||
$output->writeln('<error>不可以同时启动两个框架!</error>');
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
(new Framework($input->getOptions()))->start();
|
||||
|
||||
@@ -8,8 +8,8 @@ use Swoole\Process;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use ZM\Utils\DataProvider;
|
||||
use ZM\Utils\Manager\ProcessManager;
|
||||
use ZM\Process\ProcessStateManager;
|
||||
use ZM\Store\FileSystem;
|
||||
|
||||
class ServerStopCommand extends ServerCommand
|
||||
{
|
||||
@@ -26,8 +26,8 @@ class ServerStopCommand extends ServerCommand
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
if ($input->getOption('force') !== false) {
|
||||
$file_path = _zm_pid_dir();
|
||||
$list = DataProvider::scanDirFiles($file_path, false, true);
|
||||
$file_path = ZM_PID_DIR;
|
||||
$list = FileSystem::scanDirFiles($file_path, false, true);
|
||||
foreach ($list as $file) {
|
||||
$name = explode('.', $file);
|
||||
if (end($name) == 'pid') {
|
||||
@@ -46,7 +46,7 @@ class ServerStopCommand extends ServerCommand
|
||||
Process::kill(intval($this->daemon_file['pid']), SIGTERM);
|
||||
}
|
||||
$i = 10;
|
||||
while (ProcessManager::getProcessState(ZM_PROCESS_MASTER) !== false && $i > 0) {
|
||||
while (ProcessStateManager::getProcessState(ZM_PROCESS_MASTER) !== false && $i > 0) {
|
||||
sleep(1);
|
||||
--$i;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user