ports/129722: [PATCH] smartmontools ought to have a periodic script

Garrett Wollman wollman at FreeBSD.org
Wed Dec 17 22:00:15 UTC 2008


>Number:         129722
>Category:       ports
>Synopsis:       [PATCH] smartmontools ought to have a periodic script
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 17 22:00:00 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     Garrett Wollman
>Release:        FreeBSD 6.3-RELEASE-p2 i386
>Organization:
none apparent
>Environment:
System: FreeBSD hergotha.csail.mit.edu 6.3-RELEASE-p2 FreeBSD 6.3-RELEASE-p2 #6: Sat Oct 4 15:38:18 EDT 2008 root@:/usr/obj/usr/src/sys/HERGOTHA i386

smartmontools 5.38

>Description:

	It would be very helpful if smartmontools came with a set of
	periodic scripts.  One to show the current status, and perhaps
	another (weekly? monthly?) to run background diagnostics.
	I've implemented a daily script that does something
	reasonable.  By default, it runs "smartctl -H" against a
	user-specified list of devices; if the status returned
	indicates an unhealthy disk, it will run "smartctl -a" to
	provide more information.

>How-To-Repeat:

>Fix:

Index: Makefile
===================================================================
RCS file: /home/ncvs/ports/sysutils/smartmontools/Makefile,v
retrieving revision 1.33
diff -u -r1.33 Makefile
--- Makefile	21 Aug 2008 06:18:27 -0000	1.33
+++ Makefile	17 Dec 2008 20:31:52 -0000
@@ -18,7 +18,7 @@
 GNU_CONFIGURE=	yes
 CONFIGURE_ARGS=	--with-docdir=${DOCSDIR} --enable-sample
 
-SUB_FILES=	pkg-message
+SUB_FILES=	pkg-message smart
 USE_RC_SUBR=	smartd
 
 MAN5=		smartd.conf.5
@@ -28,6 +28,7 @@
 	@${REINPLACE_CMD} -e 's| install-initdDATA | |' ${WRKSRC}/Makefile.in
 
 post-install:
+	${INSTALL_SCRIPT} ${WRKDIR}/smart ${PREFIX}/etc/periodic/daily/smart
 	@${CAT} ${PKGMESSAGE}
 
 .include <bsd.port.mk>
Index: pkg-plist
===================================================================
RCS file: /home/ncvs/ports/sysutils/smartmontools/pkg-plist,v
retrieving revision 1.4
diff -u -r1.4 pkg-plist
--- pkg-plist	6 Jan 2007 20:13:10 -0000	1.4
+++ pkg-plist	17 Dec 2008 20:58:37 -0000
@@ -1,6 +1,7 @@
 @comment $FreeBSD: ports/sysutils/smartmontools/pkg-plist,v 1.4 2007/01/06 20:13:10 pav Exp $
 @unexec /bin/echo "===>" Stopping smartd ...
 @unexec /usr/bin/killall smartd 2>/dev/null || true
+etc/periodic/daily/smart
 etc/smartd.conf.sample
 sbin/smartctl
 sbin/smartd
Index: files/pkg-message.in
===================================================================
RCS file: /home/ncvs/ports/sysutils/smartmontools/files/pkg-message.in,v
retrieving revision 1.1
diff -u -r1.1 pkg-message.in
--- files/pkg-message.in	11 May 2006 17:02:59 -0000	1.1
+++ files/pkg-message.in	17 Dec 2008 21:01:39 -0000
@@ -5,7 +5,12 @@
 	%%PREFIX%%/sbin/smartctl -a /dev/ad0		for first ATA drive
 	%%PREFIX%%/sbin/smartctl -a /dev/da0		for first SCSI drive
 
-To enable monitor of drives, you can use %%PREFIX%%/sbin/smartd
+To include drive health information in your daily status reports,
+add a line like the following to /etc/periodic.conf:
+	daily_status_smart_devices="/dev/ad0 /dev/da0"
+substituting the appropriate device names for your SMART-capable disks.
+
+To enable drive monitoring, you can use %%PREFIX%%/sbin/smartd.
 A sample configuration file has been installed as 
 %%PREFIX%%/etc/smartd.conf.sample
 Copy this file to %%PREFIX%%/etc/smartd.conf and edit appropriately
Index: files/smart.in
===================================================================
RCS file: files/smart.in
diff -N files/smart.in
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ files/smart.in	17 Dec 2008 20:51:22 -0000
@@ -0,0 +1,52 @@
+#!/bin/sh
+# This script is in the public domain.  Original author: Garrett Wollman
+#
+# $FreeBSD$
+#
+
+if [ -r /etc/defaults/periodic.conf ]; then
+    . /etc/defaults/periodic.conf
+    source_periodic_confs
+fi
+
+smartctl=%%PREFIX%%/sbin/smartctl
+: ${daily_status_smartctl_flags="-H"}
+: ${daily_status_smartctl_extra_status_flags="-a"}
+# no default for ${daily_status_smart_devices}
+if [ -z "${daily_status_smart_devices}" ]; then
+	: ${daily_status_smart_enabled="NO"}
+else
+	: ${daily_status_smart_enabled="YES"}
+fi
+trim_junk="tail -n +4"
+
+tmpfile="$(mktemp /var/run/daily.XXXXXXXX)"
+trap "rm -f ${tmpfile}" 0 1 3 15
+
+rc=0
+case "${daily_status_smart_enable}" in
+	[Nn][Oo])
+		;;
+	*)
+		for device in ${daily_status_smart_devices}; do
+			if [ -e ${device} ]; then
+				echo 
+				echo "Checking health of ${device}:"
+				echo
+				${smartctl} ${daily_status_smartctl_flags} ${device} > "${tmpfile}"
+				status=$?
+				if [ $((status & 3)) -ne 0 ]; then
+					rc=2
+					${trim_junk} "${tmpfile}"
+				elif [ $status -ne 0 ]; then
+					rc=1
+					${smartctl} ${daily_status_smartctl_extra_status_flags} ${device} | ${trim_junk}
+				else
+					${trim_junk} "${tmpfile}"
+				fi
+			fi
+		done
+		;;
+esac
+
+exit "$rc"
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list