zhamao-framework/src/ZM/Command/Server/ServerCommand.php

37 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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