Bugfixes
This commit is contained in:
		@@ -1,7 +1,9 @@
 | 
			
		||||
# ServerCtl - Services for Developers
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Todo
 | 
			
		||||
 | 
			
		||||
- [ ] Add a --temporary option to start to remove volume after stop
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Examples
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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';
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user