diff --git a/type/__prometheus_borgbackup_exporter/files/prometheus-borgbackup-exporter.service.sh b/type/__prometheus_borgbackup_exporter/files/prometheus-borgbackup-exporter.service.sh new file mode 100755 index 0000000..44f8ca5 --- /dev/null +++ b/type/__prometheus_borgbackup_exporter/files/prometheus-borgbackup-exporter.service.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +cat << EOF +[Unit] +Description=e-Durable's Prometheus Borgbackup exporter +After=network.target + +[Service] +Type=simple +User=borgbackup +ExecStart=/opt/prometheus-borgbackup-exporter/venv/bin/python /opt/prometheus-borgbackup-exporter/prometheus-borgbackup-exporter $REPOS_DIR + +[Install] +WantedBy=multi-user.target +EOF diff --git a/type/__prometheus_borgbackup_exporter/files/prometheus-borgbackup-exporter.sh b/type/__prometheus_borgbackup_exporter/files/prometheus-borgbackup-exporter.sh new file mode 100755 index 0000000..f0d7215 --- /dev/null +++ b/type/__prometheus_borgbackup_exporter/files/prometheus-borgbackup-exporter.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +cat << EOF +#!/sbin/openrc-run + +supervisor="supervise-daemon" +command_user=borgbackup +command="/opt/prometheus-borgbackup-exporter/venv/bin/python /opt/prometheus-borgbackup-exporter/prometheus-borgbackup-exporter $REPOS_DIR" +EOF diff --git a/type/__prometheus_borgbackup_exporter/gencode-remote b/type/__prometheus_borgbackup_exporter/gencode-remote new file mode 100755 index 0000000..7888263 --- /dev/null +++ b/type/__prometheus_borgbackup_exporter/gencode-remote @@ -0,0 +1,20 @@ +#!/bin/sh + +VCS_TAG=$(cat "${__object:?}/parameter/version") +VCS_URL="https://code.recycled.cloud/e-Durable/prometheus-borgbackup-exporter/raw/tag/$VCS_TAG/prometheus-borgbackup-exporter" + +cat << EOF +cd /opt/prometheus-borgbackup-exporter + +# Fetch sources. +curl "$VCS_URL" -o prometheus-borgbackup-exporter + +# Install virtualenv and dependencies. +virtualenv venv +. venv/bin/activate +pip install prometheus_client +pip install dateutils + +# Start service +service prometheus-borgbackup-exporter start +EOF diff --git a/type/__prometheus_borgbackup_exporter/man.rst b/type/__prometheus_borgbackup_exporter/man.rst new file mode 100644 index 0000000..906da45 --- /dev/null +++ b/type/__prometheus_borgbackup_exporter/man.rst @@ -0,0 +1,52 @@ +cdist-type__prometheus_borgbackup_exporter(7) +===================== + +NAME +---- +cdist-type__prometheus_borgbackup_exporter - Deploy a Prometheus exporter for the e-Durable borgbackup server + + +DESCRIPTION +----------- +This (singleton) type deploys a Prometheus exporter for the e-Durable borgbackup exporter + +REQUIRED PARAMETERS +------------------- +version + Release tag used to fetch sources from upstream's VCS. + +OPTIONAL PARAMETERS +------------------- +repos-dir + Directory containing borg repositories to monitor. + +BOOLEAN PARAMETERS +------------------ +None. + +EXAMPLES +-------- + +.. code-block:: sh + + __prometheus_borgbackup_expoter --version v0.1 + + +SEE ALSO +-------- +- `Borgbackup `_ +- `prometheus-borgbackup-exporter VCS `_ +- `__borg(7)` +- `__borg_repo(7)` + +AUTHORS +------- +Timothée Floure + + +COPYING +------- +Copyright \(C) 2020 Timothée Floure. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/type/__prometheus_borgbackup_exporter/manifest b/type/__prometheus_borgbackup_exporter/manifest new file mode 100644 index 0000000..860960c --- /dev/null +++ b/type/__prometheus_borgbackup_exporter/manifest @@ -0,0 +1,38 @@ +#!/bin/sh + +os=$(cat "${__global:?}/explorer/os") + +mkdir -p "${__object:?}/files" +case "$os" in + debian|ubuntu) + __package python3-virtualenv + __package curl + + "${__type:?}/files/prometheus-borgbackup-exporter.service.sh" \ + > "${__object:?}/files/prometheus-borgbackup-exporter.service" + __systemd_unit prometheus-borgbackup-exporter.service \ + --source "${__object:?}/files/prometheus-borgbackup-exporter.service" \ + --enablement-state enabled + ;; + alpine) + __package py3-virtualenv + __package curl + + "${__type:?}/files/prometheus-borgbackup-exporter.sh" \ + > "${__object:?}/files/prometheus-borgbackup-exporter" + __file /etc/init.d/prometheus-borgbackup-exporter \ + --source "${__object:?}/files/prometheus-borgbackup-exporter" \ + --mode 0755 + ;; +*) + echo "$os is not supported by this type. Exiting" >&2 + exit 1 + ;; +esac + +REPOS_DIR=$(cat "${__object:?}/parameter/repos-dir") +export REPOS_DIR +__directory /opt/prometheus-borgbackup-exporter + +# Make sure the borgbackup user exist. +__user borgbackup --home "$REPOS_DIR" --create-home diff --git a/type/__prometheus_borgbackup_exporter/parameter/default/repos-dir b/type/__prometheus_borgbackup_exporter/parameter/default/repos-dir new file mode 100644 index 0000000..2740adc --- /dev/null +++ b/type/__prometheus_borgbackup_exporter/parameter/default/repos-dir @@ -0,0 +1 @@ +/srv/backup diff --git a/type/__prometheus_borgbackup_exporter/parameter/optional b/type/__prometheus_borgbackup_exporter/parameter/optional new file mode 100644 index 0000000..9455928 --- /dev/null +++ b/type/__prometheus_borgbackup_exporter/parameter/optional @@ -0,0 +1 @@ +repos-dir diff --git a/type/__prometheus_borgbackup_exporter/parameter/required b/type/__prometheus_borgbackup_exporter/parameter/required new file mode 100644 index 0000000..088eda4 --- /dev/null +++ b/type/__prometheus_borgbackup_exporter/parameter/required @@ -0,0 +1 @@ +version diff --git a/type/__prometheus_borgbackup_exporter/singleton b/type/__prometheus_borgbackup_exporter/singleton new file mode 100644 index 0000000..e69de29