#!/bin/sh #---------------------------------------------------------------------------- # /var/install/config.d/smartmon.sh - configuration generator script for smartmon # # Creation: 01.01.2004 jb # Last Update: $Id$ # # Copyright (c) 2004-2009 Jens Berger # # 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 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- config_file=/etc/config.d/smartmon smartd_config_file=/etc/smartd.conf smartmon_valid_file=/var/smartmon/smartmon_valid smartmon_device_list=/var/smartmon/smartmon_devices_watch smartmon_plot_list=/var/smartmon/smartmon_devices_plot smartmon_warn_attrib=/var/smartmon/smartmon_warn_attributes smartmon_raid_drives=/var/smartmon/smartmon_raid_drives # reading eislib . /var/install/include/eislib # reading lsb init functions . /lib/lsb/init-functions plotting=0 rm -f $smartmon_raid_drives write_device_line () { smartmon_use_device_args="$smartmon_device_args" smartmon_use_config_options="-o on -d removable -n sleep -H -I 194:-t -f -l error -l selftest -s (S/../.././02|L/../../6/03)" smartmon_use_failure_mail_to="-m $SMARTMON_FAILURE_MAIL_TO -M exec /var/install/bin/smartmon-mail" if [ $SMARTMON_STARTUP_TESTMAIL = "yes" ]; then smartmon_use_startup_testmail="-M test" fi ( echo -n "$smartmon_device_name " # NO colon! echo -n "$smartmon_use_driver_options:" if [ "$smartmon_device_override" != "yes" ]; then echo -n "$smartmon_use_config_options:" fi echo -n "$smartmon_use_device_args:" echo -n "$smartmon_use_failure_mail_to:" echo "$smartmon_use_startup_testmail" ) >> $smartmon_device_list } write_plot_list () { if [ "$SMARTMON_PLOT" = "yes" -a "$smartmon_device_plot" = "yes" -a "`grep $smartmon_device_name $smartmon_plot_list`" = "" ]; then plotting=1 if [ -f $smartmon_raid_drives ]; then smartmon_device_raid_drives="`sed 's/,$//g' $smartmon_raid_drives`" else smartmon_device_raid_drives="0" fi echo "$smartmon_device_name:$smartmon_device_type:$smartmon_device_raid_drives:" >>$smartmon_plot_list fi } configure_smartmon () { rm -f $smartd_config_file $smartmon_valid_file $smartmon_device_list $smartmon_plot_list $smartmon_warn_attrib $smartmon_raid_drives . $config_file if [ "$START_SMARTMON" = "yes" ]; then smartmon_errors=0 touch $smartmon_device_list touch $smartmon_plot_list for IDX in `seq 1 $SMARTMON_DEVICE_N`; do eval smartmon_device_active='$SMARTMON_DEVICE_'$IDX'_ACTIVE' eval smartmon_device_type='$SMARTMON_DEVICE_'$IDX'_TYPE' eval smartmon_device_name='$SMARTMON_DEVICE_'$IDX'_NAME' eval smartmon_device_args='$SMARTMON_DEVICE_'$IDX'_ARGS' eval smartmon_device_override='$SMARTMON_DEVICE_'$IDX'_OVERRIDE_DEFAULT' eval smartmon_device_plot='$SMARTMON_DEVICE_'$IDX'_PLOT' eval smartmon_device_warn='$SMARTMON_DEVICE_'$IDX'_WARN_N' device_on_list=`grep ^$smartmon_device_name $smartmon_device_list` naked_device=`echo $smartmon_device_name | sed -e 's/\/dev\///'` # for kernel 2.6.x, /proc/partitions has another output with line endings after partitions device_in_proc_partitions=`cat /proc/partitions | grep -E "[[:space:]]$naked_device([[:space:]]|$)" | awk '{print s$4}'` if [ $smartmon_device_active != "yes" ]; then log_warning_msg "Skipping monitoring for '$smartmon_device_name'" else # newer 3ware controllers (/dev/tw[a|e][0-9]*) seemed to be not listed in /proc/partitions ... # ... so ignore this little extra test for 3ware. if [ "$device_in_proc_partitions" != "$naked_device" -a $smartmon_device_type != "3ware" ]; then log_failure_msg "Drive '$smartmon_device_name' doesn't seem to be a valid device!" smartmon_errors=1 else if [ $smartmon_device_warn -gt 0 ]; then touch $smartmon_warn_attrib for IDXX in `/usr/bin/seq 1 $smartmon_device_warn`; do eval attribute='$SMARTMON_DEVICE_'$IDX'_WARN_'$IDXX'_ATTRIBUTE' eval kind='$SMARTMON_DEVICE_'$IDX'_WARN_'$IDXX'_KIND' eval relation='$SMARTMON_DEVICE_'$IDX'_WARN_'$IDXX'_RELATION' eval threshold='$SMARTMON_DEVICE_'$IDX'_WARN_'$IDXX'_THRESHOLD' echo "$smartmon_device_name:$attribute:$kind:$relation:$threshold:" >> $smartmon_warn_attrib done fi if [ "$device_on_list" = "" ]; then if [ $smartmon_device_type = "3ware" ]; then # we have to check if we have a 32- or a 16-port controller maxports=31 if [ -z "`echo $smartmon_device_name | grep '/dev/tw[a|e]'`" ]; then maxports=15 fi for i in `/usr/bin/seq 0 $maxports`; do /usr/sbin/smartctl -d 3ware,$i -a $smartmon_device_name >/dev/null 2>&1 # to evaluate: return value '2' means disk not present, for all other values generate device line (Juergen Edner) if [ $? != 4 ]; then smartmon_use_driver_options="-d 3ware,$i" echo -n "$i," >> $smartmon_raid_drives write_device_line fi done write_plot_list elif [ $smartmon_device_type = "cciss" ]; then for i in `/usr/bin/seq 0 127`; do /usr/sbin/smartctl -d cciss,$i -a $smartmon_device_name >/dev/null 2>&1 if [ $? -eq 0 ]; then smartmon_use_driver_options="-d cciss,$i" echo -n "$i," >> $smartmon_raid_drives write_device_line fi done elif [ $smartmon_device_type = "scsi" ]; then smartmon_use_driver_options="-d scsi" write_device_line elif [ $smartmon_device_type = "ata" ]; then smartmon_use_driver_options="-d ata" write_device_line write_plot_list elif [ $smartmon_device_type = "sat" ]; then smartmon_use_driver_options="-d sat" write_device_line write_plot_list elif [ $smartmon_device_type = "marvell" ]; then smartmon_use_driver_options="-d marvell" write_device_line write_plot_list fi else log_warning_msg "Drive '$smartmon_device_name' is already marked for monitoring!" smartmon_errors=1 fi fi fi done if [ "$smartmon_errors" = "0" ]; then touch $smartmon_valid_file ( echo "#-------------------------------------------------------------------------------" echo "# smartd configuration file for EIS/FAIR" echo "#" echo "# Do not edit this file. Edit $config_file instead." echo "#" echo "# Creation date: `date`" echo "#-------------------------------------------------------------------------------" # replace : by a \, and a linebreak, and a following indent for next line # smartd will fail if the line length is > 128 cat $smartmon_device_list | sed -e $'s/:/ \\\ \\\n /g' # remove empty lines ) | sed -e '/^ \\ $/d' > $smartd_config_file fi else log_warning_msg "S.M.A.R.T. Monitoring support is disabled." fi } case "$1" in configure) configure_smartmon ;; *) configure_smartmon ;; esac exit 0