~singpolyma/asterisk

ref: upstream/16.2.1_dfsg asterisk/contrib/init.d/rc.suse.asterisk -rwxr-xr-x 4.1 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
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
#!/bin/sh
# $Id: asterisk,v 1.3 2005/11/17 22:30:01 Gregory Boehnlein <damin@nacs.net>
#
# asterisk    Starts, Stops and Reloads Asterisk.
#
# chkconfig: 2345 40 60
# description: Asterisk PBX and telephony daemon.
# processname: asterisk
# pidfile: /var/run/asterisk.pid
#
# Thu Nov 17 2005 Gregory Boehnlein <damin@nacs.net>
# - Updated Version to 1.3
# - Reversed behavior of LD_ASSUME_KERNEL=2.4.1
# - Added detailed failure messages
#
# Sun Jul 18 2004 Gregory Boehnlein <damin@nacs.net>
# - Updated Version to 1.2
# - Added test for safe_asterisk
# - Verified SIGTERM issued by "killproc" ensures "stop gracefully"
# - Added support for -U and -G command line options
# - Modified "reload" to call asterisk -rx 'reload'

### BEGIN INIT INFO
# Provides:		asterisk
# Required-Start:    $network $syslog $named $local_fs $remote_fs
# Required-Stop:     $network $syslog $named $local_fs $remote_fs
# Should-Start:      dahdi misdn lcr wanrouter mysql postgresql
# Should-Stop:       dahdi misdn lcr wanrouter mysql postgresql
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Short-Description:	Asterisk PBX
# Description:		the Asterisk Open Source PBX
### END INIT INFO

# Source function library.
. /lib/lsb/init-functions

if ! [ -x /usr/sbin/asterisk ] ; then
	echo "ERROR: /usr/sbin/asterisk not found"
	exit 0
fi

if ! [ -d /etc/asterisk ] ; then
	echo "ERROR: /etc/asterisk directory not found"
	exit 0
fi

# Uncomment this ONLY if you know what you are doing.
# export LD_ASSUME_KERNEL=2.4.1

# Full path to asterisk binary
DAEMON=/usr/sbin/asterisk

# Full path to safe_asterisk script
SAFE_ASTERISK=/usr/sbin/safe_asterisk

# Uncomment the following and set them to the user/groups that you
# want to run Asterisk as. NOTE: this requires substantial work to
# be sure that Asterisk's environment has permission to write the
# files required  for  its  operation, including logs, its comm
# socket, the asterisk database, etc.
#AST_USER="asterisk"
#AST_GROUP="asterisk"

# Allow configuration overrides in /etc/sysconfig/asterisk
CONFIG0=`readlink $0`
if [ "$CONFIG0" = "" ]; then
	CONFIGFILE=/etc/sysconfig/`basename $0`
else
	CONFIGFILE=/etc/sysconfig/`basename $CONFIG0`
fi
[ -r $CONFIGFILE ] && . $CONFIGFILE

RETVAL=0

start() {
	# Start daemons.

	# Check if Asterisk is already running.  If it is, then bug out, because
	# starting Asterisk when Asterisk is already running is very bad.
	VERSION=`/usr/sbin/asterisk -rx 'core show version' 2>/dev/null`
	if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
		echo "Asterisk is already running.  $0 will exit now."
		exit 1
	fi

	echo -n $"Starting asterisk: "
        if [ -f $SAFE_ASTERISK ] ; then
		DAEMON=$SAFE_ASTERISK
	fi
	if [ $AST_USER ] ; then
		ASTARGS="-U $AST_USER"
	fi
	if [ $AST_GROUP ] ; then
		ASTARGS="`echo $ASTARGS` -G $AST_GROUP"
	fi
	if [ $ALTCONF ]; then
		ASTARGS="$ASTARGS -C $ALTCONF"
	fi
	if [ "x$COREDUMP" = "xyes" ]; then
		ASTARGS="$ASTARGS -g"
	fi
	if [ "0$MAXLOAD" -gt "0" ]; then
		ASTARGS="$ASTARGS -L $MAXLOAD"
	fi
	if [ "0$MAXCALLS" -gt "0" ]; then
		ASTARGS="$ASTARGS -M $MAXCALLS"
	fi
	if [ "0$VERBOSITY" -gt "0" ]; then
		for i in `seq 1 $VERBOSITY`; do
			ASTARGS="$ASTARGS -v"
		done
	fi
	if [ "x$INTERNALTIMING" = "xyes" ]; then
		ASTARGS="$ASTARGS -I"
	fi
	if [ "x$TEMPRECORDINGLOCATION" = "xyes" -o "x$TMPRECORDINGLOCATION" = "xyes" ]; then
		ASTARGS="$ASTARGS -t"
	fi
	if [ "x$COLOR" = "xyes" ]; then
		export TERM=linux
		sh -c "$DAEMON $ASTARGS -c" >/dev/null </dev/null 2>&1 &
	else
		$DAEMON $ASTARGS
	fi
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/asterisk
	echo
	return $RETVAL
}

stop() {
	# Stop daemons.
	echo -n $"Shutting down asterisk: "
	killproc asterisk
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/asterisk
	echo
	return $RETVAL
}

restart() {
	stop
	start
}

reload() {
	$DAEMON -rx 'module reload' > /dev/null 2> /dev/null
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	restart
	;;
  reload)
	reload
	;;
  condrestart)
	[ -f /var/lock/subsys/asterisk ] && restart || :
	;;
  status)
	status asterisk
	;;
  *)
	echo "Usage: asterisk {start|stop|restart|reload|condrestart|status}"
	exit 1
esac

exit $?