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

View File

@ -100,7 +100,7 @@ use App\Models\Setup;
<!-- Binkp Settings -->
<div class="col-6">
<h3>BINKP Settings</h3>
<p>Bink has been configured to listen on <strong>{{ Setup::BINKP_BIND }}</strong>:<strong>{{ Setup::BINKP_PORT }}</strong></p>
<p>BINKD has been configured to listen on <strong>{{ Setup::BINKP_BIND }}</strong>:<strong>{{ Setup::BINKP_PORT }}</strong></p>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="startbinkd" name="options[binkd]" value="{{ Setup::O_BINKP }}" @if(old('options.binkd',$o->optionGet(Setup::O_BINKP))) checked @endif>
@ -149,6 +149,7 @@ use App\Models\Setup;
<p class="pt-3"><sup>*</sup> Recommended Defaults</p>
<!-- @todo What's this for again? -->
<table class="table monotable">
{{--
$this->binkp_options = ['m','d','r','b'];
@ -159,7 +160,7 @@ use App\Models\Setup;
<!-- EMSI Settings -->
<div class="col-6">
<h3>EMSI Settings</h3>
<p>Bink has been configured to listen on <strong>{{ Setup::EMSI_BIND }}</strong>:<strong>{{ Setup::EMSI_PORT }}</strong></p>
<p>EMSI has been configured to listen on <strong>{{ Setup::EMSI_BIND }}</strong>:<strong>{{ Setup::EMSI_PORT }}</strong></p>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="startemsi" name="options[emsi]" value="{{ Setup::O_EMSI }}" @if(old('options.emsi',$o->optionGet(Setup::O_EMSI))) checked @endif>