Improve restart flagging for stations.
This commit is contained in:
parent
60a66c9356
commit
80400dc28f
|
@ -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,
|
||||
|
|
|
@ -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 . ']';
|
||||
|
|
Loading…
Reference in New Issue