2011-07-13 19:47:34 +02:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.smartd;
|
|
|
|
|
2011-07-21 21:32:15 +02:00
|
|
|
smartdMail = pkgs.writeScript "smartdmail.sh" ''
|
2011-11-25 18:09:37 +01:00
|
|
|
#! ${pkgs.stdenv.shell}
|
2011-07-21 21:32:15 +02:00
|
|
|
TMPNAM=/tmp/smartd-message.$$.tmp
|
|
|
|
if test -n "$SMARTD_ADDRESS"; then
|
|
|
|
echo >"$TMPNAM" "From: smartd <root>"
|
|
|
|
echo >>"$TMPNAM" 'To: undisclosed-recipients:;'
|
|
|
|
echo >>"$TMPNAM" "Subject: $SMARTD_SUBJECT"
|
|
|
|
echo >>"$TMPNAM"
|
|
|
|
echo >>"$TMPNAM" "Failure on $SMARTD_DEVICESTRING: $SMARTD_FAILTYPE"
|
|
|
|
echo >>"$TMPNAM"
|
|
|
|
cat >>"$TMPNAM"
|
|
|
|
${pkgs.smartmontools}/sbin/smartctl >>"$TMPNAM" -a -d "$SMARTD_DEVICETYPE" "$SMARTD_DEVICE"
|
|
|
|
/var/setuid-wrappers/sendmail <"$TMPNAM" -f "$SENDER" -i "$SMARTD_ADDRESS"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
smartdConf = pkgs.writeText "smartd.conf" (concatMapStrings (device:
|
|
|
|
''
|
2012-10-06 07:02:47 +02:00
|
|
|
${device} -a -m root -M exec ${smartdMail} ${cfg.deviceOpts}
|
2011-07-21 21:32:15 +02:00
|
|
|
''
|
|
|
|
) cfg.devices);
|
|
|
|
|
|
|
|
smartdFlags = if (cfg.devices == []) then "" else "--configfile=${smartdConf}";
|
|
|
|
|
2011-07-13 19:47:34 +02:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.smartd = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
example = "true";
|
|
|
|
description = ''
|
2011-07-21 21:32:15 +02:00
|
|
|
Run smartd from the smartmontools package. Note that e-mail
|
|
|
|
notifications will not be enabled unless you configure the list of
|
|
|
|
devices with <varname>services.smartd.devices</varname> as well.
|
2011-07-13 19:47:34 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2012-10-06 07:02:47 +02:00
|
|
|
deviceOpts = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.string;
|
|
|
|
example = "-o on -s (S/../.././02|L/../../7/04)";
|
|
|
|
description = ''
|
|
|
|
Additional options for each device that is monitored. The example
|
|
|
|
turns on SMART Automatic Offline Testing on startup, and schedules short
|
|
|
|
self-tests daily, and long self-tests weekly.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2011-07-21 21:32:15 +02:00
|
|
|
devices = mkOption {
|
|
|
|
default = [];
|
|
|
|
example = ["/dev/sda" "/dev/sdb"];
|
|
|
|
description = ''
|
|
|
|
List of devices to monitor. By default -- if this list is empty --,
|
|
|
|
smartd will monitor all devices connected to the machine at the time
|
|
|
|
it's being run. Configuring this option has the added benefit of
|
|
|
|
enabling e-mail notifications to "root" every time smartd detects an
|
|
|
|
error.
|
|
|
|
'';
|
|
|
|
};
|
2011-07-13 19:47:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2011-09-14 20:30:10 +02:00
|
|
|
jobs.smartd = {
|
|
|
|
description = "S.M.A.R.T. Daemon";
|
2011-07-13 19:47:34 +02:00
|
|
|
|
2011-08-19 22:44:12 +02:00
|
|
|
environment.TZ = config.time.timeZone;
|
|
|
|
|
2011-07-13 19:47:34 +02:00
|
|
|
startOn = "started syslogd";
|
|
|
|
|
2011-11-25 18:09:44 +01:00
|
|
|
path = [ pkgs.smartmontools ];
|
|
|
|
|
|
|
|
exec = "smartd --no-fork --pidfile=/var/run/smartd.pid ${smartdFlags}";
|
2011-07-13 19:47:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|