diff --git a/library/Icinga/Application/Daemon/HttpJob.php b/library/Icinga/Application/Daemon/HttpJob.php new file mode 100644 index 000000000..0a71e51c0 --- /dev/null +++ b/library/Icinga/Application/Daemon/HttpJob.php @@ -0,0 +1,70 @@ +socketPath = $config->get('socket', '/var/run/icingawebd.socket'); + } + + public function attach(LoopInterface $loop): void + { + Logger::info('Starting handling of incoming HTTP requests'); + + if (file_exists($this->socketPath)) { + // The SocketServer itself doesn't remove it, for whatever reason, and fails on restart if we don't either + unlink($this->socketPath); + } + + $this->socket = new SocketServer('unix://' . $this->socketPath, [], $loop); + $this->server = new HttpServer($loop, function ($req) { + return $this->handle($req); + }); + $this->server->listen($this->socket); + } + + public function cancel(): void + { + Logger::info('Stopping handling of incoming HTTP requests'); + + $this->socket->close(); + } + + /** + * Handle the given HTTP request + * + * @param ServerRequestInterface $request + * + * @return ResponseInterface + */ + protected function handle(ServerRequestInterface $request): ResponseInterface + { + return Response::plaintext('Hello World!' . PHP_EOL); + } +}