File hddtemp.init of Package hddtemp
#! /bin/sh
#
# Copyright (c) 1995-2000 SuSE GmbH Nuernberg, Germany.
#
# CoAuthor: Mr.Bool <mr.bool@rambler.ru> ;-)
#
# /etc/init.d/hddtemp
#
# and symbolic its link
#
# /usr/sbin/rchddtemp
#
### BEGIN INIT INFO
# Provides: hddtemp
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Default-Start: 3 5
# Default-Stop: 0 6
# Short-Description: hddtemp daemon
# Description: Start the hddtemp daemon
### END INIT INFO
. /etc/rc.status
[ -r /etc/sysconfig/hddtemp ] && . /etc/sysconfig/hddtemp
# Shell functions sourced from /etc/rc.status:
# rc_check check and set local and overall rc status
# rc_status check and set local and overall rc status
# rc_status -v ditto but be verbose in local rc status
# rc_status -v -r ditto and clear the local rc status
# rc_failed set local and overall rc status to failed
# rc_reset clear local rc status (overall remains)
# rc_exit exit appropriate to overall rc status
# First reset status of this service
rc_reset
HDDTEMP_EXEC=`/usr/bin/whereis $HDDTEMP_NAME | grep $HDDTEMP_NAME | awk '{print $2;}'`
if ! test -f $HDDTEMP_EXEC ; then
echo "$HDDTEMP_EXEC not found."
rc_failed 1
fi
if ! test -f $HDDTEMP_DB ; then
echo "$HDDTEMP_DB not found."
rc_failed 1
fi
if test "$DEVICE" = ""; then
# echo "device is not defined."
rc_failed 6
fi
if test "$HDDTEMP_PORT" = ""; then
# echo "port is not defined."
rc_failed 6
fi
case "$1" in
start)
echo -n "Starting $HDDTEMP_NAME daemon for $DEVICE"
## Start daemon with startproc(8). If this fails
## the echo return value is set appropriate.
startproc -f -q $HDDTEMP_EXEC $HDDTEMP_ARGS
# Remember status and be verbose
rc_status -v
;;
stop)
echo -n "Shutting down $HDDTEMP_NAME daemon for $DEVICE"
## Stop daemon with killproc(8) and if this fails
## set echo the echo return value.
if [ -x /bin/netstat ]; then
netstat -nlp 2>/dev/null | while read prot a b local remote state prog; do
if [ "${local##*:}" = "$HDDTEMP_PORT" ] ; then
if [ -n "$prog" ]; then
kill -TERM ${prog%%/*}
fi
fi
done
else
echo " netstat is missing. I cannot determine if there is"
echo "listening $HDDTEMP_NAME configured via $HDDTEMP_CFG"
echo "to be stoped."
rc_failed 1
fi
# Remember status and be verbose
rc_status -v
;;
try-restart)
## Stop the service and if this succeeds (i.e. the
## service was running before), start it again.
$0 status >/dev/null && $0 restart
# Remember status and be quiet
rc_status
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
$0 start
# Remember status and be quiet
rc_status
;;
force-reload|reload)
## Signal the daemon to reload its config. Most daemons
## do this on signal 1 (SIGHUP).
echo -n "Reload service $HDDTEMP_NAME for $DEVICE"
if [ -x /bin/netstat ]; then
netstat -nlp 2>/dev/null | (while read prot a b local remote state prog; do
if [ "${local##*:}" = "$HDDTEMP_PORT" ] ; then
LISTENING_PRG=$prog
fi
done
if [ -n "$LISTENING_PRG" ]; then
kill -HUP ${LISTENING_PRG%%/*}
else
rc_failed 7
fi
)
else
echo " netstat is missing. I cannot determine if there is"
echo "listening $HDDTEMP_NAME configured via $HDDTEMP_CFG"
echo "to be reloded."
rc_failed 1
fi
rc_status -v
;;
status)
echo -n "Checking for service $HDDTEMP_NAME:"
## Check status with checkproc(8), if process is running
## checkproc will return with exit status 0.
# Status has a slightly different for the status command:
# 0 - service running
# 1 - service dead, but /var/run/ pid file exists
# 2 - service dead, but /var/lock/ lock file exists
# 3 - service not running
if [ -x /bin/netstat ]; then
netstat -nlp 2>/dev/null | ( while read prot a b local remote state prog; do
if [ "${local##*:}" = "$HDDTEMP_PORT" ] ; then
LISTENING_PRG=$prog
fi
done
if [ -n "$LISTENING_PRG" ]; then
rc_failed 0
else
rc_failed 3
fi
)
else
echo " netstat is missing. I cannot determine if there is"
echo "listening $HDDTEMP_NAME configured via $HDDTEMP_CFG."
rc_failed 1
fi
rc_status -v
;;
*)
echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
exit 1
;;
esac
rc_exit