From 5acda3eaeabae9045609539303a8c12c4ce401f1 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 25 Apr 2016 12:01:08 +0200 Subject: merge with latest dev version --- .../smartctl/data/etc/cron.d/openslx-smartctl | 8 ++++++ .../system/basic.target.wants/smartctl.service | 1 + .../data/etc/systemd/system/smartctl.service | 8 ++++++ .../data/opt/openslx/scripts/systemd-smartctl | 33 ++++++++++++++++++++++ core/modules/smartctl/module.build | 13 +++++++++ core/modules/smartctl/module.conf | 5 ++++ core/modules/smartctl/module.conf.centos | 6 ++++ core/modules/smartctl/module.conf.debian | 6 ++++ core/modules/smartctl/module.conf.fedora | 6 ++++ core/modules/smartctl/module.conf.opensuse | 6 ++++ core/modules/smartctl/module.conf.ubuntu | 6 ++++ 11 files changed, 98 insertions(+) create mode 100644 core/modules/smartctl/data/etc/cron.d/openslx-smartctl create mode 120000 core/modules/smartctl/data/etc/systemd/system/basic.target.wants/smartctl.service create mode 100644 core/modules/smartctl/data/etc/systemd/system/smartctl.service create mode 100755 core/modules/smartctl/data/opt/openslx/scripts/systemd-smartctl create mode 100644 core/modules/smartctl/module.build create mode 100644 core/modules/smartctl/module.conf create mode 100644 core/modules/smartctl/module.conf.centos create mode 100644 core/modules/smartctl/module.conf.debian create mode 100644 core/modules/smartctl/module.conf.fedora create mode 100644 core/modules/smartctl/module.conf.opensuse create mode 100644 core/modules/smartctl/module.conf.ubuntu (limited to 'core/modules/smartctl') diff --git a/core/modules/smartctl/data/etc/cron.d/openslx-smartctl b/core/modules/smartctl/data/etc/cron.d/openslx-smartctl new file mode 100644 index 00000000..a895e8db --- /dev/null +++ b/core/modules/smartctl/data/etc/cron.d/openslx-smartctl @@ -0,0 +1,8 @@ +# Check smart values at night. If the machine gets shut down at night, +# this will not trigger, but we check it once on boot anyways. + +SHELL=/bin/ash +PATH=/usr/sbin:/usr/bin:/sbin:/bin:/opt/openslx/sbin:/opt/openslx/bin + +4 4 * * * root /opt/openslx/scripts/systemd-smartctl + diff --git a/core/modules/smartctl/data/etc/systemd/system/basic.target.wants/smartctl.service b/core/modules/smartctl/data/etc/systemd/system/basic.target.wants/smartctl.service new file mode 120000 index 00000000..b0849c0c --- /dev/null +++ b/core/modules/smartctl/data/etc/systemd/system/basic.target.wants/smartctl.service @@ -0,0 +1 @@ +../smartctl.service \ No newline at end of file diff --git a/core/modules/smartctl/data/etc/systemd/system/smartctl.service b/core/modules/smartctl/data/etc/systemd/system/smartctl.service new file mode 100644 index 00000000..ab268cbc --- /dev/null +++ b/core/modules/smartctl/data/etc/systemd/system/smartctl.service @@ -0,0 +1,8 @@ +[Unit] +Description=Check HDD health status + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/opt/openslx/scripts/systemd-smartctl + diff --git a/core/modules/smartctl/data/opt/openslx/scripts/systemd-smartctl b/core/modules/smartctl/data/opt/openslx/scripts/systemd-smartctl new file mode 100755 index 00000000..1eef0a23 --- /dev/null +++ b/core/modules/smartctl/data/opt/openslx/scripts/systemd-smartctl @@ -0,0 +1,33 @@ +#!/bin/ash + +# Check Reallocated_Sector_Ct and Spin_Retry_Count of local disk(s) + +. /opt/openslx/config + +[ -z "$SLX_SMARTCTL_MIN_REALLOC" ] && SLX_SMARTCTL_MIN_REALLOC=0 +FILES= + +for dev in /dev/sd?; do + FILE=$(mktemp) + FILES="$FILES $FILE" + smartctl -H -A -f "brief" "$dev" > "$FILE" || continue # should we report devices where smartctl doesn't work? + # parse + OVERALL=$(grep -o "test result: .*$" "$FILE" | cut -c 14-) + [ "x$OVERALL" = "xPASSED" ] && OVERALL="" + REALLOC=$(grep "^ *5 " "$FILE" | awk '{print $8}') + SPINRETRY_VAL=$(grep "^ *10 " "$FILE" | awk '{print $4}') + SPINRETRY_THR=$(grep "^ *10 " "$FILE" | awk '{print $6}') + # report if applicable + if [ -n "$OVERALL" ]; then + slxlog "smartctl-fail" "Failed HDD: $dev reports health as $OVERALL" "$FILE" + fi + if [ -n "$REALLOC" ] && [ "$REALLOC" -gt "$SLX_SMARTCTL_MIN_REALLOC" ]; then + slxlog "smartctl-realloc" "Failing HDD: $dev has $REALLOC reallocated sectors!" "$FILE" + fi + if [ -n "$SPINRETRY_VAL" ] && [ "$SPINRETRY_VAL" -le "$SPINRETRY_THR" ]; then + slxlog "smartctl-spinretry" "Failing HDD: $dev has bad spin retry count! ($SPINRETRY_VAL/$SPINRETRY_THR)" "$FILE" + fi +done +sleep 2 # give slxlog a little time, as it's running async +[ -n "$FILES" ] && rm -f -- $FILES # list, no "" + diff --git a/core/modules/smartctl/module.build b/core/modules/smartctl/module.build new file mode 100644 index 00000000..435a7b10 --- /dev/null +++ b/core/modules/smartctl/module.build @@ -0,0 +1,13 @@ +fetch_source() { + : +} + +build() { + COPYLIST="list_dpkg_output" + list_packet_files > "$COPYLIST" + tarcopy "$(cat "${COPYLIST}" | sort -u)" "${MODULE_BUILD_DIR}" +} + +post_copy() { + : +} diff --git a/core/modules/smartctl/module.conf b/core/modules/smartctl/module.conf new file mode 100644 index 00000000..9ea1ed03 --- /dev/null +++ b/core/modules/smartctl/module.conf @@ -0,0 +1,5 @@ +REQUIRED_BINARIES=" + smartctl +" +REQUIRED_LIBRARIES="" +REQUIRED_DIRECTORIES="" diff --git a/core/modules/smartctl/module.conf.centos b/core/modules/smartctl/module.conf.centos new file mode 100644 index 00000000..d699f2f0 --- /dev/null +++ b/core/modules/smartctl/module.conf.centos @@ -0,0 +1,6 @@ +REQUIRED_CONTENT_PACKAGES=" + smartmontools +" +REQUIRED_INSTALLED_PACKAGES=" + smartmontools +" diff --git a/core/modules/smartctl/module.conf.debian b/core/modules/smartctl/module.conf.debian new file mode 100644 index 00000000..d699f2f0 --- /dev/null +++ b/core/modules/smartctl/module.conf.debian @@ -0,0 +1,6 @@ +REQUIRED_CONTENT_PACKAGES=" + smartmontools +" +REQUIRED_INSTALLED_PACKAGES=" + smartmontools +" diff --git a/core/modules/smartctl/module.conf.fedora b/core/modules/smartctl/module.conf.fedora new file mode 100644 index 00000000..d699f2f0 --- /dev/null +++ b/core/modules/smartctl/module.conf.fedora @@ -0,0 +1,6 @@ +REQUIRED_CONTENT_PACKAGES=" + smartmontools +" +REQUIRED_INSTALLED_PACKAGES=" + smartmontools +" diff --git a/core/modules/smartctl/module.conf.opensuse b/core/modules/smartctl/module.conf.opensuse new file mode 100644 index 00000000..d699f2f0 --- /dev/null +++ b/core/modules/smartctl/module.conf.opensuse @@ -0,0 +1,6 @@ +REQUIRED_CONTENT_PACKAGES=" + smartmontools +" +REQUIRED_INSTALLED_PACKAGES=" + smartmontools +" diff --git a/core/modules/smartctl/module.conf.ubuntu b/core/modules/smartctl/module.conf.ubuntu new file mode 100644 index 00000000..d699f2f0 --- /dev/null +++ b/core/modules/smartctl/module.conf.ubuntu @@ -0,0 +1,6 @@ +REQUIRED_CONTENT_PACKAGES=" + smartmontools +" +REQUIRED_INSTALLED_PACKAGES=" + smartmontools +" -- cgit v1.2.3-55-g7522