File: ld10k1.init

package info (click to toggle)
alsa-tools 1.0.28-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 12,464 kB
  • ctags: 5,787
  • sloc: ansic: 23,609; cpp: 15,057; sh: 12,305; pascal: 1,140; asm: 1,053; xml: 814; makefile: 733; python: 250
file content (193 lines) | stat: -rwxr-xr-x 5,339 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/sh
#
# Copyright (C) 2005 Mikael Magnusson <mikma@users.sourceforge.net>
#
### BEGIN INIT INFO
# Provides:          ld10k1
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Should-Start:      udev
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Startup script for the ALSA emu10k1/2 patch loader
# Description:       A patch loader for use with the emu10k1 ALSA driver.
#                    Supports Sound Blaster Live!, Audigy and Audigy 2.
### END INIT INFO#

# Don't use set -e.  Check return status instead.

NAME=ld10k1
MYNAME=/etc/init.d/$NAME
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DAEMON=/usr/sbin/ld10k1
LO10K1=/usr/bin/lo10k1
DESC="emu10k1/2 patch loader"
STATE_FILE=/var/lib/alsa/ld10k1.state
RUN_DIR=/var/run/ld10k1
PIPE_NAME=${RUN_DIR}/ld10k1.socket
PID_FILE=${RUN_DIR}/ld10k1.pid
LOG_FILE=/var/log/ld10k1


. /lib/lsb/init-functions
print_warning_msg() { log_warning_msg "$1" ; }
print_error_msg() { log_warning_msg "$1" ; }
print_action_msg() { log_begin_msg "${1}..." ; }
print_daemon_msg() { log_daemon_msg "$1" $2 ; }
print_progress_msg() { log_progress_msg "$1" ; }
print_completion_msg_and_exit() { [ "$1" = "0" ] && log_progress_msg "done" ; log_end_msg "$1" ; exit $1 ; }
print_end_msg_and_exit() { log_end_msg "$1" ; exit $1 ; }

# Default overrides
if [ -r /etc/default/ld10k1 ] ; then
	. /etc/default/ld10k1 || { print_error_msg "${MYNAME}: Error: Failed reading /etc/default/ld10k1" ; exit 1 ; }
fi

[ "$CARD" ] || exit 0
[ -x "$DAEMON" ] || exit 0
[ -x "$LO10K1" ] || exit 0

check_run_dir()
{
	[ -d "$RUN_DIR" ] && return 0
	mkdir "$RUN_DIR" || return 1
	[ -d "$RUN_DIR" ] || return 1
	chgrp audio "$RUN_DIR" || return 1
	chmod 750 "$RUN_DIR" || return 1
	return 0
}

daemon_is_running()
{
	# Return
	#   0 if daemon is running
	#   1 if daemon is not running
	start-stop-daemon --start --quiet --pidfile "$PID_FILE" --exec "$DAEMON" --test > /dev/null \
		|| return 0
	return 1
}

start_daemon()
{
	# Return
	#   0 if daemon has been started
	#   1 if daemon was already running
	#   2 if daemon could not be started
	daemon_is_running && return 1
	start-stop-daemon --start --quiet --pidfile "$PID_FILE" --exec "$DAEMON" -- \
		--pipe_name "$PIPE_NAME" \
		--daemon "$DAEMON_OPTS" \
		--pidfile "$PID_FILE" \
		--logfile "$LOG_FILE" \
		--card "$CARD" \
		|| return 2
}

stop_daemon()
{
	# Return
	#   0 if daemon has been stopped
	#   1 if daemon was already stopped
	#   2 if daemon could not be stopped
	daemon_is_running && start-stop-daemon --stop --quiet --retry=TERM/10/KILL/5 --pidfile "$PID_FILE" --name "$NAME"
	RETVAL="$?"
	[ "$RETVAL" = 2 ] && return 2
	# Wait for children to finish too
	start-stop-daemon --stop --quiet --oknodo --retry=0/10/KILL/5 --exec "$DAEMON"
	[ "$?" = 2 ] && return 2
	rm -f "$PID_FILE"
	return "$RETVAL"
}

restore_state()
{
	$LO10K1 --restore "$STATE_FILE" >/dev/null 2>&1
}

store_state()
{
	$LO10K1 --store "$STATE_FILE" >/dev/null 2>&1
}

case "$1" in
  start)
	print_daemon_msg "Starting $DESC"
	check_run_dir || print_end_msg_and_exit 1 "" "(failed creating run directory)"
	print_progress_msg "$NAME"
	start_daemon
	case "$?" in
	  0) : ;;
	  1) print_progress_msg "(already running)" ; print_end_msg_and_exit 0 ;;
	  *) print_end_msg_and_exit 1 ;;
	esac
	[ -r "$STATE_FILE" ] || { print_progress_msg "(no state to restore)" ; print_end_msg_and_exit 0 ; }
	if restore_state ; then
		print_progress_msg "(state restored)"
		print_end_msg_and_exit 0
	else
		print_progress_msg "(state restore failed)"
		print_end_msg_and_exit 1
	fi
	;;
  stop)
	print_daemon_msg "Stopping $DESC"
	if daemon_is_running; then
		if store_state; then
			print_progress_msg "(state stored)"
		else
			print_progress_msg "(state store failed)"
		fi
	fi
	print_progress_msg "$NAME"
	stop_daemon
	case "$?" in
	  0) print_end_msg_and_exit 0 ;;
	  1) print_progress_msg "(not running)" ; print_end_msg_and_exit 0 ;;
	  *) print_end_msg_and_exit 1 ;;
	esac
	;;
  restart)
	print_daemon_msg "Restarting $DESC"
	print_progress_msg "$NAME"
	stop_daemon
	case "$?" in
	  0) : ;;
	  1) print_progress_msg "(not running)" ;;
	  *) print_progress_msg "(failed on stop)" ;;
	esac
	start_daemon
	case "$?" in
	  0) : ;;
	  1) print_progress_msg "(old process is still running)" ; print_end_msg_and_exit 1 ;;
	  *) print_progress_msg "(failed to start)" ; print_end_msg_and_exit 1 ;;
	esac
	[ -r "$STATE_FILE" ] || { print_progress_msg "(no state to restore)" ; print_end_msg_and_exit 0 ; }
	if restore_state ; then
		print_progress_msg "(state restored)"
		print_end_msg_and_exit 0
	else
		print_progress_msg "(state restore failed)"
		print_end_msg_and_exit 1
	fi
	;;
  reload|force-reload)
	print_action_msg "Reloading $DESC state"
	daemon_is_running || { print_progress_msg "(not running)" ; print_completion_msg_and_exit 0 ; }
	[ -r "$STATE_FILE" ] || { print_progress_msg "(no state to restore)" ; print_completion_msg_and_exit 0 ; }
	restore_state
	print_completion_msg_and_exit "$?"
	;;
  store)
	print_action_msg "Storing $DESC state"
	daemon_is_running || { print_progress_msg "(not running)" ; print_completion_msg_and_exit 0 ; }
	store_state
	print_completion_msg_and_exit "$?"
	;;
  *)
	print_warning_msg "Usage: $MYNAME {start|stop|restart|reload|force-reload|store}"
	exit 3
	;;
esac

exit 0