]> git.pld-linux.org Git - packages/alsa-utils.git/blame - alsasound.init
- fixed force-reload, added try-restart
[packages/alsa-utils.git] / alsasound.init
CommitLineData
678c4fff 1#!/bin/sh
634db781 2#
8e5b4036 3# alsasound This shell script takes care of starting and stopping \
4# ALSA sound driver.
634db781
AM
5#
6# This script requires /usr/sbin/alsactl program from alsa-utils package.
7#
f3ec2d8f 8# Copyright (c) by Jaroslav Kysela <perex@jcu.cz>
634db781
AM
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24#
2efb5f03 25# For PLD Linux Distribution:
8e5b4036 26# chkconfig: 2345 87 14
27# description: ALSA driver
634db781
AM
28#
29
30# Source function library.
31. /etc/rc.d/init.d/functions
32
678c4fff
AM
33driver_start()
34{
634db781
AM
35 #
36 # insert all sound modules
37 #
b0646167 38 modprobe -c | awk '$1 == "alias" && $3 != "off" && ($2 ~ /^snd-card-[0-9]$/) {print $3}' | \
e0831d0a 39 while read line; do \
40 msg_starting "sound driver: $line"
41 busy
42 /sbin/modprobe $line
43 ok
44 done
b0646167 45 modprobe -c | awk '$1 == "alias" && $3 != "off" && ($2 ~ /^sound-service-[0-9]-[0-9]+$/) {print $3}' | \
634db781 46 while read line; do \
d08febb7 47 msg_starting "sound driver: $line"
150b8378 48 busy
49 /sbin/modprobe $line
50 ok
634db781 51 done
b0646167 52
634db781
AM
53 # restore driver settings
54 #
a5788d60 55 if [ -x /usr/sbin/alsactl ]; then
b8fb64c0 56 if [ -f /etc/asound.state ]; then
049f843f 57 if [ "$(kernelver)" -lt "002006012" ]; then
2a5ddd29 58 for i in 1 2 3 4; do
59 [ -a /dev/snd/controlC0 ] && break
60 sleep 1
61 done
62 fi
a5788d60 63 /usr/sbin/alsactl restore
b8fb64c0 64 fi
634db781
AM
65 else
66 show "ERROR: alsactl not found"; fail
67 fi
68}
69
678c4fff
AM
70detect_stop()
71{
634db781
AM
72 #
73 # remove all sound modules
74 #
4d1ff5eb
ER
75 /sbin/lsmod | awk '/^(snd|ac97_bus)/ { print $1 }' | while read module; do \
76 /sbin/rmmod $module
634db781
AM
77 done
78}
79
678c4fff
AM
80driver_stop()
81{
634db781
AM
82 #
83 # store driver settings
84 #
a5788d60
ER
85 if [ -x /usr/sbin/alsactl ]; then
86 /usr/sbin/alsactl store
634db781 87 else
678c4fff 88 show '!!!alsactl not found!!!'; fail
634db781
AM
89 fi
90 #
91 # remove all sound modules
92 #
93 detect_stop
94}
95
678c4fff
AM
96detect_start()
97{
634db781
AM
98 #
99 # run only detect module
100 #
101 /sbin/modprobe snd-detect
102}
103
02813c63
ER
104# Start driver.
105start() {
634db781 106 if [ ! -d /proc/asound ]; then
d08febb7 107 driver_start
108 if [ -d /proc/asound ]; then
109 touch /var/lock/subsys/alsasound
110 else
111 exit 1
112 fi
634db781 113 else
d08febb7 114 if [ -f /proc/asound/detect ]; then
b52c7707 115 show "Shutting down sound detect module"
d08febb7 116 detect_stop
117 ok
118 driver_start
119 if [ -d /proc/asound ]; then
120 touch /var/lock/subsys/alsasound
121 else
122 exit 1
123 fi
124 else
e0831d0a 125 msg_already_running "ALSA driver"
d08febb7 126 fi
634db781 127 fi
02813c63
ER
128}
129
130# Stop daemons.
131stop() {
634db781 132 if [ -d /proc/asound ]; then
b52c7707 133 show "Shutting down sound driver"
d08febb7 134 busy
135 if [ -f /proc/asound/detect ]; then
136 detect_stop
137 else
138 driver_stop
139 fi
e0831d0a 140 (rmmod isapnp; rmmod soundcore) 2> /dev/null
d08febb7 141 if [ -d /var/lock/subsys ]; then
142 rm -f /var/lock/subsys/alsasound
143 fi
144 ok
634db781 145 else
d08febb7 146 msg_not_running "ALSA driver"
634db781 147 fi
5ef1ff04
ER
148}
149
031987f5
JB
150condrestart() {
151 if [ -f /var/lock/subsys/alsasound ]; then
152 stop
153 start
154 else
155 msg_not_running "ALSA driver"
156 RETVAL=$1
157 fi
158}
159
02813c63
ER
160
161# See how we were called.
162case "$1" in
163 start)
164 start
165 ;;
166 stop)
167 stop
d08febb7 168 ;;
031987f5 169 restart)
02813c63
ER
170 stop
171 start
d08febb7 172 ;;
031987f5
JB
173 try-restart)
174 condrestart 0
175 ;;
176 force-reload)
177 condrestart 7
178 ;;
d08febb7 179 status)
180 # TODO
634db781 181 ;;
634db781 182 *)
031987f5 183 msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
d08febb7 184 exit 3
634db781
AM
185esac
186
187exit 0
This page took 0.106555 seconds and 4 git commands to generate.