6
0
Fork 0

Add __prometheus_borgbackup_exporter type

This commit is contained in:
Timothée Floure 2020-11-20 08:26:02 +01:00
parent e5f5477241
commit ca4f833a56
9 changed files with 137 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 <https://www.borgbackup.org/>`_
- `prometheus-borgbackup-exporter VCS <https://code.recycled.cloud/e-Durable/prometheus-borgbackup-exporter>`_
- `__borg(7)`
- `__borg_repo(7)`
AUTHORS
-------
Timothée Floure <t.floure@e-durable.ch>
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.

View file

@ -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

View file

@ -0,0 +1 @@
/srv/backup

View file

@ -0,0 +1 @@
repos-dir

View file

@ -0,0 +1 @@
version