summaryrefslogtreecommitdiff
blob: 579c2291b9d7f2696ac5e33c798cebbb683848a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/sbin/runscript
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2

depend() {
    need localmount
}

checkconfig() {
    if [[ -n ${DISK} ]]; then
	ewarn "Please migrate DISK to DISKLIST in /etc/conf.d/hdapsd."
	DISKLIST=${DISK}
    fi

    if [[ -z ${DISKLIST} || -z ${THRESHOLD} ]] ; then
	eerror "You should setup DISKLIST and THRESHOLD in /etc/conf.d/hdapsd."
	return 1
    fi

    for DISK in ${DISKLIST}; do
        if [ ! -b /dev/${DISK} ]; then
            eerror "Could not find disk /dev/${DISK}!"
            eerror "Adjust the DISK setting in /etc/conf.d/hdapsd"
            return 1
        fi

        if [[ ! -e /sys/block/${DISK}/queue/protect ]] && [[ ! -e /sys/block/${DISK}/device/unload_heads ]] ; then
            eerror "No protect entry for ${DISK}!"
            eerror "Make sure your kernel is patched with the blk_freeze patch"
            return 1
        fi
    done

    # Load the tp_smapi module first
    # This is not a requirement, but it helps hdapsd adaptive mode
    if [[ ! -e /sys/devices/platform/smapi ]] ; then
	modprobe tp_smapi 2>/dev/null
    fi
	
    if [[ ! -d /sys/devices/platform/hdaps ]]; then
	ebegin "Loading hdaps module"
        modprobe hdaps
	eend $? || return 1
    fi
}

start() {
    checkconfig || return 1

    local DISKOPTS DISK
    for DISK in ${DISKLIST}; do
	DISKOPTS="-d ${DISK} "
    done

    ebegin "Starting Hard Drive Active Protection System daemon"
    start-stop-daemon --start --exec /usr/sbin/hdapsd \
	--pidfile /var/run/hdapsd.pid \
	-- --syslog --background --pidfile \
	${DISKOPTS} --sensitivity "${THRESHOLD}" ${OPTIONS}
    eend $?
}
	
stop() {
    ebegin "Stopping Hard Drive Active Protection System daemon"
    start-stop-daemon --stop --exec /usr/sbin/hdapsd \
	--pidfile /var/run/hdapsd.pid
    eend $?
}