mcst-linux-kernel/patches-2024.06.26/smartmontools-7.1/files/smartmontools.init

125 lines
2.9 KiB
Bash

#!/bin/sh -e
#
# smartmontools init.d startup script
#
# (C) 2003,04,07 Guido Günther <agx@sigxcpu.org>
#
# loosely based on the init script that comes with smartmontools which is
# copyrighted 2002 by Bruce Allen <smartmontools-support@lists.sourceforge.net>
#
### BEGIN INIT INFO
# Provides: smartmontools
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: SMART monitoring daemon
### END INIT INFO
SMARTCTL=/usr/sbin/smartctl
DAEMON=/usr/sbin/smartd
PIDFILE=/var/run/smartd.pid
[ -x $SMARTCTL ] || exit 0
[ -x $DAEMON ] || exit 0
#. /lib/lsb/init-functions
. /etc/sysconfig/rc
. ${rc_functions}
RET=0
[ -r /etc/default/smartmontools ] && . /etc/default/smartmontools
smartd_opts="--pidfile $PIDFILE $smartd_opts"
enable_smart() {
boot_mesg "Enabling S.M.A.R.T." ${NORMAL}
for device in $enable_smart; do
echo -n "$device: "
if ! $SMARTCTL --quietmode=errorsonly --smart=on $device; then
echo "(failed)"
RET=2
fi
done
echo_ok
}
running_pid()
{
# Check if a given process pid's cmdline matches a given name
pid=$1
name=$2
[ -z "$pid" ] && return 1
[ ! -d /proc/$pid ] && return 1
cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
# Is this the expected child?
[ "$cmd" != "$name" ] && return 1
return 0
}
running()
{
# Check if the process is running looking at /proc
# (works for all users)
# No pidfile, probably no daemon present
[ ! -f "$PIDFILE" ] && return 1
# Obtain the pid and check it against the binary name
pid=`cat $PIDFILE`
running_pid $pid $DAEMON || return 1
return 0
}
case "$1" in
start)
[ -n "$enable_smart" ] && enable_smart
boot_mesg "Starting S.M.A.R.T. daemon: smartd" ${NORMAL}
if running; then
boot_mesg "already running" ${NORMAL}
echo_ok
exit 0
fi
rm -f $PIDFILE
if start-stop-daemon --start --quiet --pidfile $PIDFILE \
--exec $DAEMON -- $smartd_opts; then
echo_ok
else
echo_failure
RET=1
fi
;;
stop)
boot_mesg "Stopping S.M.A.R.T. daemon: smartd" ${NORMAL}
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
echo_ok
;;
reload|force-reload)
boot_mesg "Reloading S.M.A.R.T. daemon: smartd" ${NORMAL}
if start-stop-daemon --stop --quiet --signal 1 \
--pidfile $PIDFILE; then
echo_ok
else
echo_failure
RET=1
fi
;;
restart)
boot_mesg "Restarting S.M.A.R.T. daemon: smartd" ${NORMAL}
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PIDFILE
rm -f $PIDFILE
if start-stop-daemon --start --quiet --pidfile $PIDFILE \
--exec $DAEMON -- $smartd_opts; then
echo_ok
else
echo_failure
RET=1
fi
;;
status)
statusproc $DAEMON && exit 0 || exit $?
;;
*)
echo "Usage: /etc/init.d/smartmontools {start|stop|restart|reload|force-reload|status}"
exit 1
esac
exit $RET