Server start based on config

This commit is contained in:
Deon George
2021-08-14 14:10:29 +10:00
parent 6c6976678f
commit 569201e972
2 changed files with 26 additions and 15 deletions

View File

@@ -36,27 +36,34 @@ class StartServer extends Command
{
$o = Setup::findOrFail(config('app.id'));
// @todo This should be a config item.
$start = [
'emsi' => [
'address'=>Setup::EMSI_BIND,
'port'=>Setup::EMSI_PORT,
'class'=>new EMSI($o),
$start = collect();
],
'binkp' => [
if ($o->optionGet(Setup::O_BINKP))
$start->put('binkp',[
'address'=>Setup::BINKP_BIND,
'port'=>Setup::BINKP_PORT,
'class'=>new Binkp($o),
],
];
]);
if ($o->optionGet(Setup::O_EMSI))
$start->put('emsi',[
'address'=>Setup::EMSI_BIND,
'port'=>Setup::EMSI_PORT,
'class'=>new EMSI($o),
]);
$children = collect();
Log::debug(sprintf('%s:+ Starting Servers...',__METHOD__));
if (! $start->count()) {
Log::alert(sprintf('%s: - No servers configured to start',__METHOD__));
return;
}
pcntl_signal(SIGCHLD,SIG_IGN);
foreach ($start as $item => $config) {
foreach ($start->toArray() as $item => $config) {
Log::debug(sprintf('%s: - Starting: [%s]',__METHOD__,$item));
$pid = pcntl_fork();
@@ -91,11 +98,14 @@ class StartServer extends Command
}
// Wait for children to exit
while ($children->count()) {
while ($x=$children->count()) {
// Wait for children to finish
$exited = pcntl_wait($status);
Log::info(sprintf('%s: - Exited: [%s]',__METHOD__,$children->pull($exited)));
if ($exited < 0)
abort(500,'Something strange for status: '.serialize($status));
Log::info(sprintf('%s: - Exited: #%d [%s]',__METHOD__,$x,$children->pull($exited)));
}
// Done