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,14 +185,10 @@ class Configuration
}
} catch (SupervisorException) {
}
$was_restarted = true;
}
if ($was_restarted) {
$this->markAsStarted($station);
}
}
$this->markAsStarted($station);
}
/**
@ -449,15 +450,15 @@ class Configuration
[, $program_name] = explode(':', $adapter->getProgramName($station));
$config_lines = [
'user' => 'azuracast',
'priority' => $priority ?? 50,
'command' => $adapter->getCommand($station),
'directory' => $station->getRadioConfigDir(),
'environment' => 'TZ="' . $station->getTimezone() . '"',
'stdout_logfile' => $adapter->getLogPath($station),
'user' => 'azuracast',
'priority' => $priority ?? 50,
'command' => $adapter->getCommand($station),
'directory' => $station->getRadioConfigDir(),
'environment' => 'TZ="' . $station->getTimezone() . '"',
'stdout_logfile' => $adapter->getLogPath($station),
'stdout_logfile_maxbytes' => '5MB',
'stdout_logfile_backups' => '10',
'redirect_stderr' => 'true',
'stdout_logfile_backups' => '10',
'redirect_stderr' => 'true',
];
$supervisor_config[] = '[program:' . $program_name . ']';