File: init.d

package info (click to toggle)
qcontrol 0.4.2-1lenny1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 208 kB
  • ctags: 116
  • sloc: ansic: 968; sh: 206; makefile: 69
file content (159 lines) | stat: -rw-r--r-- 3,432 bytes parent folder | download
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
#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          qcontrol
# Required-Start:    $all
# Required-Stop:     
# Should-Start:      
# Should-Stop:       
# Default-Start:     2 3 4 5
# Default-Stop:      0 6
# Short-Description: Change status leds for QNAP TS-109/TS-209/TS-409
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DAEMON=/usr/sbin/qcontrol
NAME=qcontrol

PIDFILE=/var/run/$NAME.pid 

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

SOUND_BUZZER=yes

# Include defaults if available
if [ -f /etc/default/$NAME ] ; then
	. /etc/default/$NAME
fi

set -e

SOCKET=/var/run/qcontrol.sock

qcontrol_start() {
	# Should not already be running, but check anyway
	local pid="$(pidof qcontrol || true)"
	if [ -z "$pid" ]; then
		rm -f $SOCKET
		qcontrol -d >/dev/null & disown
		# allow time to startup (read config)
		sleep 0.5
		pid=$(pidof qcontrol)
	fi

	if [ "$pid" ]; then
		if [ -S $SOCKET ]; then
			echo $pid
			return 0
		else
			kill -TERM $pid
		fi
	fi
	return 1
}

# The gpio_keys character device is required with the default
# Debian configuration file.
test_event_dev() {
	if [ ! -c /dev/input/by-path/platform-gpio-keys-event ]; then
		log_warning_msg "qcontrol error: gpio_keys device not available"
		return 1
	fi
}

case "$1" in
    start)
	# Change status led to show green
	device=$(grep "Hardware[[:space:]]*:" /proc/cpuinfo 2>/dev/null | \
		 head -n1 | sed "s/^[^:]*: //")
	case $device in
	    "QNAP TS-109/TS-209")
		test_event_dev || exit 0
		if pid=$(qcontrol_start); then
			log_action_msg "System boot completed"
			# Returns 1 even on success
			qcontrol statusled greenon || true
			qcontrol powerled on || true
			if [ "$SOUND_BUZZER" != no ]; then
				qcontrol buzzer short || true
			fi

			# Kill the control process
			kill -TERM $pid
			rm -f $SOCKET
		fi
		;;
	    "QNAP TS-409")
		test_event_dev || exit 0
		if pid=$(qcontrol_start); then
			log_action_msg "System boot completed"
			# Returns 1 even on success
			qcontrol statusled greenon || true
			if [ "$SOUND_BUZZER" != no ]; then
				qcontrol buzzer short || true
			fi

			# Kill the control process
			kill -TERM $pid
			rm -f $SOCKET
		fi
		;;
	    *)
		log_warning_msg "qcontrol error: device is not supported"
		;;
	esac
	;;
    stop)
	# Change status led to show red
	device=$(grep "Hardware[[:space:]]*:" /proc/cpuinfo 2>/dev/null | \
		 head -n1 | sed "s/^[^:]*: //")
	case $device in
	    "QNAP TS-109/TS-209")
		test_event_dev || exit 0
		if pid=$(qcontrol_start); then
			log_action_msg "Preparing for shutdown"
			# Returns 1 even on success
			if [ "$SOUND_BUZZER" != no ]; then
				qcontrol buzzer short || true
			fi
			qcontrol statusled redon || true
			qcontrol powerled 1hz || true

			# Kill the control process
			kill -TERM $pid
			rm -f $SOCKET
		fi
		;;
	    "QNAP TS-409")
		test_event_dev || exit 0
		if pid=$(qcontrol_start); then
			log_action_msg "Preparing for shutdown"
			# Returns 1 even on success
			if [ "$SOUND_BUZZER" != no ]; then
				qcontrol buzzer short || true
			fi
			qcontrol statusled redon || true

			# Kill the control process
			kill -TERM $pid
			rm -f $SOCKET
		fi
		;;
	    *)
		log_warning_msg "qcontrol error: device is not supported"
		;;
	esac
	;;
    force-stop|restart|force-reload|status|reload)
	;;
    *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
	exit 1
	;;
esac

exit 0