| 1 |
#! /bin/sh |
| 2 |
### BEGIN INIT INFO |
| 3 |
# Provides: hdapsd |
| 4 |
# Required-Start: $local_fs $remote_fs |
| 5 |
# Required-Stop: $local_fs $remote_fs |
| 6 |
# Default-Start: 2 3 4 5 |
| 7 |
# Default-Stop: 0 1 6 |
| 8 |
# Short-Description: initscript to start hdapsd |
| 9 |
# Description: This file starts the hdapsd daemon |
| 10 |
### END INIT INFO |
| 11 |
|
| 12 |
# Author: Evgeni Golov <[email protected]> |
| 13 |
|
| 14 |
# Do NOT "set -e" |
| 15 |
|
| 16 |
# PATH should only include /usr/* if it runs after the mountnfs.sh script |
| 17 |
PATH=/sbin:/usr/sbin:/bin:/usr/bin |
| 18 |
DESC="IBM Hard Disk Active Protection System (HDAPS) daemon" |
| 19 |
NAME=hdapsd |
| 20 |
DAEMON=/usr/sbin/$NAME |
| 21 |
DAEMON_ARGS="" |
| 22 |
PIDFILE=/var/run/$NAME.pid |
| 23 |
SCRIPTNAME=/etc/init.d/$NAME |
| 24 |
DISK="sda" |
| 25 |
SENSITIVITY=15 |
| 26 |
OPTIONS="" |
| 27 |
FORCEENABLE="no" |
| 28 |
|
| 29 |
# Exit if the package is not installed |
| 30 |
[ -x "$DAEMON" ] || exit 0 |
| 31 |
|
| 32 |
# Read configuration variable file if it is present |
| 33 |
[ -r /etc/default/$NAME ] && . /etc/default/$NAME |
| 34 |
|
| 35 |
# Load the VERBOSE setting and other rcS variables |
| 36 |
. /lib/init/vars.sh |
| 37 |
|
| 38 |
# Define LSB log_* functions. |
| 39 |
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
| 40 |
. /lib/lsb/init-functions |
| 41 |
|
| 42 |
DAEMON_ARGS="-p$PIDFILE -d $DISK -s $SENSITIVITY -b $OPTIONS" |
| 43 |
if [ "$FORCEENABLE" = "yes" ]; then |
| 44 |
DAEMON_ARGS="$DAEMON_ARGS -f" |
| 45 |
fi |
| 46 |
|
| 47 |
# |
| 48 |
# Function that checks if /sys/block/$DISK/queue/protect |
| 49 |
# or /sys/block/$DISK/device/unload_heads exist |
| 50 |
# |
| 51 |
do_checkprotect() |
| 52 |
{ |
| 53 |
if [ ! -f /sys/block/$DISK/queue/protect -a ! -f /sys/block/$DISK/device/unload_heads ]; then |
| 54 |
log_warning_msg "Not starting $NAME: neither /sys/block/$DISK/queue/protect nor /sys/block/$DISK/device/unload_heads do exist, please read /usr/share/doc/hdapsd/README.Debian" |
| 55 |
exit 0 |
| 56 |
fi |
| 57 |
} |
| 58 |
|
| 59 |
# |
| 60 |
# Function that starts the daemon/service |
| 61 |
# |
| 62 |
do_start() |
| 63 |
{ |
| 64 |
# Return |
| 65 |
# 0 if daemon has been started |
| 66 |
# 1 if daemon was already running |
| 67 |
# 2 if daemon could not be started |
| 68 |
start-stop-daemon --start --quiet --exec $DAEMON --test > /dev/null \ |
| 69 |
|| return 1 |
| 70 |
start-stop-daemon --start --quiet --exec $DAEMON -- $DAEMON_ARGS \ |
| 71 |
|| return 2 |
| 72 |
# Add code here, if necessary, that waits for the process to be ready |
| 73 |
# to handle requests from services started subsequently which depend |
| 74 |
# on this one. As a last resort, sleep for some time. |
| 75 |
} |
| 76 |
|
| 77 |
# |
| 78 |
# Function that stops the daemon/service |
| 79 |
# |
| 80 |
do_stop() |
| 81 |
{ |
| 82 |
# Return |
| 83 |
# 0 if daemon has been stopped |
| 84 |
# 1 if daemon was already stopped |
| 85 |
# 2 if daemon could not be stopped |
| 86 |
# other if a failure occurred |
| 87 |
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME |
| 88 |
RETVAL="$?" |
| 89 |
[ "$RETVAL" = 2 ] && return 2 |
| 90 |
# Wait for children to finish too if this is a daemon that forks |
| 91 |
# and if the daemon is only ever run from this initscript. |
| 92 |
# If the above conditions are not satisfied then add some other code |
| 93 |
# that waits for the process to drop all resources that could be |
| 94 |
# needed by services started subsequently. A last resort is to |
| 95 |
# sleep for some time. |
| 96 |
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON |
| 97 |
[ "$?" = 2 ] && return 2 |
| 98 |
# Many daemons don't delete their pidfiles when they exit. |
| 99 |
rm -f $PIDFILE |
| 100 |
return "$RETVAL" |
| 101 |
} |
| 102 |
|
| 103 |
# |
| 104 |
# Function that sends a SIGUSR1 to the daemon/service |
| 105 |
# |
| 106 |
do_pause() { |
| 107 |
start-stop-daemon --stop --signal 10 --quiet --pidfile $PIDFILE --name $NAME |
| 108 |
return 0 |
| 109 |
} |
| 110 |
|
| 111 |
case "$1" in |
| 112 |
start) |
| 113 |
do_checkprotect |
| 114 |
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" |
| 115 |
do_start |
| 116 |
case "$?" in |
| 117 |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 118 |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 119 |
esac |
| 120 |
;; |
| 121 |
stop) |
| 122 |
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
| 123 |
do_stop |
| 124 |
case "$?" in |
| 125 |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 126 |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 127 |
esac |
| 128 |
;; |
| 129 |
status) |
| 130 |
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? |
| 131 |
;; |
| 132 |
pause) |
| 133 |
[ "$VERBOSE" != no ] && log_daemon_msg "Pauseing (8sec) $DESC" "$NAME" |
| 134 |
do_pause |
| 135 |
;; |
| 136 |
restart|force-reload) |
| 137 |
# |
| 138 |
# If the "reload" option is implemented then remove the |
| 139 |
# 'force-reload' alias |
| 140 |
# |
| 141 |
log_daemon_msg "Restarting $DESC" "$NAME" |
| 142 |
do_stop |
| 143 |
case "$?" in |
| 144 |
0|1) |
| 145 |
do_start |
| 146 |
case "$?" in |
| 147 |
0) log_end_msg 0 ;; |
| 148 |
1) log_end_msg 1 ;; # Old process is still running |
| 149 |
*) log_end_msg 1 ;; # Failed to start |
| 150 |
esac |
| 151 |
;; |
| 152 |
*) |
| 153 |
# Failed to stop |
| 154 |
log_end_msg 1 |
| 155 |
;; |
| 156 |
esac |
| 157 |
;; |
| 158 |
*) |
| 159 |
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload|pause}" >&2 |
| 160 |
exit 3 |
| 161 |
;; |
| 162 |
esac |
| 163 |
|
| 164 |
: |