From fc55f479fa94466d99c1b114fe784729220b5de3 Mon Sep 17 00:00:00 2001 From: jblu Date: Fri, 16 Jun 2023 02:11:08 -0500 Subject: [PATCH] initial commit --- .dockerignore | 3 +++ .drone.yml | 18 ++++++++++++++++++ .gitignore | 1 + Dockerfile | 6 ++++++ crontab | 1 + entrypoint.sh | 5 +++++ phc.sh | 15 +++++++++++++++ 7 files changed, 49 insertions(+) create mode 100644 .dockerignore create mode 100644 .drone.yml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 crontab create mode 100644 entrypoint.sh create mode 100644 phc.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..480d2b1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +*.env +*.md +*drone* \ No newline at end of file diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..13dc29a --- /dev/null +++ b/.drone.yml @@ -0,0 +1,18 @@ +kind: pipeline +name: default + +steps: +- name: docker + image: plugins/docker + settings: + registry: git.jbranan.com + dry_run: false + username: jblu + password: + from_secret: gittea_drone + repo: git.jbranan.com/jblu/phc + tags: + - latest + when: + branch: + - main \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f509e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9b2cab4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +from alpine:latest +RUN apk add --no-cache curl +COPY . opt +RUN crontab /opt/crontab +RUN chmod +x /opt/entrypoint.sh +CMD ["/opt/entrypoint.sh"] \ No newline at end of file diff --git a/crontab b/crontab new file mode 100644 index 0000000..2cbb225 --- /dev/null +++ b/crontab @@ -0,0 +1 @@ +*/30 * * * * . /etc/environment; bash /opt/phc.sh >> /logfile \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..ca10c91 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +printenv | grep -v "no_proxy" >> /etc/environment + +crond -f \ No newline at end of file diff --git a/phc.sh b/phc.sh new file mode 100644 index 0000000..56cb2d8 --- /dev/null +++ b/phc.sh @@ -0,0 +1,15 @@ +: "${PHC_PLEX_SECRET_TOKEN:?Must set PHC_SECRET_TOKEN env variable}" +: "${PHC_HEALTHCHECK_URL:?Must set PHC_HEALTHCHECK_URL env variable}" +: "${PHC_HEALTHCHECK_ID:?Must set PHC_HEALTHCHECK_ID env variable}" +: "${PHC_PLEX_HOST:?Must set PHC_PLEX_HOST env variable}" +: "${PHC_PLEX_PORT:-32400}" +: "${PHC_PLEX_PROTOCOL:-"http"}" + +URL="${PHC_PLEX_PROTOCOL}://${PHC_PLEX_HOST}:${PHC_PLEX_PORT}/connections?X-Plex-Token=${PHC_PLEX_SECRET_TOKEN}" + +ping_hc() { + curl -fsS -m 10 --retry 5 -o /dev/null --data-raw "$2" "${PHC_HEALTHCHECK_URL}/ping/${PHC_HEALTHCHECK_ID}/$1" +} + +connections=$(set -x; { wget --no-check-certificate -nv -O - "$URL"; } 2>&1) +ping_hc "$?" "$connections" \ No newline at end of file