Improve restart flagging for stations.

This commit is contained in:
Buster "Silver Eagle" Neece 2022-06-21 10:45:42 -05:00
parent 60a66c9356
commit 80400dc28f
No known key found for this signature in database
GPG Key ID: F1D2E64A0005E80E
2 changed files with 25 additions and 14 deletions

View File

@ -12,6 +12,7 @@ use App\Nginx\Nginx;
use App\OpenApi;
use App\Radio\Backend\Liquidsoap;
use App\Radio\Configuration;
use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Attributes as OA;
use Psr\Http\Message\ResponseInterface;
use Throwable;
@ -105,6 +106,7 @@ use Throwable;
final class ServicesController
{
public function __construct(
private readonly EntityManagerInterface $em,
private readonly Configuration $configuration,
private readonly Nginx $nginx,
) {
@ -139,6 +141,10 @@ final class ServicesController
$station = $request->getStation();
try {
$station->setHasStarted(true);
$this->em->persist($station);
$this->em->flush();
$this->configuration->writeConfiguration(
station: $station,
forceRestart: true
@ -166,6 +172,10 @@ final class ServicesController
$station = $request->getStation();
try {
$station->setHasStarted(true);
$this->em->persist($station);
$this->em->flush();
$this->configuration->writeConfiguration(
station: $station,
forceRestart: true,

View File

@ -103,6 +103,11 @@ class Configuration
$supervisorConfig = [];
$supervisorConfigFile = $this->getSupervisorConfigFile($station);
if (!$station->getHasStarted()) {
$this->unlinkAndStopStation($station, $reloadSupervisor);
throw new RuntimeException('Station has not started yet.');
}
if (!$station->getIsEnabled()) {
$this->unlinkAndStopStation($station, $reloadSupervisor);
throw new RuntimeException('Station is disabled.');
@ -180,15 +185,11 @@ class Configuration
}
} catch (SupervisorException) {
}
$was_restarted = true;
}
}
if ($was_restarted) {
$this->markAsStarted($station);
}
}
}
/**
* @param Station $station