-
Notifications
You must be signed in to change notification settings - Fork 0
/
asterisk
executable file
·140 lines (130 loc) · 3.94 KB
/
asterisk
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
#!/bin/bash
# $Id$
#
# Mon Jun 04 2007 Iñaki Baz Castillo <ibc@in.ilimit.es>
# - Eliminated SAFE_ASTERISK since it doesn't work as LSB script (it could require a independent "safe_asterisk" init script).
# - Load and use the standar "/lib/lsb/init-functions".
# - Added "--oknodo" to "start-stop-daemon" for compatibility with LSB:
# http://www.linux-foundation.org/spec/refspecs/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
#
# Thu Nov 17 2005 Gregory Boehnlein <damin@nacs.net>
# - Reversed behavior of LD_ASSUME_KERNEL=2.4.1
# - Added detailed failure messages
#
# Sun Jul 18 2004 Gregory Boehnlein <damin@nacs.net>
# - Added test for safe_asterisk
# - Changed "stop gracefully" to "stop now"
# - Added support for -U and -G command line options
# - Modified "reload" to call asterisk -rx 'reload'
### BEGIN INIT INFO
# Provides: asterisk
# Required-Start: mysql
# Required-Stop: mysql
### END INIT INFO
set -e
if ! [ -x $DAEMON ] ; then
echo "ERROR: $DAEMON not found"
exit 0
fi
if ! [ -d $ASTETCDIR ] ; then
echo "ERROR: $ASTETCDIR directory not found"
exit 0
fi
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=asterisk
DESC="Asterisk PBX"
# Full path to asterisk binary
DAEMON=/usr/sbin/asterisk
ASTVARRUNDIR=/var/run/asterisk
ASTETCDIR=/etc/asterisk
TRUE=/bin/true
PIDFILE=/var/run/asterisk/asterisk.pid
# Use the LSB standard functions for services management
. /lib/lsb/init-functions
# Allow configuration overrides in /etc/default/asterisk
CONFIGFILE=/etc/default/$NAME
[ -f $CONFIGFILE ] && . $CONFIGFILE
function stop {
log_begin_msg "Stopping $DESC: $NAME"
# "start-stop-daemon --oknodo" returns 0 even if Asterisk was already stopped (as LSB expects):
start-stop-daemon --stop --oknodo --name $NAME --pidfile "$PIDFILE" -q
log_end_msg $?
}
function start {
# Check if Asterisk is already running. If it is, then bug out, because
# starting up Asterisk when Asterisk is already running is very bad.
VERSION=`${DAEMON} -rx 'core show version' 2>/dev/null || ${TRUE}`
if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
echo "Asterisk is already running. $0 will exit now."
exit 0
fi
log_begin_msg "Starting $DESC: $NAME"
if [ ! -d $ASTVARRUNDIR ]; then
mkdir -p $ASTVARRUNDIR
fi
if [ $AST_USER ] ; then
ASTARGS="-U $AST_USER"
chown $AST_USER $ASTVARRUNDIR
fi
if [ $AST_GROUP ] ; then
ASTARGS="$ASTARGS -G $AST_GROUP"
chgrp $AST_GROUP $ASTVARRUNDIR
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
# -v implies -f, so we override that implicit specification here
ASTARGS="$ASTARGS -F"
fi
if [ "x$INTERNALTIMING" = "xyes" ]; then
ASTARGS="$ASTARGS -I"
fi
if [ "x$TEMPRECORDINGLOCATION" = "xyes" -o "x$TMPRECORDINGLOCATION" = "xyes" ]; then
ASTARGS="$ASTARGS -t"
fi
if test "x$COLOR" = "xno" ; then
ASTARGS="$ASTARGS -n"
fi
# "start-stop-daemon --oknodo" returns 0 even if Asterisk was already running (as LSB expects):
start-stop-daemon --start --oknodo --pidfile "$PIDFILE" -q --exec $DAEMON -- $ASTARGS
log_end_msg $?
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
echo "Reloading $DESC configuration files."
$DAEMON -rx 'module reload' > /dev/null 2> /dev/null
;;
restart|force-reload)
stop
sleep 2 # It needs some time to really be stopped.
start
# "restart|force-reload" starts Asterisk and returns 0 even if Asterisk was stopped (as LSB expects).
;;
status)
start-stop-daemon --status --pidfile "$PIDFILE" --name "$name"
exit $?
;;
*)
echo "Usage: $0 {start|stop|restart|reload|force-reload|status}" >&2
exit 1
;;
esac