2021-01-29 20:47:00 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
|
declare(strict_types=1);
|
2021-01-29 20:47:00 +08:00
|
|
|
|
|
2022-05-14 23:40:22 +08:00
|
|
|
|
namespace ZM\Command\Server;
|
2021-01-29 20:47:00 +08:00
|
|
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2022-05-14 23:40:22 +08:00
|
|
|
|
use ZM\Exception\ZMKnownException;
|
2022-08-01 16:31:54 +08:00
|
|
|
|
use ZM\Process\ProcessStateManager;
|
2021-01-29 20:47:00 +08:00
|
|
|
|
|
2022-05-14 23:40:22 +08:00
|
|
|
|
abstract class ServerCommand extends Command
|
2021-01-29 20:47:00 +08:00
|
|
|
|
{
|
2022-03-15 18:05:33 +08:00
|
|
|
|
protected $daemon_file;
|
2021-01-29 20:47:00 +08:00
|
|
|
|
|
2022-05-14 23:40:22 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @throws ZMKnownException
|
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
|
|
{
|
2022-08-01 16:31:54 +08:00
|
|
|
|
$file = ProcessStateManager::getProcessState(ZM_PROCESS_MASTER);
|
|
|
|
|
|
/* @noinspection PhpComposerExtensionStubsInspection */
|
2022-03-15 18:05:33 +08:00
|
|
|
|
if ($file === false || posix_getsid(intval($file['pid'])) === false) {
|
|
|
|
|
|
$output->writeln('<comment>未检测到正在运行的守护进程或框架进程!</comment>');
|
2022-08-01 16:31:54 +08:00
|
|
|
|
if (ProcessStateManager::isStateEmpty()) {
|
|
|
|
|
|
ProcessStateManager::removeProcessState(ZM_PROCESS_MASTER);
|
2022-05-14 23:40:22 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
$output->writeln('<comment>检测到可能残留的守护进程或框架进程,请使用命令关闭:server:stop --force</comment>');
|
|
|
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
|
exit(1);
|
2021-01-29 20:47:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
$this->daemon_file = $file;
|
2021-04-06 01:19:56 +08:00
|
|
|
|
return 0;
|
2021-01-29 20:47:00 +08:00
|
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
|
}
|