~singpolyma/asterisk

ref: upstream/16.2.1_dfsg asterisk/contrib/init.d/rc.mandriva.zaptel -rwxr-xr-x 1.9 KiB
fe6d69c0Stephen Paul Weber import-tar 9 months ago
                                                                                
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
#!/bin/sh
#
# DAHDI:       Loads Asterisk modules
#
# Version:      @(#) /etc/rc.d/init.d/dahdi 1.0
#
# chkconfig: 2345 90 10
# description: Loads and unloads DAHDI modules at boot time and shutdown.
#
# hide: true

# $Id$

# Source function library.
. /etc/rc.d/init.d/functions

# Default modules - override in /etc/sysconfig/dahdi
######################################
MODULES="usb-uhci dahdi wcfxo wcusb"
######################################

# Resolve back to the basename (i.e. dahdi, not S90dahdi)
if [ 0`readlink $0` = "0" ]; then
	CONFIGFILE=/etc/sysconfig/`basename $0`
else
	CONFIG0=`readlink $0`
	CONFIGFILE=/etc/sysconfig/`basename $CONFIG0`
fi

[ -f $CONFIGFILE ] && . $CONFIGFILE

function probe() {
	gprintf "                           $1"
	modprobe -i $1
	# It has to be in the module list, otherwise something is wrong
	if lsmod | grep -c ^$1 >/dev/null; then
		success
	else
		failure
	fi
	echo
}

function unprobe() {
	gprintf "                           $1"
	rmmod $1 >/dev/null 2>&1
	# If it's still in the module list after removing it, there's something wrong.
	if lsmod | grep -c ^$1 >/dev/null; then
		failure
	else
		success
	fi
	echo
}

function reverse_modules() {
	tmp=$MODULES
	MODULES=''
	for i in $tmp; do
		MODULES="$i $MODULES" ;
	done
}

# See how we were called.
case "$1" in
  start)
	gprintf "Loading Asterisk modules:\n"
	for i in $MODULES; do
		probe $i
		usleep 100000 ;
	done
	ztcfg
	;;
  stop)
	gprintf "Unloading Asterisk modules:\n"
	reverse_modules
	for i in $MODULES; do
		unprobe $i
		usleep 100000 ;
	done
	;;
  status)
  	#ztcfg -vv
	OK=1
	gprintf "Checking Asterisk modules"
	for i in $MODULES; do
		if [ `lsmod | grep -c $i` -eq 0 ]; then
			OK=0
		fi
	done
	if [ $OK -gt 0 ]; then
		success
	else
		failure
	fi
	echo
	;;
  restart)
  	$0 stop
	$0 start
	;;
  *)
	gprintf "*** Usage: $0 {start|stop|status|restart}\n"
	exit 1
esac

exit 0