summaryrefslogtreecommitdiff
blob: 7e1b4617d2987a72c208ca39dc66c72805170569 (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
#!/sbin/runscript
# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

SPINDOWND_BIN="/usr/sbin/spindownd"
SPINDOWND_CFG=${SPINDOWND_CFG:-/etc/spindown.conf}
SPINDOWND_PID=${SPINDOWND_PID:-/var/run/spindown.pid}
SPINDOWND_FIFO=${SPINDOWND_FIFO:-/var/run/spindown.fifo}

opts="reload"

depend() {
	need localmount
	after bootmisc
}

checkconfig() {
	# check for config file
	if [ ! -e "${SPINDOWND_CFG}" ]; then
		eerror
		eerror "The spindownd config file (${SPINDOWND_CFG})"
		eerror "is missing!"
		eerror
		return 1
	fi
	# check for leftover pidfile
	if [ -f "${SPINDOWND_PID}" ]; then
		ewarn
		ewarn "The spindownd pidfile (${SPINDOWND_PID})"
		ewarn "exists although the service is not marked as started."
		ewarn "Will remove the pidfile and start the service in 10s"
		ewarn "if not interrupted..."
		ewarn
		sleep 10
		if ! rm -f "${SPINDOWND_PID}"; then
			eerror "Failed to remove the spindownd pidfile (${SPINDOWND_PID})"
			return 1
		fi
	fi
}

start() {
	checkconfig || return 1
	ebegin "Starting spindownd"
	start-stop-daemon --start --exec ${SPINDOWND_BIN} \
		-- -d -c ${SPINDOWND_CFG} -p ${SPINDOWND_PID} -f ${SPINDOWND_FIFO}
	eend $?
}

stop() {
	ebegin "Stopping spindownd"
	start-stop-daemon --stop --exec ${SPINDOWND_BIN} --pidfile ${SPINDOWND_PID}
	eend $?
}

reload() {
	ebegin "Reloading spindownd configuration"
	start-stop-daemon --stop --exec ${SPINDOWND_BIN} --pidfile ${SPINDOWND_PID} \
		--signal HUP
	eend $?
}