optimize py control service
This commit is contained in:
@@ -9,19 +9,26 @@ use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'mto:agent:vector:control',
|
||||
description: 'Vector environment control'
|
||||
description: 'Production-safe vector service control (deps/install/start/stop/reload/status)'
|
||||
)]
|
||||
final class VectorControlCommand extends Command
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->addOption('install', null, InputOption::VALUE_NONE)
|
||||
->addOption('start', null, InputOption::VALUE_NONE)
|
||||
->addOption('reload', null, InputOption::VALUE_NONE);
|
||||
->addOption('install', null, InputOption::VALUE_NONE, 'Install missing python deps into .venv')
|
||||
->addOption('start', null, InputOption::VALUE_NONE, 'Start service if not running')
|
||||
->addOption('stop', null, InputOption::VALUE_NONE, 'Stop service using PID file')
|
||||
->addOption('force', null, InputOption::VALUE_NONE, 'Force stop (SIGKILL) if needed')
|
||||
->addOption('reload', null, InputOption::VALUE_NONE, 'Trigger /reload')
|
||||
->addOption('status', null, InputOption::VALUE_NONE, 'Print status')
|
||||
->addOption('foreground', null, InputOption::VALUE_NONE, 'Start in foreground (rare)')
|
||||
->addOption('port', null, InputOption::VALUE_OPTIONAL, 'Port (default 8090)', '8090')
|
||||
->addOption('host', null, InputOption::VALUE_OPTIONAL, 'Host (default 0.0.0.0)', '0.0.0.0');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
@@ -31,21 +38,37 @@ final class VectorControlCommand extends Command
|
||||
if ($input->getOption('install')) {
|
||||
$cmd[] = '--install';
|
||||
}
|
||||
|
||||
if ($input->getOption('start')) {
|
||||
$cmd[] = '--start';
|
||||
}
|
||||
|
||||
if ($input->getOption('stop')) {
|
||||
$cmd[] = '--stop';
|
||||
}
|
||||
if ($input->getOption('force')) {
|
||||
$cmd[] = '--force';
|
||||
}
|
||||
if ($input->getOption('reload')) {
|
||||
$cmd[] = '--reload';
|
||||
}
|
||||
if ($input->getOption('status')) {
|
||||
$cmd[] = '--status';
|
||||
}
|
||||
if ($input->getOption('foreground')) {
|
||||
$cmd[] = '--foreground';
|
||||
}
|
||||
|
||||
$process = new \Symfony\Component\Process\Process($cmd);
|
||||
$cmd[] = '--port';
|
||||
$cmd[] = (string)$input->getOption('port');
|
||||
|
||||
$cmd[] = '--host';
|
||||
$cmd[] = (string)$input->getOption('host');
|
||||
|
||||
$process = new Process($cmd);
|
||||
$process->setTimeout(300);
|
||||
$process->run();
|
||||
|
||||
$output->writeln($process->getOutput());
|
||||
|
||||
return Command::SUCCESS;
|
||||
return $process->isSuccessful() ? Command::SUCCESS : Command::FAILURE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user