diff --git a/proxDoc.sh b/proxDoc.sh index c578442..6d3d8a4 100755 --- a/proxDoc.sh +++ b/proxDoc.sh @@ -18,6 +18,8 @@ LOGFILE="${PROXDOC_LOGFILE:-}" ################### # Disk list cache - populated on first use DISK_LIST="" +# Unit files cache - populated on first use +UNIT_FILES="" ################### # Pattern Constants @@ -128,6 +130,20 @@ get_disk_list() { echo "$DISK_LIST" } +# Get systemctl unit files with caching +get_unit_files() { + if [[ -z "$UNIT_FILES" ]]; then + UNIT_FILES=$(systemctl list-unit-files 2>/dev/null) + fi + echo "$UNIT_FILES" +} + +# Check if a unit file exists (uses cached data) +unit_file_exists() { + local unit_name="$1" + get_unit_files | grep -q "$unit_name" +} + # Efficient process wait with optional spinner # Usage: wait_for_process $pid [delay] # Uses kill -0 instead of ps -p for efficiency @@ -531,7 +547,7 @@ get_node_exporter_status() { else log_message warn "Port 9100 not listening" fi - elif systemctl list-unit-files 2>/dev/null | grep -q node_exporter; then + elif unit_file_exists node_exporter; then log_message warn "Node Exporter is installed but not running" echo -e "Start with: systemctl start node_exporter" else @@ -546,7 +562,7 @@ get_hwmon_status() { systemctl list-timers hwmon.timer --no-pager 2>/dev/null echo -e "\n${GREEN}Last Run:${NC}" journalctl -u hwmon.service -n 3 --no-pager 2>/dev/null || true - elif systemctl list-unit-files 2>/dev/null | grep -q hwmon.timer; then + elif unit_file_exists hwmon.timer; then log_message warn "hwmon timer is installed but not active" echo -e "Enable with: systemctl enable --now hwmon.timer" else