#!/bin/sh #---------------------------------------------------------------------------------------- # /etc/init.d/smartmon - configuration generator script for smartmon # # Creation: 09.02.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. #---------------------------------------------------------------------------------------- # reading eislib . /var/install/include/eislib # reading lsb init functions . /lib/lsb/init-functions smartd_bin=/usr/sbin/smartd smartmon_conf_file=/etc/config.d/smartmon pid_file=/var/run/smartd.pid smartmon_valid_file=/var/smartmon/smartmon_valid crontab_path=/etc/cron/root crontab_file=$crontab_path/smartmon plot_script=/var/install/bin/smartmon-plot . $smartmon_conf_file add_cron_job () { # check for cron directory if [ ! -d $crontab_path ]; then mkdir -p $crontab_path fi # write file ( echo "# Do not edit this file, edit $smartmon_conf_file" echo "# Creation date: `date`" echo "$SMARTMON_PLOT_CRON_SCHEDULE $plot_script" ) > $crontab_file # update crontab file /var/install/config.d/cron >/dev/null 2>&1 } delete_cron_job () { # check for crontab file if [ -f $crontab_file ]; then # delete existing file rm -f $crontab_file # update crontab file /var/install/config.d/cron >/dev/null 2>&1 fi } start_smartd () { log_daemon_msg "Starting S.M.A.R.T. daemon ..." ps -e | grep -w -q smartd if [ $? -eq 0 ]; then log_failure_msg "S.M.A.R.T. daemon is already running." exit 0 else rm -f $pid_file if [ -f $smartmon_valid_file ]; then if /sbin/start-stop-daemon --start --quiet --oknodo --pidfile $pid_file --exec $smartd_bin -- -p $pid_file; then log_end_msg 0 if [ "$SMARTMON_PLOT" = "yes" ]; then add_cron_job else delete_cron_job fi else log_end_msg 1 log_failure_msg "Errors occured while trying to start S.M.A.R.T. daemon." log_failure_msg "Please check /var/log/messages." delete_cron_job fi else log_end_msg 1 log_failure_msg "S.M.A.R.T. daemon not started because of misconfiguration." log_failure_msg "Please check your configuration." delete_cron_job fi fi } stop_smartd () { log_daemon_msg "Stopping S.M.A.R.T. daemon ..." if /sbin/start-stop-daemon --stop --quiet --oknodo --pidfile $pid_file; then log_end_msg 0 delete_cron_job else log_end_msg 1 fi rm -f $pid_file } status_smartd () { pidofproc -p $pid_file $smartd_bin >/dev/null status=$? if [ $status -eq 0 ]; then log_warning_msg "S.M.A.R.T. daemon is running." else log_failure_msg "S.M.A.R.T. daemon is not running." fi exit $status } case $1 in start) start_smartd ;; stop) stop_smartd ;; restart) stop_smartd start_smartd ;; status) status_smartd ;; *) mecho "Usage: $0 {start|stop|status|restart}" ;; esac