#!/bin/bash # Prometheus install hooks — drop the prometheus.yml template alongside the # compose, and 0777 the storage dirs so the container can write its TSDB # regardless of the host UID mapping. prometheus_install_post_compose() { local app_name="$1" local result result=$(createFolders "loud" $docker_install_user "$(appDir "$app_name")/$app_name") checkSuccess "Created $app_name folder in $app_name" result=$(createTouch "$(appDir "$app_name")/$app_name/$app_name.yml" $docker_install_user) checkSuccess "Created $app_name.yml file for $app_name" result=$(copyResource "$app_name" "$app_name.yml" "$app_name" | runInstallWrite -a "$logs_dir/$docker_log_file" 2>&1) checkSuccess "Copying $app_name.yml to containers folder." } prometheus_install_post_start() { local app_name="$1" if [ -f "$(appDir prometheus)/prometheus/prometheus.yml" ]; then updateFileOwnership "$(appDir prometheus)/prometheus/prometheus.yml" $docker_install_user $docker_install_user fi # Prometheus runs as nobody (65534) inside the container, which rootless maps # to a subuid outside this user's authority (65534 -> 296605 here). Two # different needs, and the old blanket `chmod -R 777` on both got the second # one wrong: # # prometheus/ config, READ-only to the container. a+rX is enough — world # WRITE on a config the container obeys is not something to # hand out, and -R is safe here because nothing but LibrePortal # writes this dir. go-w is included so the fix actually lands on # installs the old 777 already touched: a+rX only ADDS bits, so # without it every existing prometheus.yml stays world-writable # by any local user. Everything here is written through # runFileOp — i.e. by the owner — so owner-write is all it needs. # # prom_data/ the container's own store. It needs write on the DIRECTORY to # create prom_data/data on first boot; everything under that is # created by, and belongs to, prometheus itself. Recursing into # it meant chmod'ing files owned by 296605 as the docker install # user: "Operation not permitted" per file and a failed step on # every REINSTALL (a fresh install passed only because the dir # was still empty). Those files must keep prometheus's ownership # anyway — that is what lets it write them. if [ -d "$(appDir prometheus)/prometheus" ]; then local result result=$(runFileOp chmod -R a+rX,go-w "$(appDir prometheus)/prometheus") checkSuccess "Set permissions to prometheus folder." fi if [ -d "$(appDir prometheus)/prom_data" ]; then local result result=$(runFileOp chmod 0777 "$(appDir prometheus)/prom_data") checkSuccess "Set permissions to prom_data folder." fi }