diff --git a/type/__prometheus_yoctotemp_exporter/files/prometheus-yoctotemp-exporter.service b/type/__prometheus_yoctotemp_exporter/files/prometheus-yoctotemp-exporter.service new file mode 100644 index 0000000..72c2f76 --- /dev/null +++ b/type/__prometheus_yoctotemp_exporter/files/prometheus-yoctotemp-exporter.service @@ -0,0 +1,12 @@ +[Unit] +Description=Prometheus YoctoTemperature exporter +After=network.target + +[Service] +Type=simple +# FIXME: ugly workaround with potential side effects. +ExecStartPre=/usr/bin/chown -R root:dialout /dev/bus/usb/003 +ExecStart=/opt/prometheus-yoctotemp-exporter/venv/bin/python /opt/prometheus-yoctotemp-exporter/prometheus-yoctotemp-exporter + +[Install] +WantedBy=multi-user.target diff --git a/type/__prometheus_yoctotemp_exporter/gencode-remote b/type/__prometheus_yoctotemp_exporter/gencode-remote new file mode 100755 index 0000000..04cbb7f --- /dev/null +++ b/type/__prometheus_yoctotemp_exporter/gencode-remote @@ -0,0 +1,20 @@ +#!/bin/sh + +VCS_TAG=$(cat "$__object/parameter/version") +VCS_URL="https://code.recycled.cloud/e-Durable/prometheus-yoctotemp-exporter/raw/tag/$VCS_TAG/prometheus-yoctotemp-exporter" + +cat << EOF +cd /opt/prometheus-yoctotemp-exporter + +# Fetch sources. +curl "$VCS_URL" -o prometheus-yoctotemp-exporter + +# Install virtualenv and dependencies. +virtualenv venv +. venv/bin/activate +pip install prometheus_client +pip install yoctopuce + +# Start service +service prometheus-yoctotemp-exporter start +EOF diff --git a/type/__prometheus_yoctotemp_exporter/man.rst b/type/__prometheus_yoctotemp_exporter/man.rst new file mode 100644 index 0000000..e734e7a --- /dev/null +++ b/type/__prometheus_yoctotemp_exporter/man.rst @@ -0,0 +1,57 @@ +cdist-type__prometheus_yoctotemp_exporter(7) +===================== + +NAME +---- +cdist-type__prometheus_yoctotemp_exporter - Deploy a Prometheus exporter for the YoctoTemperature sensor + + +DESCRIPTION +----------- +This (singleton) type deploys a Prometheus exporter for the YoctoTemperature sensor + +NOTE +---- + +FIXME: this systemd service currently use an ugly hack to deal with +/dev/bus/usb permissions, with potential side effects. udev should be used +instead. + +REQUIRED PARAMETERS +------------------- +version + Release tag used to fetch sources from upstream's VCS. + + +OPTIONAL PARAMETERS +------------------- +None. + +BOOLEAN PARAMETERS +------------------ +None. + +EXAMPLES +-------- + +.. code-block:: sh + + __prometheus_yoctotemp_expoter --version v0.1 + + +SEE ALSO +-------- +- `YoctoTemerature sensor `_ +- `prometheus-yoctotemp-exporter VCS `_ + +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_yoctotemp_exporter/manifest b/type/__prometheus_yoctotemp_exporter/manifest new file mode 100644 index 0000000..5b1a292 --- /dev/null +++ b/type/__prometheus_yoctotemp_exporter/manifest @@ -0,0 +1,22 @@ +#!/bin/sh + +os=$(cat "${__global:?}/explorer/os") +case "$os" in + debian|ubuntu) + __package python3-virtualenv + __package curl + ;; +*) + echo "$os is not supported by this type. Exiting" >&2 + exit 1 + ;; +esac + +__directory /opt/prometheus-yoctotemp-exporter + +# Make sure the prometheus user exist and belongs to dialout. +__user prometheus +require="__user/prometheus" __user_groups prometheus --group dialout +__systemd_unit prometheus-yoctotemp-exporter.service \ + --source "$__type/files/prometheus-yoctotemp-exporter.service" \ + --enablement-state enabled diff --git a/type/__prometheus_yoctotemp_exporter/parameter/required b/type/__prometheus_yoctotemp_exporter/parameter/required new file mode 100644 index 0000000..088eda4 --- /dev/null +++ b/type/__prometheus_yoctotemp_exporter/parameter/required @@ -0,0 +1 @@ +version diff --git a/type/__prometheus_yoctotemp_exporter/singleton b/type/__prometheus_yoctotemp_exporter/singleton new file mode 100644 index 0000000..e69de29