File: noflushd.templ

package info (click to toggle)
noflushd 2.7.5-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 792 kB
  • ctags: 302
  • sloc: ansic: 2,537; sh: 1,142; makefile: 85
file content (177 lines) | stat: -rw-r--r-- 4,145 bytes parent folder | download | duplicates (4)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
#
# Start the noflush daemon to spin down idle disks.
#
# Written by Daniel Kobras <kobras@linux.de>
# $Id: noflushd.templ,v 1.6 2004/07/19 10:00:32 nold Exp $
#
# The next lines define runlevels and priorities to start this
# skript. Syntax is <runlevels_to_start> <start_priority> <stop_priotity>.
#
# chkconfig: 2345 80 10
# description: 	Start and stop the noflush daemon to handle spindown \
#		of idle disks.
#
### BEGIN INIT INFO
# Provides: noflushd
# Required-Start: $remote_fs
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO

# Note: Edit TIMEOUT below to change the default timeout. If present, 
# variable NOFLUSHD_TIMEOUT in /etc/rc.config will override this value.
# However, highest priority is given to an environment variable TIMEOUT.
# Example (assuming bash, skript in /etc/init.d/): 
#
# # TIMEOUT=60 /etc/init.d/noflushd restart
#
# to restart the daemon with 1 hour of idle timeout, overriding defaults.

# XXX: In earlier versions, the timeout values were given in seconds.
#      Now we use minutes instead. Don't get confused!

# One IDE hard disk present:
DISKS="/dev/hda"

DEFAULT_TIMEOUT=60	# default timeout in minutes (EDIT THIS!)

if [ -f /etc/rc.config ]; then
	. /etc/rc.config
	if [ "$START_NOFLUSHD" ]; then
		[ "$START_NOFLUSHD" = "yes" ] || exit 0
	fi	
	if [ ! "$TIMEOUT" ]; then
		[ "$NOFLUSHD_TIMEOUT" ] && TIMEOUT="$NOFLUSHD_TIMEOUT"
	fi
	[ "$NOFLUSHD_DISKS" ] && DISKS="$NOFLUSHD_DISKS"
elif [ -f /etc/sysconfig/noflushd ]; then
	# No namespace problems here. TIMEOUT and DISKS can be set
	# verbatim.
	. /etc/sysconfig/noflushd
fi

[ ! "$TIMEOUT" ] && TIMEOUT=$DEFAULT_TIMEOUT
DAEMON=+sbindir+/noflushd	# +sbindir+ gets rewritten at make time.
PIDFILE=/var/run/noflushd.pid
OPTIONS="-v -n $TIMEOUT $DISKS"

check_pidfile() {

	test -r "$PIDFILE" || return 0
	return $(cat $PIDFILE)
}

find_pid_by_name() {

	NAME="$1"
	for i in /proc/[1-9]*; do
		# Use cat instead of shell redir because /proc/<pid> might
		# have vanished before we had a chance to open an fd on
		# status. The cat variant fails gracefully in this case.
		cat "$i/status" 2> /dev/null | while read TAG VALUE; do
                	test "$TAG" = "Name:" || continue
                     	test "$VALUE" != "$NAME" || return "$(basename $i)"
			break
		done || return $?
	done
	return 0
}

start_debian() {

	/sbin/start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $OPTIONS
}

stop_debian() {

	/sbin/start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON
}

start_lsb() {

	startproc $DAEMON $OPTIONS
}

stop_lsb() {

	killproc -TERM $DAEMON
	rm -f $PIDFILE
}

start_redhat() {

	daemon $DAEMON $OPTIONS
}

stop_redhat() {

	killproc $DAEMON
}

start_generic() {
	if ! check_pidfile || ! find_pid_by_name $(basename $DAEMON); then
		echo "Warning! Another noflushd appears to be already running. Starting anyway."
	fi
	$DAEMON $OPTIONS 2>&1 >/dev/null
}

stop_generic() {

	check_pidfile || { kill $?; return; }
	find_pid_by_name $(basename $DAEMON) || kill $?
}

activate_kupdate() {

	find_pid_by_name kupdate || kill -CONT $?
	find_pid_by_name kupdated || kill -CONT $?
}

test -x $DAEMON || exit 0

found=0
for name in pdflush kupdate kupdated; do
	find_pid_by_name "$name" || { found=1; break; }
done

if [ "$found" -eq 0 ]; then
		echo "No kupdate[d]/pdflush found. Run bdflush-1.6 for sleep support."
		exit 0
fi

set -e 

METHOD=generic
[ -x /sbin/start-stop-daemon ] && METHOD=debian
[ -x /sbin/startproc ] && METHOD=lsb
if [ -f /etc/rc.d/init.d/functions ]; then
	. /etc/rc.d/init.d/functions && METHOD=redhat
fi

case "$1" in

	start)
		echo "Starting idle disk daemon with default timeout $TIMEOUT..."
		start_$METHOD && echo "Done."
		;;
	stop)
		echo -n "Stopping idle disk daemon"
		stop_$METHOD && echo "."
		activate_kupdate	# Paranoia.
		;;
	restart)
		echo -n "Stopping idle disk daemon"
		stop_$METHOD && echo "."
		activate_kupdate	# Paranoia.
		sleep 1
		echo "Starting idle disk daemon with default timeout $TIMEOUT..."
		start_$METHOD && echo "Done."
		;;	
	*)
		echo "Usage: $(basename $0) {start|stop|restart}"
		exit 1
esac

exit 0