A free, self-hostable news aggregator…
Docker healthcheck (#7945)
Alexandre Alapetitec8da217e875c
diff --git a/Docker/README.md b/Docker/README.mdindex 095c189c7..a641921c1 100644--- a/Docker/README.md+++ b/Docker/README.md@@ -338,7 +338,7 @@ services:TZ: Europe/Paris# Cron job to refresh feeds at specified minutesCRON_MIN: '2,32'- # 'development' for additional logs; default is 'production'+ # Optional 'development' for additional logs; default is 'production'FRESHRSS_ENV: development# Optional advanced parameter controlling the internal Apache listening portLISTEN: 0.0.0.0:80@@ -372,6 +372,14 @@ services:--language en--password ${ADMIN_PASSWORD}--user admin+ # Optional healthcheck+ healthcheck:+ test: ["CMD", "cli/health.php"]+ timeout: 10s+ start_period: 60s+ start_interval: 11s+ interval: 75s+ retries: 3```### Docker Compose with PostgreSQLdiff --git a/Docker/freshrss/docker-compose.yml b/Docker/freshrss/docker-compose.ymlindex e1f66179b..e9ff40240 100644--- a/Docker/freshrss/docker-compose.yml+++ b/Docker/freshrss/docker-compose.yml@@ -23,3 +23,11 @@ services:TZ: Europe/ParisCRON_MIN: '3,33'TRUSTED_PROXY: 172.16.0.1/12 192.168.0.1/16+ # # Optional healthcheck section:+ # healthcheck:+ # test: ["CMD", "cli/health.php"]+ # timeout: 10s+ # start_period: 60s+ # start_interval: 11s+ # interval: 75s+ # retries: 3diff --git a/cli/health.php b/cli/health.phpnew file mode 100755index 000000000..a001f43aa--- /dev/null+++ b/cli/health.php@@ -0,0 +1,31 @@+#!/usr/bin/env php+<?php+declare(strict_types=1);++if (php_sapi_name() !== 'cli') {+ echo 'Error: This script may only be invoked from command line!', PHP_EOL;+ die(2);+}++$options = getopt('', ['url::', 'connect_timeout::', 'timeout::']);+$address = is_string($options['url'] ?? null) ? $options['url'] : 'http://localhost/i/';+$ch = curl_init($address);+if ($ch === false) {+ fwrite(STDERR, 'Error: Failed to initialize cURL!' . PHP_EOL);+ die(3);+}+curl_setopt_array($ch, [+ CURLOPT_CONNECTTIMEOUT => is_numeric($options['connect_timeout'] ?? null) ? (int)$options['connect_timeout'] : 3,+ CURLOPT_TIMEOUT => is_numeric($options['timeout'] ?? null) ? (int)$options['timeout'] : 5,+ CURLOPT_ENCODING => '', //Enable all encodings+ CURLOPT_HTTPHEADER => [+ 'Connection: close',+ ],+ CURLOPT_RETURNTRANSFER => true,+]);+$content = curl_exec($ch);+$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);++if ($httpCode !== 200 || !is_string($content) || !str_contains($content, 'jsonVars') || !str_contains($content, '</html>')) {+ die(1);+}