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

View File

@ -103,6 +103,11 @@ class Configuration
$supervisorConfig = []; $supervisorConfig = [];
$supervisorConfigFile = $this->getSupervisorConfigFile($station); $supervisorConfigFile = $this->getSupervisorConfigFile($station);
if (!$station->getHasStarted()) {
$this->unlinkAndStopStation($station, $reloadSupervisor);
throw new RuntimeException('Station has not started yet.');
}
if (!$station->getIsEnabled()) { if (!$station->getIsEnabled()) {
$this->unlinkAndStopStation($station, $reloadSupervisor); $this->unlinkAndStopStation($station, $reloadSupervisor);
throw new RuntimeException('Station is disabled.'); throw new RuntimeException('Station is disabled.');
@ -180,14 +185,10 @@ class Configuration
} }
} catch (SupervisorException) { } 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)); [, $program_name] = explode(':', $adapter->getProgramName($station));
$config_lines = [ $config_lines = [
'user' => 'azuracast', 'user' => 'azuracast',
'priority' => $priority ?? 50, 'priority' => $priority ?? 50,
'command' => $adapter->getCommand($station), 'command' => $adapter->getCommand($station),
'directory' => $station->getRadioConfigDir(), 'directory' => $station->getRadioConfigDir(),
'environment' => 'TZ="' . $station->getTimezone() . '"', 'environment' => 'TZ="' . $station->getTimezone() . '"',
'stdout_logfile' => $adapter->getLogPath($station), 'stdout_logfile' => $adapter->getLogPath($station),
'stdout_logfile_maxbytes' => '5MB', 'stdout_logfile_maxbytes' => '5MB',
'stdout_logfile_backups' => '10', 'stdout_logfile_backups' => '10',
'redirect_stderr' => 'true', 'redirect_stderr' => 'true',
]; ];
$supervisor_config[] = '[program:' . $program_name . ']'; $supervisor_config[] = '[program:' . $program_name . ']';