3
# dahdi This shell script takes care of loading and unloading \
4
# DAHDI Telephony interfaces
6
# description: The DAHDI drivers allow you to use your linux \
7
# computer to accept incoming data and voice interfaces
9
# config: /etc/dahdi/init.conf
13
# Required-Start: $local_fs $remote_fs
14
# Required-Stop: $local_fs $remote_fs
15
# Should-Start: $network $syslog
16
# Should-Stop: $network $syslog
17
# Default-Start: 2 3 4 5
19
# Description: dahdi - load and configure DAHDI modules
24
# Don't edit the following values. Edit /etc/dahdi/init.conf instead.
26
DAHDI_CFG=/usr/sbin/dahdi_cfg
27
DAHDI_CFG_CMD=${DAHDI_CFG_CMD:-"$DAHDI_CFG"} # e.g: for a custom system.conf location
29
FXOTUNE=/usr/sbin/fxotune
31
# The default syncer Astribank. Usually set automatically to a sane
32
# value by xpp_sync(1) if you have an Astribank. You can set this to an
33
# explicit Astribank (e.g: 01).
36
# The maximal timeout (seconds) to wait for udevd to finish generating
37
# device nodes after the modules have loaded and before running dahdi_cfg.
40
# A list of modules to unload when stopping.
41
# All of their dependencies will be unloaded as well.
42
DAHDI_UNLOAD_MODULES="dahdi"
45
# Determine which kind of configuration we're using
47
system=redhat # assume redhat
48
if [ -f /etc/debian_version ]; then
52
if [ -f /etc/gentoo-release ]; then
56
if [ -f /etc/SuSE-release -o -f /etc/novell-release ]
61
# Source function library.
62
if [ $system = redhat ]; then
63
. $initdir/functions || exit 0
66
DAHDI_MODULES_FILE="/etc/dahdi/modules"
68
[ -r /etc/dahdi/init.conf ] && . /etc/dahdi/init.conf
70
if [ $system = redhat ]; then
71
LOCKFILE=/var/lock/subsys/dahdi
74
# recursively unload a module and its dependencies, if possible.
75
# where's modprobe -r when you need it?
76
# inputs: module to unload.
77
# returns: the result from
80
line=`lsmod 2>/dev/null | grep "^$1 "`
81
if [ "$line" = '' ]; then return; fi # module was not loaded
84
# $1: the original module, $2: size, $3: refcount, $4: deps list
85
mods=`echo $4 | tr , ' '`
87
# xpp_usb keeps the xpds below busy if an xpp hardware is
88
# connected. Hence must be removed before them:
89
case "$module" in xpd_*) mods="xpp_usb $mods";; esac
94
ec_modules="$mod $ec_modules"
97
# run in a subshell, so it won't step over our vars:
102
# Now that all the other dependencies are unloaded, we can unload the
103
# dahdi_echocan modules. The drivers that register spans may keep
104
# references on the echocan modules before they are unloaded.
105
for mod in $ec_modules; do
112
for module in $DAHDI_UNLOAD_MODULES; do
113
unload_module $module
117
# In (xpp) hotplug mode, the init script is also executed from the
118
# hotplug hook. In that case it should not attempt to loade modules.
120
# This function only retunrs false (1) if we're in hotplug mode and
121
# coming from the hotplug hook script.
122
hotplug_should_load_modules() {
123
if [ "$XPP_HOTPLUG_DAHDI" = yes -a "$CALLED_FROM_ATRIBANK_HOOK" != '' ]
130
# In (xpp) hotplug mode: quit after we loaded modules.
132
# In hotplug mode, the main run should end here, whereas the rest of the
133
# script should be finished by the instance running from the hook.
134
# Note that we only get here if there are actually Astribanks on the
135
# system (otherwise noone will trigger the run of the hotplug hook
137
hotplug_exit_after_load() {
138
if [ "$XPP_HOTPLUG_DAHDI" = yes -a "$CALLED_FROM_ATRIBANK_HOOK" = '' ]
144
# Initialize the Xorcom Astribank (xpp/) using perl utiliites:
146
# do nothing if there are no astribank devices:
147
if ! /usr/share/dahdi/waitfor_xpds; then return 0; fi
149
hotplug_exit_after_load
151
# overriding locales for the above two, as perl can be noisy
152
# when locales are missing.
153
# No register all the devices if they didn't auto-register:
154
LC_ALL=C dahdi_registration on
160
if ! echo /var/lib/digium/licenses/HPEC-*.lic | grep -v '\*' | grep -q .; then
164
# dahdihpec_enable not installed in /usr/sbin
165
if [ ! -f /usr/sbin/dahdihpec_enable ]; then
166
echo -n "Running dahdihpec_enable: Failed"
168
echo " The dahdihpec_enable binary is not installed in /usr/sbin."
172
# dahdihpec_enable not set executable
173
if [ ! -x /usr/sbin/dahdihpec_enable ]; then
174
echo -n "Running dahdihpec_enable: Failed"
176
echo " /usr/sbin/dahdihpec_enable is not set as executable."
180
# dahdihpec_enable properly installed
181
if [ $system = debian ]; then
182
echo -n "Running dahdihpec_enable: "
183
/usr/sbin/dahdihpec_enable 2> /dev/null
184
elif [ $system = redhat ]; then
185
action "Running dahdihpec_enable: " /usr/sbin/dahdihpec_enable
193
echo " This can be caused if you had already run dahdihpec_enable, or if your HPEC license is no longer valid."
198
if ! grep -q ' DYN/' /proc/dahdi/* 2>/dev/null; then return; fi
200
# we should only get here if we have dynamic spans. Right?
205
# Some systems, e.g. Debian Lenny, add here -b, which will break
206
# loading of modules blacklisted in modprobe.d/*
207
unset MODPROBE_OPTIONS
208
modules=`sed -e 's/#.*$//' $DAHDI_MODULES_FILE 2>/dev/null`
209
#if [ "$modules" = '' ]; then
212
echo "Loading DAHDI hardware modules:"
214
for line in $modules; do
215
if [ $system = debian ]; then
217
if modprobe $line 2> /dev/null; then
222
elif [ $system = redhat ]; then
223
action " ${line}: " modprobe $line
229
if [ ! -x "$DAHDI_CFG" ]; then
230
echo "dahdi_cfg not executable"
234
if [ ! -f /etc/dahdi/system.conf ]; then
235
echo "/etc/dahdi/system.conf not found. Nothing to do."
241
# See how we were called.
244
if hotplug_should_load_modules; then
248
TMOUT=$DAHDI_DEV_TIMEOUT # max secs to wait
250
while [ ! -d /dev/dahdi ] ; do
252
TMOUT=`expr $TMOUT - 1`
253
if [ $TMOUT -eq 0 ] ; then
254
echo "Error: missing /dev/dahdi!"
261
if [ ! -e /proc/dahdi/1 ]; then
262
echo "No hardware timing source found in /proc/dahdi, loading dahdi_dummy"
263
modprobe dahdi_dummy 2> /dev/null
266
if [ $system = debian ]; then
267
echo -n "Running dahdi_cfg: "
268
$DAHDI_CFG_CMD 2> /dev/null && echo -n "done"
270
elif [ $system = redhat ]; then
271
action "Running dahdi_cfg: " $DAHDI_CFG_CMD
275
if [ "$LOCKFILE" != '' ]; then
276
[ $RETVAL -eq 0 ] && touch $LOCKFILE
279
if [ -x "$FXOTUNE" ] && [ -r /etc/fxotune.conf ]; then
280
# Allowed to fail if e.g. Asterisk already uses channels:
284
# Set the right Astribanks ticker:
285
LC_ALL=C xpp_sync "$XPP_SYNC"
291
#shutdown_dynamic # FIXME: needs test from someone with dynamic spans
292
echo -n "Unloading DAHDI hardware modules: "
293
if unload_modules; then
298
if [ "$LOCKFILE" != '' ]; then
299
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
305
restart|force-reload)
310
if [ $system = debian ]; then
311
echo -n "Rerunning dahdi_cfg: "
312
$DAHDI_CFG_CMD 2> /dev/null && echo -n "done"
314
elif [ $system = redhat ]; then
315
action "Rerunning dahdi_cfg: " $DAHDI_CFG_CMD
320
if [ -d /proc/dahdi ]; then
328
echo "Usage: dahdi {start|stop|restart|status|reload|unload}"