mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Changes for tests identified by CodeRabbit
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user