-# Cygwin
-elif uname | grep -i CYGWIN > /dev/null 2>&1 ; then
-
-# The following settings may be changed by the configuration file below
- # Service Name (must be unique)
- smartd_svcname=smartd
- # Service display name
- smartd_svcdisp="CYGWIN smartd"
- # Service description
- smartd_svcdesc="\
-Controls and monitors storage devices using the Self-Monitoring \
-Analysis and Reporting Technology System (S.M.A.R.T.) \
-built into ATA and SCSI Hard Drives. \
-http://smartmontools.sourceforge.net/"
-
-# Source configuration file. This should define the shell variable smartd_opts.
-# Email smartmontools-support@lists.sourceforge.net if there is a better choice
-# of path for Cygwin
-
- [ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools
-
- PID_FILE=/var/run/smartd.pid
- RETVAL=0
-
- # Note: "[ -r $PID_FILE ]" is not used here. On Cygwin, this command may
- # return success even if the file is present but cannot be read by current user.
- # If smartd is running as service, smartd.pid is owned by local system account
- # which is different from any user ever executing this script.
-
- case "$1" in
- start)
- if cygrunsrv -L 2>/dev/null | grep "^${smartd_svcname}$" >/dev/null 2>&1; then
- echo -n "Starting service $smartd_svcname: "
- cygrunsrv -S "$smartd_svcname"
- else
- echo -n "Starting smartd as daemon: "
- $SMARTD_BIN -p $PID_FILE $smartd_opts
- fi
- RETVAL=$?
- ;;
- stop)
- echo -n "Shutting down smartd: "
- pid="`cat $PID_FILE 2>/dev/null`" && kill "$pid"
- RETVAL=$?
- ;;
- reload)
- echo -n "Reloading smartd configuration: "
- pid="`cat $PID_FILE 2>/dev/null`" && kill -HUP "$pid"
- RETVAL=$?
- ;;
- report)
- echo -n "Checking SMART devices now: "
- pid="`cat $PID_FILE 2>/dev/null`" && kill -USR1 "$pid"
- RETVAL=$?
- ;;
- restart)
- $0 stop
- sleep 1
- $0 start
- exit $?
- ;;
- install)
- shift
- [ $# -eq 0 ] || smartd_opts="$*"
- dep=
- if cygrunsrv -L 2>/dev/null | grep "^syslogd$" >/dev/null 2>&1; then
- dep="-y syslogd"
- else
- echo "Warning: syslogd service not installed, smartd will write to windows event log.";
- fi
- echo "Installing service ${smartd_svcname}${smartd_opts+ with options '$smartd_opts'}:"
- cygrunsrv -I "$smartd_svcname" -d "$smartd_svcdisp" -f "$smartd_svcdesc" $dep \
- -e CYGWIN="$CYGWIN" -p $SMARTD_BIN -a "--service -p ${PID_FILE}${smartd_opts+ }$smartd_opts"
- RETVAL=$?
- ;;
- remove)
- echo "Removing service $smartd_svcname:"
- cygrunsrv -R "$smartd_svcname"
- RETVAL=$?
- ;;
- status)
- echo -n "Checking smartd status: "
- if cygrunsrv -L 2>/dev/null | grep "^${smartd_svcname}$" >/dev/null 2>&1; then
- if cygrunsrv -Q "$smartd_svcname" 2>/dev/null | grep "State *: Running" >/dev/null 2>&1; then
- echo "running as service '$smartd_svcname'."
- elif ps -e 2>/dev/null | grep " ${SMARTD_BIN}$" >/dev/null 2>&1; then
- echo "installed as service '$smartd_svcname' but running as daemon."
- else
- echo "installed as service '$smartd_svcname' but not running."
- RETVAL=1
- fi
- elif ps -e 2>/dev/null | grep " ${SMARTD_BIN}$" >/dev/null 2>&1; then
- echo "running as daemon."
- else
- echo "not running."
- RETVAL=1
- fi
- exit $RETVAL
- ;;
- *)
- echo "Usage: $0 {start|stop|restart|reload|report|status}"
- echo " $0 {install [options]|remove}"
- exit 1
- esac
-
- if [ "$RETVAL" -eq 0 ]; then echo "done"; else echo "ERROR"; fi
- exit $RETVAL
-