From 3e0045219073281b7045e90e6343be41eb48b2b7 Mon Sep 17 00:00:00 2001 From: ngosang Date: Thu, 2 Feb 2023 19:48:08 +0100 Subject: [PATCH] Rename PASSWORD_FILE env var to RESTIC_REPO_PASSWORD_FILE --- README.md | 2 +- entrypoint.sh | 7 ++----- restic-exporter.py | 10 +++++----- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e5c3c31..7b673db 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Requirements: pip install -r /requirements.txt export RESTIC_REPO_URL=/data -export PASSWORD_FILE=/restic_password_file +export RESTIC_REPO_PASSWORD_FILE=/restic_password_file python restic-exporter.py ``` diff --git a/entrypoint.sh b/entrypoint.sh index a9832f6..9e17911 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,17 +3,14 @@ # Exit on error. For debug use set -x set -e -export PASSWORD_FILE="/tmp/restic_passwd" - if [ -z "${RESTIC_REPO_PASSWORD}" ]; then if [ -z "${RESTIC_REPO_PASSWORD_FILE}" ]; then echo "You have to define one of these environment variables: RESTIC_REPO_PASSWORD or RESTIC_REPO_PASSWORD_FILE" exit 1 - else - cp "${RESTIC_REPO_PASSWORD_FILE}" "${PASSWORD_FILE}" fi else - echo "${RESTIC_REPO_PASSWORD}" > "${PASSWORD_FILE}" + export RESTIC_REPO_PASSWORD_FILE="/tmp/restic_passwd" + echo "${RESTIC_REPO_PASSWORD}" > "${RESTIC_REPO_PASSWORD_FILE}" fi /usr/local/bin/python -u /restic-exporter.py diff --git a/restic-exporter.py b/restic-exporter.py index 46ee0e4..7636c87 100644 --- a/restic-exporter.py +++ b/restic-exporter.py @@ -14,9 +14,9 @@ import prometheus_client.core class ResticCollector(object): - def __init__(self, repository, password_file_): + def __init__(self, repository, password_file): self.repository = repository - self.password_file = password_file_ + self.password_file = password_file # todo: the stats cache increases over time -> remove old ids # todo: cold start -> the stats cache could be saved in a persistent volume # todo: cold start -> the restic cache (/root/.cache/restic) could be saved in a persistent volume @@ -212,16 +212,16 @@ if __name__ == "__main__": sys.exit(1) try: - password_file = os.environ["PASSWORD_FILE"] + restic_repo_password_file = os.environ["RESTIC_REPO_PASSWORD_FILE"] except Exception: - logging.error("Configuration error. The environment variable PASSWORD_FILE is mandatory") + logging.error("Configuration error. The environment variable RESTIC_REPO_PASSWORD_FILE is mandatory") sys.exit(1) exporter_address = os.environ.get("LISTEN_ADDRESS", "0.0.0.0") exporter_port = int(os.environ.get("LISTEN_PORT", 8001)) exporter_refresh_interval = int(os.environ.get("REFRESH_INTERVAL", 60)) - collector = ResticCollector(restic_repo_url, password_file) + collector = ResticCollector(restic_repo_url, restic_repo_password_file) prometheus_client.core.REGISTRY.register(collector) prometheus_client.start_http_server(exporter_port, exporter_address)