mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-12-03 09:48:41 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
95e25dea0a |
No files matched your search
+4
-4
@@ -129,10 +129,10 @@ ARG RUNTIME_PACKAGES="\
|
|||||||
ghostscript \
|
ghostscript \
|
||||||
gnupg \
|
gnupg \
|
||||||
icc-profiles-free \
|
icc-profiles-free \
|
||||||
# PostgreSQL
|
# PostgreSQL client library, used by psycopg
|
||||||
postgresql-client \
|
libpq5 \
|
||||||
# MySQL / MariaDB
|
# MariaDB client library, used by mysqlclient
|
||||||
mariadb-client \
|
libmariadb3 \
|
||||||
# OCRmyPDF dependencies
|
# OCRmyPDF dependencies
|
||||||
tesseract-ocr \
|
tesseract-ocr \
|
||||||
tesseract-ocr-eng \
|
tesseract-ocr-eng \
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Single-shot database readiness probe used by the init-wait-for-db s6 service.
|
||||||
|
|
||||||
|
Exits 0 if the database server is accepting connections, 1 otherwise. The
|
||||||
|
retry and backoff loop lives in the calling shell script.
|
||||||
|
|
||||||
|
This replaces pg_isready / mariadb-admin ping, so the image does not need the
|
||||||
|
PostgreSQL or MariaDB command line clients. Like those tools, this only checks
|
||||||
|
that the server answers. A server which responds with an error, such as bad
|
||||||
|
credentials or an unknown database, counts as ready, so the real error is
|
||||||
|
reported by the migrations step instead of this one timing out.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
CONNECT_TIMEOUT = 5
|
||||||
|
|
||||||
|
|
||||||
|
def postgres_ready() -> bool:
|
||||||
|
from psycopg import pq
|
||||||
|
from psycopg.conninfo import make_conninfo
|
||||||
|
|
||||||
|
# This is libpq's PQping, which is what pg_isready uses. It reports OK when
|
||||||
|
# the server answers, even if it would refuse these credentials, and REJECT
|
||||||
|
# when the server is up but still starting or shutting down.
|
||||||
|
conninfo = make_conninfo(
|
||||||
|
host=os.environ.get("PAPERLESS_DBHOST", "localhost"),
|
||||||
|
port=int(os.environ.get("PAPERLESS_DBPORT", "5432")),
|
||||||
|
user=os.environ.get("PAPERLESS_DBUSER", "paperless"),
|
||||||
|
connect_timeout=CONNECT_TIMEOUT,
|
||||||
|
)
|
||||||
|
return pq.PGconn.ping(conninfo.encode()) == pq.Ping.OK
|
||||||
|
|
||||||
|
|
||||||
|
def mariadb_ready() -> bool:
|
||||||
|
import MySQLdb
|
||||||
|
|
||||||
|
try:
|
||||||
|
MySQLdb.connect(
|
||||||
|
host=os.environ.get("PAPERLESS_DBHOST", "localhost"),
|
||||||
|
port=int(os.environ.get("PAPERLESS_DBPORT", "3306")),
|
||||||
|
user=os.environ.get("PAPERLESS_DBUSER", "paperless"),
|
||||||
|
passwd=os.environ.get("PAPERLESS_DBPASS", "paperless"),
|
||||||
|
connect_timeout=CONNECT_TIMEOUT,
|
||||||
|
).close()
|
||||||
|
return True
|
||||||
|
except MySQLdb.OperationalError as e:
|
||||||
|
# Codes below 2000 are errors sent by the server (access denied, too
|
||||||
|
# many connections, ...). 2000+ are client side (can't connect, lost
|
||||||
|
# connection), meaning the server was not reached.
|
||||||
|
code = e.args[0] if e.args and isinstance(e.args[0], int) else 0
|
||||||
|
return 0 < code < 2000
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
if os.environ.get("PAPERLESS_DBENGINE") == "mariadb":
|
||||||
|
ready = mariadb_ready()
|
||||||
|
else:
|
||||||
|
ready = postgres_ready()
|
||||||
|
return 0 if ready else 1
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
@@ -7,6 +7,7 @@ set -euo pipefail
|
|||||||
declare -r LOG_PREFIX="[init-db-wait]"
|
declare -r LOG_PREFIX="[init-db-wait]"
|
||||||
|
|
||||||
declare -ri TIMEOUT=60
|
declare -ri TIMEOUT=60
|
||||||
|
declare -r PROBE="/etc/s6-overlay/s6-rc.d/init-wait-for-db/db_ready.py"
|
||||||
declare -i ATTEMPT=0
|
declare -i ATTEMPT=0
|
||||||
declare -i DELAY=0
|
declare -i DELAY=0
|
||||||
declare -i STARTED_AT=${EPOCHSECONDS:?EPOCHSECONDS var unset}
|
declare -i STARTED_AT=${EPOCHSECONDS:?EPOCHSECONDS var unset}
|
||||||
@@ -35,11 +36,7 @@ delay_next_attempt() {
|
|||||||
wait_for_postgres() {
|
wait_for_postgres() {
|
||||||
echo "${LOG_PREFIX} Waiting for PostgreSQL to start..."
|
echo "${LOG_PREFIX} Waiting for PostgreSQL to start..."
|
||||||
|
|
||||||
local -r host="${PAPERLESS_DBHOST:-localhost}"
|
while ! python3 "${PROBE}"; do
|
||||||
local -r port="${PAPERLESS_DBPORT:-5432}"
|
|
||||||
local -r user="${PAPERLESS_DBUSER:-paperless}"
|
|
||||||
|
|
||||||
while ! pg_isready -h "${host}" -p "${port}" --username "${user}"; do
|
|
||||||
delay_next_attempt
|
delay_next_attempt
|
||||||
done
|
done
|
||||||
echo "${LOG_PREFIX} Connected to PostgreSQL"
|
echo "${LOG_PREFIX} Connected to PostgreSQL"
|
||||||
@@ -48,10 +45,7 @@ wait_for_postgres() {
|
|||||||
wait_for_mariadb() {
|
wait_for_mariadb() {
|
||||||
echo "${LOG_PREFIX} Waiting for MariaDB to start..."
|
echo "${LOG_PREFIX} Waiting for MariaDB to start..."
|
||||||
|
|
||||||
local -r host="${PAPERLESS_DBHOST:-localhost}"
|
while ! python3 "${PROBE}"; do
|
||||||
local -r port="${PAPERLESS_DBPORT:-3306}"
|
|
||||||
|
|
||||||
while ! mariadb-admin --host="${host}" --port="${port}" --skip-ssl ping --silent >/dev/null 2>&1; do
|
|
||||||
delay_next_attempt
|
delay_next_attempt
|
||||||
done
|
done
|
||||||
echo "${LOG_PREFIX} Connected to MariaDB"
|
echo "${LOG_PREFIX} Connected to MariaDB"
|
||||||
|
|||||||
Reference in new issue
Block a user