getStation(); $backend = $this->adapters->getBackendAdapter($station); $frontend = $this->adapters->getFrontendAdapter($station); return $response->withJson( new Entity\Api\StationServiceStatus( null !== $backend && $backend->isRunning($station), null !== $frontend && $frontend->isRunning($station), $station->getHasStarted(), $station->getNeedsRestart() ) ); } public function reloadAction( ServerRequest $request, Response $response, string $station_id ): ResponseInterface { // Reloading attempts to update configuration without restarting broadcasting, if possible and supported. $station = $request->getStation(); try { $station->setHasStarted(true); $this->em->persist($station); $this->em->flush(); $this->configuration->writeConfiguration( station: $station, forceRestart: true ); $this->nginx->writeConfiguration($station); } catch (Throwable $e) { return $response->withJson( new Entity\Api\Error( 500, $e->getMessage() ) ); } return $response->withJson(new Entity\Api\Status(true, __('Station reloaded.'))); } public function restartAction( ServerRequest $request, Response $response, string $station_id ): ResponseInterface { // Restarting will always shut down and restart any services. $station = $request->getStation(); try { $station->setHasStarted(true); $this->em->persist($station); $this->em->flush(); $this->configuration->writeConfiguration( station: $station, forceRestart: true, attemptReload: false ); $this->nginx->writeConfiguration($station); } catch (Throwable $e) { return $response->withJson( new Entity\Api\Error( 500, $e->getMessage() ) ); } return $response->withJson(new Entity\Api\Status(true, __('Station restarted.'))); } public function frontendAction( ServerRequest $request, Response $response, string $station_id, string $do = 'restart' ): ResponseInterface { $station = $request->getStation(); $frontend = $this->adapters->getFrontendAdapter($station); if (null === $frontend) { throw new StationUnsupportedException(); } switch ($do) { case 'stop': $frontend->stop($station); return $response->withJson(new Entity\Api\Status(true, __('Service stopped.'))); case 'start': $frontend->start($station); return $response->withJson(new Entity\Api\Status(true, __('Service started.'))); case 'reload': $frontend->write($station); $frontend->reload($station); return $response->withJson(new Entity\Api\Status(true, __('Service reloaded.'))); case 'restart': default: try { $frontend->stop($station); } catch (NotRunningException) { } $frontend->write($station); $frontend->start($station); return $response->withJson(new Entity\Api\Status(true, __('Service restarted.'))); } } public function backendAction( ServerRequest $request, Response $response, string $station_id, string $do = 'restart' ): ResponseInterface { $station = $request->getStation(); $backend = $this->adapters->getBackendAdapter($station); if (null === $backend) { throw new StationUnsupportedException(); } switch ($do) { case 'skip': $backend->skip($station); return $response->withJson(new Entity\Api\Status(true, __('Song skipped.'))); case 'disconnect': $backend->disconnectStreamer($station); return $response->withJson(new Entity\Api\Status(true, __('Streamer disconnected.'))); case 'stop': $backend->stop($station); return $response->withJson(new Entity\Api\Status(true, __('Service stopped.'))); case 'start': $backend->start($station); return $response->withJson(new Entity\Api\Status(true, __('Service started.'))); case 'reload': $backend->write($station); $backend->reload($station); return $response->withJson(new Entity\Api\Status(true, __('Service reloaded.'))); case 'restart': default: try { $backend->stop($station); } catch (NotRunningException) { } $backend->write($station); $backend->start($station); return $response->withJson(new Entity\Api\Status(true, __('Service restarted.'))); } } }