From b021c51f2e8a3fb287f85cefb324c62354721a98 Mon Sep 17 00:00:00 2001 From: Tomas Smetana Date: Tue, 4 Sep 2007 11:59:22 +0000 Subject: [PATCH] - fix #271741 - smartd-conf.py should allow customization of parameters - fix #253753 - service starting by default, perhaps shouldn't - update initscript (related #247058 - initscript review) --- smartd-conf.py | 62 ++++++++++-------- smartd.initd | 145 ++++++++++++++++++++++++++++-------------- smartmontools.spec | 7 +- smartmontools.sysconf | 2 + 4 files changed, 140 insertions(+), 76 deletions(-) diff --git a/smartd-conf.py b/smartd-conf.py index e44d011..c7a4d61 100755 --- a/smartd-conf.py +++ b/smartd-conf.py @@ -7,9 +7,9 @@ import dbus class Drive: def __init__(self, bus, device, sysfspath): - self.bus = bus - self.device = device - self.sysfspath = sysfspath + self.bus = bus + self.device = device + self.sysfspath = sysfspath def listDrivesbyHAL(): drives = [] @@ -19,15 +19,15 @@ def listDrivesbyHAL(): storage_udi_list = halm.FindDeviceByCapability('storage') for udi in storage_udi_list: - drive_obj = bus.get_object('org.freedesktop.Hal', udi) - drive = dbus.Interface(drive_obj, 'org.freedesktop.Hal.Device') - storage_bus = drive.GetProperty('storage.bus') - drive_type = drive.GetProperty('storage.drive_type') - if (storage_bus == 'ide' or storage_bus == 'scsi') and drive_type == 'disk': - device_file = drive.GetProperty('block.device') - sysfs_path = drive.GetProperty('linux.sysfs_path') - drv = Drive(storage_bus, device_file, sysfs_path) - drives += [drv] + drive_obj = bus.get_object('org.freedesktop.Hal', udi) + drive = dbus.Interface(drive_obj, 'org.freedesktop.Hal.Device') + storage_bus = drive.GetProperty('storage.bus') + drive_type = drive.GetProperty('storage.drive_type') + if (storage_bus == 'ide' or storage_bus == 'scsi') and drive_type == 'disk': + device_file = drive.GetProperty('block.device') + sysfs_path = drive.GetProperty('linux.sysfs_path') + drv = Drive(storage_bus, device_file, sysfs_path) + drives += [drv] return drives drives = listDrivesbyHAL() @@ -66,27 +66,35 @@ print """# *SMARTD*AUTOGENERATED* /etc/smartd.conf def getfile(fname): try: - fh = open(fname) + fh = open(fname) line = fh.read().rstrip() - fh.close() + fh.close() except IOError: - line = '' + line = '' return line +try: + execfile('/etc/sysconfig/smartmontools') +except IOError: + pass + for drive in drives: if getfile("%s/removable" % drive.sysfspath) == '0': - driver = '' - comment = '' - if getfile("%s/device/vendor" % drive.sysfspath) == 'ATA': - driver = '-d ata ' - if float(getfile("/sys/module/libata/version")) < 1.20: - comment = "# not yet supported in this kernel version\n# " - if not comment: - status = os.system("/usr/sbin/smartctl -s on -i %s%s 2>&1 >/dev/null" % - (driver, drive.device)) - if not os.WIFEXITED(status) or os.WEXITSTATUS(status) != 0: - comment = "# smartctl -i returns error for this drive\n# " - print "%s%s %s-H -m root" % (comment, drive.device, driver) + driver = '' + comment = '' + if getfile("%s/device/vendor" % drive.sysfspath) == 'ATA': + driver = '-d ata' + if float(getfile("/sys/module/libata/version")) < 1.20: + comment = "# not yet supported in this kernel version\n# " + if not comment: + status = os.system("/usr/sbin/smartctl -s on -i %s%s 2>&1 >/dev/null" % + (driver, drive.device)) + if not os.WIFEXITED(status) or os.WEXITSTATUS(status) != 0: + comment = "# smartctl -i returns error for this drive\n# " + try: + print "%s%s %s %s" % (comment, drive.device, driver, smartd_conf_opts) + except NameError: + print "%s%s %s -H -m root" % (comment, drive.device, driver) print """ # First two SCSI disks. This will monitor everything that smartd can diff --git a/smartd.initd b/smartd.initd index 99a131c..ae7f81e 100644 --- a/smartd.initd +++ b/smartd.initd @@ -2,13 +2,23 @@ # smartmontools init file for smartd # Copyright (C) 2002-4 Bruce Allen -# $Id: smartd.initd,v 1.5 2007/06/21 13:26:38 tsmetana Exp $ +# $Id: smartd.initd,v 1.6 2007/09/04 11:59:22 tsmetana Exp $ # For RedHat and cousins: -# chkconfig: 2345 99 01 +# chkconfig: - 99 01 # description: Self Monitoring and Reporting Technology (SMART) Daemon # processname: smartd +### BEGIN INIT INFO +# Provides: smartd +# Required-Start: $local_fs $network +# Required-Stop: $local_fs $network +# Should-Start: +# Short-Description: Self Monitoring and Reporting Technology (SMART) Daemon +# Description: The smartd daemon monitors SMART status of the local hard drives and +# provides advanced warnings of of disk degradation or failures. +### END INIT INFO + # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2, or (at your option) any later @@ -33,59 +43,98 @@ SMARTD_BIN=/usr/sbin/smartd [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools +RETVAL=0 +prog=smartd +pidfile=/var/lock/subsys/smartd + +genconfig() +{ + if [ -x /usr/sbin/smartd-conf.py ]; then + GEN_CONF="*SMARTD*AUTOGENERATED*" + [ ! -f /etc/smartd.conf ] || read DUMMY GEN_CONF DUMMY /dev/null >/etc/smartd.conf.new-autogenerated \ + && mv -f /etc/smartd.conf.new-autogenerated /etc/smartd.conf + fi +} + +start() +{ + echo -n $"Starting $prog: " + daemon $SMARTD_BIN $smartd_opts + RETVAL=$? + echo + [ $RETVAL = 0 ] && touch $pidfile + return $RETVAL +} + +stop() +{ + echo -n $"Shutting down $prog: " + killproc $SMARTD_BIN + RETVAL=$? + echo + rm -f $pidfile + return $RETVAL +} + +reload() +{ + echo -n $"Reloading $prog daemon configuration: " + killproc $SMARTD_BIN -HUP + RETVAL=$? + echo + return $RETVAL +} + +report() +{ + echo -n $"Checking SMART devices now: " + killproc $SMARTD_BIN -USR1 + RETVAL=$? + echo + return $RETVAL +} + case "$1" in - start | reload | restart) - if [ -x /usr/sbin/smartd-conf.py ]; then - GEN_CONF="*SMARTD*AUTOGENERATED*" - [ ! -f /etc/smartd.conf ] || read DUMMY GEN_CONF DUMMY /dev/null >/etc/smartd.conf.new-autogenerated \ - && mv -f /etc/smartd.conf.new-autogenerated /etc/smartd.conf - fi - ;; -esac - - RETVAL=0 - - prog=smartd - - case "$1" in start) - echo -n $"Starting $prog: " - daemon $SMARTD_BIN $smartd_opts - touch /var/lock/subsys/smartd - echo - exit 0 - ;; + genconfig + start + ;; stop) - echo -n $"Shutting down $prog: " - killproc $SMARTD_BIN - rm -f /var/lock/subsys/smartd - echo - ;; + stop + ;; reload) - echo -n $"Reloading $prog daemon configuration: " - killproc $SMARTD_BIN -HUP - RETVAL=$? - echo - ;; + genconfig + reload + ;; report) - echo -n $"Checking SMART devices now: " - killproc $SMARTD_BIN -USR1 - RETVAL=$? - echo - ;; + report + ;; restart) - $0 stop - $0 start - ;; + stop + genconfig + start + ;; + try-restart) + if [ -f $pidfile ]; then + stop + genconfig + start + fi + ;; + force-reload) + genconfig + reload || (stop; start) + ;; status) - status $prog - ;; + status $prog + RETVAL=$? + ;; *) - echo $"Usage: $0 {start|stop|reload|report|restart|status}" - RETVAL=1 - esac + echo $"Usage: $0 {start|stop|reload|force-reload|report|restart|try-restart|status}" + RETVAL=3 +esac - exit $RETVAL +exit $RETVAL diff --git a/smartmontools.spec b/smartmontools.spec index 8089a65..b96f980 100644 --- a/smartmontools.spec +++ b/smartmontools.spec @@ -1,7 +1,7 @@ Summary: Tools for monitoring SMART capable hard disks Name: smartmontools Version: 5.37 -Release: 5%{?dist} +Release: 6%{?dist} Epoch: 1 Group: System Environment/Base License: GPLv2+ @@ -91,6 +91,11 @@ exit 0 %exclude %{_sbindir}/smartd-conf.py[co] %changelog +* Tue Sep 04 2007 Tomas Smetana - 1:5.37-6 +- fix #271741 - smartd-conf.py should allow customization of parameters +- fix #253753 - service starting by default, perhaps shouldn't +- update initscript (related #247058 - initscript review) + * Mon Aug 20 2007 Tomas Smetana - 1:5.37-5 - add support for 24 disks on 3ware RAID controllers (related #252055) - fix #245442 - add %%{arm} to smartmontools's set of build archs diff --git a/smartmontools.sysconf b/smartmontools.sysconf index 066fc3b..75d591c 100644 --- a/smartmontools.sysconf +++ b/smartmontools.sysconf @@ -1,2 +1,4 @@ # command line options for smartd smartd_opts="-q never" +# autogenerated config file options +# smartd_conf_opts="-H -m root"