#!/bin/sh DAEMON=spindown . /etc/init.d/modlibrc PID_FILE=/var/run/$DAEMON.$SPINDOWN_DEVICE.pid config() { SYSFS=$(grep sysfs /proc/mounts | head -n 1 | awk '{print $2}') if [ -z "$SYSFS" ]; then echo -n "Trying to mount sysfs ... " mkdir -p /var/sys mount sysfs /var/sys -t sysfs exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else [ ! -d /sys ] && echo "failed (backup mountpoint not available)." && exit 1 mount sysfs /sys -t sysfs exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi fi fi } start() { modlib_startdaemon start-stop-daemon -S -b -q -m -p $PID_FILE -n $DAEMON$SPINDOWN_DEVICE -a \ $DAEMON_BIN -- $SPINDOWN_DEVICE $SPINDOWN_IDLETIME $SPINDOWN_MODE } stop() { echo -n "(" for I in $(ls /var/run/$DAEMON.*.pid); do kill $(cat $I) > /dev/null 2>&1 if [ "$?" -eq 0 ]; then echo -n 'v' else echo -n 'x' fi done echo ") " } case $1 in ""|load) modreg cgi 'spindown' 'Disk Spindown' modreg daemon $DAEMON modlib_start $SPINDOWN_ENABLED ;; unload) modunreg daemon $DAEMON modunreg cgi 'spindown' modlib_stop ;; start) modlib_start ;; stop) modlib_stop ;; restart) modlib_restart ;; status) modlib_status ;; *) echo "Usage: $0 [load|unload|start|stop|restart|status]" 1>&2 exit 1 ;; esac exit 0