74 lines
2.6 KiB
PHP
74 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Command;
|
|
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
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: '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, '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
|
|
{
|
|
$cmd = ['.venv/bin/python', 'python/vector/vector_control.py'];
|
|
|
|
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';
|
|
}
|
|
|
|
$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 $process->isSuccessful() ? Command::SUCCESS : Command::FAILURE;
|
|
}
|
|
} |