Add noexec /tmp detection — fall back to /usr/local/src for staging
Scripts auto-detect noexec /tmp by attempting to execute a test script. If /tmp is noexec, staging directory falls back to /usr/local/src. Supports mixed fleets with both noexec and standard /tmp mounts. Updated: deploy-exporter (1.1), install-node-exporter (1.2), install-prometheus-stack (3.2), update-prometheus-stack (1.02), install-snort (1.02), install-ntfy-server (1.1), install-bot-monitor (1.2)
This commit is contained in:
+22
-10
@@ -9,7 +9,7 @@ set -euo pipefail
|
||||
#### Author: Phil Connor ####
|
||||
#### Contact: contact@mylinux.work ####
|
||||
#### License: MIT ####
|
||||
#### Version: 3.1 ####
|
||||
#### Version: 3.2 ####
|
||||
#### ####
|
||||
#### Usage: ./install-prometheus-stack.sh [OPTIONS] ####
|
||||
#############################################################
|
||||
@@ -105,9 +105,21 @@ CONFIG FILE FORMAT:
|
||||
EOF
|
||||
}
|
||||
|
||||
# Detect noexec /tmp — fall back to /usr/local/src
|
||||
STAGE_DIR="/tmp"
|
||||
_exec_test=$(mktemp /tmp/.exec_test.XXXXXX 2>/dev/null)
|
||||
if [[ -n "$_exec_test" ]]; then
|
||||
printf '#!/bin/sh\nexit 0\n' > "$_exec_test"
|
||||
chmod +x "$_exec_test"
|
||||
"$_exec_test" 2>/dev/null || STAGE_DIR="/usr/local/src"
|
||||
rm -f "$_exec_test"
|
||||
else
|
||||
STAGE_DIR="/usr/local/src"
|
||||
fi
|
||||
|
||||
cleanup() {
|
||||
if [[ -d "/tmp/prometheus-install-$$" ]]; then
|
||||
rm -rf "/tmp/prometheus-install-$$"
|
||||
if [[ -d "${STAGE_DIR}/prometheus-install-$$" ]]; then
|
||||
rm -rf "${STAGE_DIR}/prometheus-install-$$"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -262,7 +274,7 @@ install_prometheus() {
|
||||
return
|
||||
fi
|
||||
|
||||
local workdir="/tmp/prometheus-install-$$/prometheus"
|
||||
local workdir="${STAGE_DIR}/prometheus-install-$$/prometheus"
|
||||
mkdir -p "$workdir"
|
||||
cd "$workdir"
|
||||
|
||||
@@ -417,7 +429,7 @@ install_node_exporter() {
|
||||
return
|
||||
fi
|
||||
|
||||
local workdir="/tmp/prometheus-install-$$/node_exporter"
|
||||
local workdir="${STAGE_DIR}/prometheus-install-$$/node_exporter"
|
||||
mkdir -p "$workdir"
|
||||
cd "$workdir"
|
||||
|
||||
@@ -494,7 +506,7 @@ install_blackbox() {
|
||||
return
|
||||
fi
|
||||
|
||||
local workdir="/tmp/prometheus-install-$$/blackbox"
|
||||
local workdir="${STAGE_DIR}/prometheus-install-$$/blackbox"
|
||||
mkdir -p "$workdir"
|
||||
cd "$workdir"
|
||||
|
||||
@@ -686,7 +698,7 @@ install_loki() {
|
||||
return
|
||||
fi
|
||||
|
||||
local workdir="/tmp/prometheus-install-$$/loki"
|
||||
local workdir="${STAGE_DIR}/prometheus-install-$$/loki"
|
||||
mkdir -p "$workdir"
|
||||
cd "$workdir"
|
||||
|
||||
@@ -830,7 +842,7 @@ install_alloy() {
|
||||
return
|
||||
fi
|
||||
|
||||
local workdir="/tmp/prometheus-install-$$/alloy"
|
||||
local workdir="${STAGE_DIR}/prometheus-install-$$/alloy"
|
||||
mkdir -p "$workdir"
|
||||
cd "$workdir"
|
||||
|
||||
@@ -1243,7 +1255,7 @@ install_alertmanager() {
|
||||
return
|
||||
fi
|
||||
|
||||
local workdir="/tmp/prometheus-install-$$/alertmanager"
|
||||
local workdir="${STAGE_DIR}/prometheus-install-$$/alertmanager"
|
||||
mkdir -p "$workdir"
|
||||
cd "$workdir"
|
||||
|
||||
@@ -1337,7 +1349,7 @@ install_mysql_exporter() {
|
||||
return
|
||||
fi
|
||||
|
||||
local workdir="/tmp/prometheus-install-$$/mysql_exporter"
|
||||
local workdir="${STAGE_DIR}/prometheus-install-$$/mysql_exporter"
|
||||
mkdir -p "$workdir"
|
||||
cd "$workdir"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user