]> gitweb.michael.orlitzky.com - mjo-overlay.git/blob - app-laptop/hdapsd/files/hdapsd.init-20141024
Manifest bump.
[mjo-overlay.git] / app-laptop / hdapsd / files / hdapsd.init-20141024
1 #!/sbin/runscript
2 # Copyright 1999-2014 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License, v2
4
5 description="Hard Drive Active Protection System daemon"
6 command="/usr/sbin/hdapsd"
7 pidfile="/run/hdapsd.pid"
8
9 # Always daemonize when started by OpenRC, and don't make the pidfile
10 # configurable. Even if the user sets something dumb for the pidfile
11 # in /etc/hdapsd.conf, we want it to work! Fortunately the settings
12 # passed on the command-line override the config file.
13 command_args="--background --pidfile=${pidfile}"
14
15
16 depend() {
17 need localmount
18 }
19
20 checkconfig() {
21 # An empty DISKLIST is allowed because the disk will be
22 # auto-detected.
23 for DISK in ${DISKLIST}; do
24 if [ ! -b /dev/${DISK} ]; then
25 eerror "Could not find disk /dev/${DISK}!"
26 eerror "Adjust the DISK setting in /etc/conf.d/hdapsd"
27 return 1
28 fi
29
30 if [ ! -e /sys/block/${DISK}/queue/protect ] && \
31 [ ! -e /sys/block/${DISK}/device/unload_heads ] ; then
32 eerror "No protect entry for ${DISK}!"
33 eerror "Make sure your kernel is patched with the blk_freeze patch"
34 return 1
35 fi
36 done
37
38 # Load the tp_smapi module first. This is not a requirement, but
39 # it helps hdapsd's adaptive mode.
40 if [ ! -e /sys/devices/platform/smapi ] ; then
41 modprobe tp_smapi 2>/dev/null
42 fi
43
44 if [ ! -d /sys/devices/platform/hdaps ] ; then
45 ebegin "Loading hdaps module"
46 modprobe hdaps
47 eend $? || return 1
48 fi
49 }
50
51 start() {
52 checkconfig || return 1
53
54 for DISK in ${DISKLIST}; do
55 command_args="${command_args} -d ${DISK}"
56 done
57
58 # Since all of these settings are now optional, we append them
59 # only if we need to.
60 if [ ! -z "${THRESHOLD}" ] ; then
61 command_args="${command_args} --sensitivity ${THRESHOLD}"
62 fi
63
64 if [ ! -z "${SYSLOG}" ] ; then
65 command_args="${command_args} --syslog"
66 fi
67
68 if [ ! -z "${OPTIONS}" ] ; then
69 command_args="${command_args} ${OPTIONS}"
70 fi
71
72 ebegin "Starting the ${description}"
73 start-stop-daemon --start --exec "${command}" --pidfile "${pidfile}" \
74 -- ${command_args}
75 eend $?
76 }