diff options
Diffstat (limited to 'systems/monitoring-1/monitoring')
-rw-r--r-- | systems/monitoring-1/monitoring/Dockerfile | 35 | ||||
-rw-r--r-- | systems/monitoring-1/monitoring/docker-compose.yml | 15 | ||||
-rw-r--r-- | systems/monitoring-1/monitoring/env.example | 5 | ||||
-rw-r--r-- | systems/monitoring-1/monitoring/run.sh | 47 |
4 files changed, 102 insertions, 0 deletions
diff --git a/systems/monitoring-1/monitoring/Dockerfile b/systems/monitoring-1/monitoring/Dockerfile new file mode 100644 index 0000000..4bbf01b --- /dev/null +++ b/systems/monitoring-1/monitoring/Dockerfile | |||
@@ -0,0 +1,35 @@ | |||
1 | FROM debian:bookworm | ||
2 | |||
3 | ARG namespace | ||
4 | |||
5 | RUN \ | ||
6 | apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ | ||
7 | curl \ | ||
8 | gnupg | ||
9 | |||
10 | RUN \ | ||
11 | curl -s "https://build.opensuse.org/projects/home:naemon/signing_keys/download?kind=gpg" | gpg --dearmor > /usr/share/keyrings/naemon.gpg \ | ||
12 | && echo "deb [signed-by=/usr/share/keyrings/naemon.gpg] https://download.opensuse.org/repositories/home:/naemon/Debian_12/ ./" >> /etc/apt/sources.list.d/naemon-stable.list | ||
13 | |||
14 | # Install the baseline packages for this image. Note, these | ||
15 | # packages are not version controlled and may change between | ||
16 | # builds. | ||
17 | RUN apt-get update && \ | ||
18 | DEBIAN_FRONTEND=noninteractive \ | ||
19 | # La liste des packages debian à installer est directement fournie par Immae | ||
20 | apt-get install -y $(curl https://status.immae.eu/$namespace/debian-packages) | ||
21 | |||
22 | # Perform the data directory initialization | ||
23 | RUN mkdir -p /data/var/log/naemon \ | ||
24 | && rm -rf /var/log/naemon \ | ||
25 | && ln -s /data/var/log/naemon /var/log/naemon \ | ||
26 | && find /etc/naemon -type f -not -name "naemon.cfg" -delete | ||
27 | |||
28 | # Add the bootstrap script | ||
29 | RUN curl https://status.immae.eu/common/run.sh > /run.sh | ||
30 | RUN chmod 755 /run.sh | ||
31 | |||
32 | # All data is stored on the root data volme | ||
33 | VOLUME ["/data"] | ||
34 | |||
35 | ENTRYPOINT ["/run.sh"] | ||
diff --git a/systems/monitoring-1/monitoring/docker-compose.yml b/systems/monitoring-1/monitoring/docker-compose.yml new file mode 100644 index 0000000..b369463 --- /dev/null +++ b/systems/monitoring-1/monitoring/docker-compose.yml | |||
@@ -0,0 +1,15 @@ | |||
1 | services: | ||
2 | naemon: | ||
3 | build: | ||
4 | context: https://status.immae.eu/common/Dockerfile | ||
5 | args: | ||
6 | - namespace=${NAMESPACE} | ||
7 | container_name: naemon | ||
8 | restart: unless-stopped | ||
9 | environment: | ||
10 | - NOTIFY_REMOTE_TOKEN=${NOTIFY_REMOTE_TOKEN} | ||
11 | - NAMESPACE=${NAMESPACE} | ||
12 | pid: host | ||
13 | network_mode: host | ||
14 | volumes: | ||
15 | - ./data/log:/data/var/log/naemon | ||
diff --git a/systems/monitoring-1/monitoring/env.example b/systems/monitoring-1/monitoring/env.example new file mode 100644 index 0000000..bace5a5 --- /dev/null +++ b/systems/monitoring-1/monitoring/env.example | |||
@@ -0,0 +1,5 @@ | |||
1 | # Les deux variables ci-dessous sont à demander à Immae | ||
2 | # Token pour notifier le serveur distant (immae) | ||
3 | NOTIFY_REMOTE_TOKEN= | ||
4 | # Namespace sur immae.eu | ||
5 | NAMESPACE= | ||
diff --git a/systems/monitoring-1/monitoring/run.sh b/systems/monitoring-1/monitoring/run.sh new file mode 100644 index 0000000..9a57990 --- /dev/null +++ b/systems/monitoring-1/monitoring/run.sh | |||
@@ -0,0 +1,47 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | function graceful_exit(){ | ||
4 | # Note, "service naemon stop" does not work in the phusion image | ||
5 | # We just kill the process rather than chase this down. | ||
6 | pkill naemon | ||
7 | exit $1 | ||
8 | } | ||
9 | |||
10 | # Recup fichiers Ismael | ||
11 | if [ -n "$NAMESPACE" ]; then | ||
12 | echo "Namespace: $NAMESPACE" | ||
13 | else | ||
14 | echo "Le namespace n'a pas été défini dans \$NAMESPACE." | ||
15 | exit 1 | ||
16 | fi | ||
17 | |||
18 | curl -o /etc/naemon/conf.d/objects.cfg "https://status.immae.eu/$NAMESPACE/objects.conf" | ||
19 | curl -o /etc/naemon/module-conf.d/immae.cfg "https://status.immae.eu/common/immae.cfg" | ||
20 | curl -o /etc/naemon/resource.cfg "https://status.immae.eu/common/resource.cfg" | ||
21 | |||
22 | curl "https://status.immae.eu/$NAMESPACE/plugins.tar" | tar -C /etc/naemon -x | ||
23 | |||
24 | sed -i -e "s|@@COMMON_PLUGINS@@|/usr/lib/naemon/plugins|" \ | ||
25 | -e "s|@@IMMAE_PLUGINS@@|/etc/naemon/immae_plugins/|" \ | ||
26 | -e "s|@@TOKEN@@|$NOTIFY_REMOTE_TOKEN|" \ | ||
27 | /etc/naemon/resource.cfg | ||
28 | |||
29 | # Ensure consistent ownership for the data volume, even if the | ||
30 | # UID/GID's changes | ||
31 | chown -R naemon:naemon /etc/naemon /data/var/log/naemon | ||
32 | |||
33 | # Start the services | ||
34 | service naemon start | ||
35 | |||
36 | # Trap exit signals and do a proper shutdown | ||
37 | trap "graceful_exit 0;" SIGINT SIGTERM | ||
38 | |||
39 | sleep 5 | ||
40 | while true | ||
41 | do | ||
42 | if ! [ -d "/proc/$(cat /var/run/naemon/naemon.pid)" ]; then | ||
43 | echo "Naemon no longer running" | ||
44 | graceful_exit 1 | ||
45 | fi | ||
46 | sleep 1 | ||
47 | done | ||