Adding the smartd service to SME server

It is interesting to monitor the hard drives of your Linux server for possible problems.

The smartd package allows you to monitor the SMART parameters of any drive attached to your system. In case things are going wrong, smartd will warn you by email and chances are that you will be able to gracefully shut down the system.

Enabling the smartd service on SME Server (tested on 7.0pre3) is easy, since the package is already installed by default.

You only need to configure it, and to add it to the list of known services.

Adding the smartd service to the configuration database

All settings on the SME server are stored in a central database. You'll have to add the smartd service first

This is done through the following commands:

     /sbin/e-smith/db configuration set smartd service
     /sbin/e-smith/db configuration setprop smartd status enabled
     /sbin/e-smith/db configuration setprop smartd mailrecipient '<your_mail_address>'

Verify that everything went fine with:

    /sbin/e-smith/db configuration show smartd

this should return:

smartd=service
    mailrecipient=<your_mail_address>
    status=enabled

Configuring smartd

Settings for the smart daemon are passed through the configuration file '/etc/smartd.conf'.

Since SME uses a template system for the configuration files, you first have to create such a template in '/etc/e-smith/templates-custom/etc/smartd.conf'.

Add the following content:

{
my $recipient = $smartd{mailrecipient} || 'root@localhost';
"/dev/hda -H \\                          # check disk health
         -m $recipient \\ # be sure to mail me
         -l selftest     \\             # report failed selftest
         -l error        \\             # report increased error counts
         -s (L/../../7/00|S/../.././01) \\             # Run a long test on sunday (00h) and a short test every day (01h)
         -t                            # Report prefail and end-of-life"
}

Using the following example file, the hard drive /dev/hda is monitored. Once a day, a quick self-test is performed, and once a week (on sundays) a full test is done.

Now, create the actual configuration file with:

     /sbin/e-smith/expand-template /etc/smartd.conf

Verify that the file is correctly created.

Finally, add the service to the list of services that are automatically started at system boot:

     cd /etc/rc7.d
     ln -s /etc/rc.d/init.d/e-smith-service S99smartd

And check if the service starts with:

    ./S99smartd start

Make sure the configuration and startup script survive a backup

If system backups are created using the backup2 panel, the files that were just added can be automatically expanded in case of a system restore.

Make sure the smartd.conf is restored with a console-save event:

    cd /etc/e-smith/events/console-save/templates2expand/etc
    touch smartd.conf

Make sure the startup link is restored:

    cd /etc/e-smith/events/actions/
    touch restore_smartd_initscript

Add the following contents to restore_smartd_initscript

    if [ ! -e /etc/rc7.d/S99smartd ]
    then
       ln -s /etc/rc.d/init.d/e-smith-service /etc/rc7.d/S99smartd
    fi

Finally, add a link to this script file from the console-save folder

    cd /etc/e-smith/events/console-save/
    ln -s ../actions/restore_smartd_initscript S99restore_smartd_initscript

 

Thanks

to Ralf Simon for fixing an error in the scheduling section of the smartd.conf file.