This commit is contained in:
Chris 2022-09-27 12:47:30 +02:00
parent 592f5579ab
commit 0b66b826f7
5 changed files with 24 additions and 8 deletions

View File

@ -1,7 +1,9 @@
# ServerCtl - Services for Developers
## Todo
- [ ] Add a --temporary option to start to remove volume after stop
## Examples

View File

@ -14,7 +14,7 @@ class ExecCommand extends Command
protected function configure()
{
$this->addOption("instance", "I", InputOption::VALUE_REQUIRED, "Specify the instance name", "default");
$this->addOption("instance", "i", InputOption::VALUE_REQUIRED, "Specify the instance name", "default");
$this->addOption("script", "s", InputOption::VALUE_NONE, "The command is a script (use 'list' for list)");
$this->addArgument("service", InputArgument::REQUIRED, "The service name");
$this->addArgument("execute", InputArgument::REQUIRED, "The command or script to execute");

View File

@ -14,7 +14,7 @@ class StartCommand extends Command
protected function configure()
{
$this->addOption("instance", "I", InputOption::VALUE_REQUIRED, "Specify the instance name", "default");
$this->addOption("instance", "i", InputOption::VALUE_REQUIRED, "Specify the instance name", "default");
$this->addOption("portoffset", "p", InputOption::VALUE_REQUIRED, "Offset port numbers by value", 0);
$this->addArgument("service", InputArgument::REQUIRED, "The service name");
}
@ -32,13 +32,19 @@ class StartCommand extends Command
$output->writeln("<error>No such service in registry</>");
return self::FAILURE;
}
$instanceName = $input->getOption("instance");
$options = [
'name' => $input->getOption("instance"),
'name' => $instanceName,
'portoffset' => $input->getOption("portoffset")
];
$containerManager->startService($serviceInfo, $options);
$info = $containerManager->startService($serviceInfo, $options);
$output->writeln("Started <fg=cyan>{$serviceName}</><<fg=cyan>{$instanceName}</>>");
foreach ($info['ports'] as $info=>$port) {
$output->writeln(" <info>{$info}</>: <comment>{$port}</comment>");
}
return self::SUCCESS;
}

View File

@ -14,7 +14,7 @@ class StopCommand extends Command
protected function configure()
{
$this->addOption("instance", "I", InputOption::VALUE_REQUIRED, "Specify the instance name", "default");
$this->addOption("instance", "i", InputOption::VALUE_REQUIRED, "Specify the instance name", "default");
$this->addArgument("service", InputArgument::REQUIRED, "The service name");
}
@ -25,6 +25,7 @@ class StopCommand extends Command
$serviceName = $input->getArgument("service");
$instanceName = $input->getOption("instance");
$serviceInfo = $serviceRegistry->findServiceByName($serviceName);
if (!$serviceInfo) {
@ -32,7 +33,7 @@ class StopCommand extends Command
return self::FAILURE;
}
$containerManager->stopService($serviceInfo, $input->getOption("instance"));
$containerManager->stopService($serviceInfo, $instanceName);
return self::SUCCESS;
}

View File

@ -28,6 +28,7 @@ class ContainerManager
$serviceName = $service['name'];
$instanceName = $options['name']??'default';
$portOffset = intval($options['portoffset']??0);
$containerName = "sm_".$serviceName."_".$instanceName;
@ -39,9 +40,12 @@ class ContainerManager
// Map the ports
$ports = (array)($service['ports']??[]);
$mappedPorts = [];
foreach ($ports as $port) {
$portNumber = intval($port['port']) + $portOffset;
$args[] = '-p';
$args[] = $port['port'];
$args[] = $portNumber;
$mappedPorts[$port['info']] = $portNumber;
}
// Get the paths to persist
@ -72,6 +76,10 @@ class ContainerManager
echo "$ {$cmdl}\n";
passthru($cmdl);
return [
'ports' => $mappedPorts
];
}
/**
@ -82,7 +90,6 @@ class ContainerManager
$args = [];
$serviceName = $service['name'];
$instanceName = $options['name']??'default';
$containerName = "sm_".$serviceName."_".$instanceName;
$args[] = 'stop';