Changes for tests identified by CodeRabbit

This commit is contained in:
Adam Outler
2025-10-26 15:30:03 +00:00
parent fb02774814
commit d2c28f6a28
14 changed files with 157 additions and 171 deletions

View File

@@ -34,7 +34,6 @@ warn_if_not_persistent_mount "${NETALERTX_API}" "API JSON cache" || failures=$((
warn_if_not_persistent_mount "${SYSTEM_SERVICES_RUN}" "Runtime work directory" || failures=$((failures + 1))
if [ "${failures}" -ne 0 ]; then
sleep 5
exit 1
fi

View File

@@ -1,37 +1,38 @@
#!/bin/sh
# check-storage.sh - Verify critical paths are persistent mounts.
# Get the Device ID of the root filesystem (overlayfs/tmpfs)
# The default, non-persistent container root will have a unique Device ID.
# Persistent mounts will have a different Device ID (unless it's a bind mount
# from the host's root, which is a rare and unusual setup for a single volume check).
ROOT_DEV_ID=$(stat -c '%d' /)
# Define non-persistent filesystem types to check against
# NOTE: 'overlay' and 'aufs' are the primary non-persistent types for container roots.
# 'tmpfs' and 'ramfs' are for specific non-persistent mounts.
NON_PERSISTENT_FSTYPES="tmpfs|ramfs|overlay|aufs"
MANDATORY_PERSISTENT_PATHS="/app/db /app/config"
# This function is now the robust persistence checker.
is_persistent_mount() {
target_path="$1"
# Stat the path and get its Device ID
current_dev_id=$(stat -c '%d' "${target_path}")
mount_entry=$(awk -v path="${target_path}" '$2 == path { print $0 }' /proc/mounts)
# If the Device ID of the target is *different* from the root's Device ID,
# it means it resides on a separate filesystem, implying a mount.
if [ "${current_dev_id}" != "${ROOT_DEV_ID}" ]; then
return 0 # Persistent (different filesystem/device ID)
if [ -z "${mount_entry}" ]; then
# CRITICAL FIX: If the mount entry is empty, check if it's one of the mandatory paths.
if echo "${MANDATORY_PERSISTENT_PATHS}" | grep -w -q "${target_path}"; then
# The path is mandatory but not mounted: FAIL (Not persistent)
return 1
else
# Not mandatory and not a mount point: Assume persistence is inherited from parent (pass)
return 0
fi
fi
# Fallback to check if it's the root directory itself (which is always mounted)
if [ "${target_path}" = "/" ]; then
return 0
# ... (rest of the original logic remains the same for explicit mounts)
fs_type=$(echo "${mount_entry}" | awk '{print $3}')
# Check if the filesystem type matches any non-persistent types
if echo "${fs_type}" | grep -E -q "^(${NON_PERSISTENT_FSTYPES})$"; then
return 1 # Not persistent (matched a non-persistent type)
else
return 0 # Persistent
fi
# Check parent directory recursively
parent_dir=$(dirname "${target_path}")
if [ "${parent_dir}" != "${target_path}" ]; then
is_persistent_mount "${parent_dir}"
return $?
fi
return 1 # Not persistent
}
warn_if_not_persistent_mount() {
@@ -41,8 +42,6 @@ warn_if_not_persistent_mount() {
return 0
fi
# ... (Your existing warning message block remains unchanged) ...
failures=1
YELLOW=$(printf '\033[1;33m')
RESET=$(printf '\033[0m')
@@ -52,8 +51,7 @@ warn_if_not_persistent_mount() {
⚠️ ATTENTION: ${path} is not a persistent mount.
Your data in this directory may not persist across container restarts or
upgrades. To ensure your settings and history are saved, you must mount
this directory as a persistent volume.
upgrades. The filesystem type for this path is identified as non-persistent.
Fix: mount ${path} explicitly as a bind mount or a named volume:
# Bind mount
@@ -82,5 +80,5 @@ warn_if_not_persistent_mount "${NETALERTX_CONFIG}"
if [ "${failures}" -ne 0 ]; then
# We only warn, not exit, as this is not a critical failure
# but the user should be aware of the potential data loss.
sleep 5 # Give user time to read the message
sleep 1 # Give user time to read the message
fi

View File

@@ -42,7 +42,7 @@ warn_if_not_dedicated_mount "${NETALERTX_API}"
warn_if_not_dedicated_mount "${NETALERTX_LOG}"
if [ ! -L "${SYSTEM_NGINX_CONFIG}/conf.active" ]; then
echo "Note: Using default listen address ${LISTEN_ADDR}:${PORT} (no ${SYSTEM_NGINX_CONFIG}/conf.active override)."
if [ ! -w "${SYSTEM_NGINX_CONFIG}/conf.active" ]; then
echo "Note: Using default listen address 0.0.0.0:20211 instead of ${LISTEN_ADDR}:${PORT} (no ${SYSTEM_NGINX_CONFIG}/conf.active override)."
fi
exit 0

View File

@@ -29,7 +29,6 @@ if [ "${CURRENT_UID}" -eq 0 ]; then
══════════════════════════════════════════════════════════════════════════════
EOF
>&2 printf "%s" "${RESET}"
sleep 5 # Give user time to read the message
exit 1
fi

View File

@@ -39,5 +39,3 @@ RESET=$(printf '\033[0m')
══════════════════════════════════════════════════════════════════════════════
EOF
>&2 printf "%s" "${RESET}"
sleep 5 # Give user time to read the message
exit 0

View File

@@ -19,7 +19,7 @@ TEMP_FILE="/services/run/tmp/ieee-oui.txt.tmp"
OUTPUT_FILE="/services/run/tmp/ieee-oui.txt"
# Download the file using wget to stdout and process it
if ! wget --timeout=30 --tries=3 "https://standards-oui.ieee.org/oui/oui.txt" -O /dev/stdout | \
if ! wget --timeout=30 --tries=3 "https://standards-oui.ieee.org/oui/oui.txt" -O /dev/stdout 2>/dev/null | \
sed -E 's/ *\(base 16\)//' | \
awk -F' ' '{printf "%s\t%s\n", $1, substr($0, index($0, $2))}' | \
sort | \