feat: add adaptive SMART refresh controls (#96)

This commit is contained in:
Gustavo Rosa
2026-07-24 14:13:17 -04:00
committed by GitHub
parent 27c6a808da
commit ff289e523f
14 changed files with 512 additions and 89 deletions
@@ -8,7 +8,41 @@ fi
project_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
service_name="noctalia-drive-health"
target_user="${SUDO_USER:-${1:-}}"
target_user="${SUDO_USER:-}"
if [[ -z "$target_user" && "${PKEXEC_UID:-}" =~ ^[0-9]+$ ]]; then
target_user="$(id -un "$PKEXEC_UID" 2>/dev/null || true)"
fi
interval_minutes=15
while (($# > 0)); do
case "$1" in
--interval-minutes)
if (($# < 2)); then
echo "--interval-minutes requires a value." >&2
exit 2
fi
interval_minutes="$2"
shift 2
;;
--help)
echo "usage: $0 [--interval-minutes 1-1440] [desktop-user]"
exit 0
;;
*)
if [[ -n "$target_user" ]]; then
echo "Unexpected argument: $1" >&2
exit 2
fi
target_user="$1"
shift
;;
esac
done
if ! [[ "$interval_minutes" =~ ^[0-9]+$ ]] || ((10#$interval_minutes < 1 || 10#$interval_minutes > 1440)); then
echo "Interval must be a whole number of minutes from 1 to 1440." >&2
exit 2
fi
if [[ -z "$target_user" || "$target_user" == root ]] || ! id "$target_user" >/dev/null 2>&1; then
echo "Unable to determine the desktop user. Run with sudo, or pass the username explicitly." >&2
@@ -34,6 +68,15 @@ install -Dm0755 \
install -Dm0755 \
"$project_dir/packaging/smart-action.sh" \
"/usr/local/libexec/$service_name/smart-action.sh"
install -Dm0755 \
"$project_dir/packaging/set-collector-interval.sh" \
"/usr/local/libexec/$service_name/set-collector-interval.sh"
install -Dm0755 \
"$project_dir/packaging/manage-collector.sh" \
"/usr/local/libexec/$service_name/manage-collector.sh"
install -Dm0755 \
"$project_dir/packaging/uninstall-system-collector.sh" \
"/usr/local/libexec/$service_name/uninstall-collector.sh"
install -Dm0644 \
"$rendered_service" \
"/etc/systemd/system/$service_name.service"
@@ -44,6 +87,7 @@ install -Dm0644 \
systemctl daemon-reload
systemctl enable --now "$service_name.timer"
systemctl start "$service_name.service"
/usr/local/libexec/$service_name/set-collector-interval.sh "$interval_minutes"
echo "Installed the read-only SMART collector."
echo "Cache: /run/$service_name/raw.json"
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail
if (( EUID != 0 )); then
echo "Run this command through the administrator authorization dialog." >&2
exit 1
fi
if (($# != 1)) || [[ "$1" != "start" && "$1" != "pause" ]]; then
echo "usage: $0 {start|pause}" >&2
exit 2
fi
service_name="noctalia-drive-health"
case "$1" in
start)
systemctl daemon-reload
systemctl enable --now "$service_name.timer"
systemctl start "$service_name.service"
echo "Started the Noctalia Drive Health collector."
;;
pause)
systemctl disable --now "$service_name.timer"
systemctl stop "$service_name.service"
echo "Paused the Noctalia Drive Health collector."
;;
esac
@@ -3,7 +3,7 @@ Description=Refresh SMART data for Noctalia
[Timer]
OnBootSec=20s
OnUnitActiveSec=30s
OnUnitActiveSec=15min
AccuracySec=5s
Unit=noctalia-drive-health.service
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -euo pipefail
if (( EUID != 0 )); then
echo "Run this command with sudo." >&2
exit 1
fi
if (($# != 1)) || ! [[ "$1" =~ ^[0-9]+$ ]] || ((10#$1 < 1 || 10#$1 > 1440)); then
echo "usage: $0 MINUTES (1-1440)" >&2
exit 2
fi
service_name="noctalia-drive-health"
interval_minutes=$((10#$1))
dropin_dir="/etc/systemd/system/$service_name.timer.d"
dropin_path="$dropin_dir/interval.conf"
temporary=$(mktemp)
trap 'rm -f -- "$temporary"' EXIT
printf '[Timer]\nOnUnitActiveSec=\nOnUnitActiveSec=%smin\n' "$interval_minutes" >"$temporary"
install -d -m0755 "$dropin_dir"
install -m0644 "$temporary" "$dropin_path"
systemctl daemon-reload
systemctl restart "$service_name.timer"
systemctl start "$service_name.service"
echo "Noctalia full SMART refresh interval set to $interval_minutes minute(s)."