3
# asterisk start the asterisk PBX
4
# (c) Mark Purcell <msp@debian.org>
5
# May be distributed under the terms of this General Public License
9
# skeleton example file to build /etc/init.d/ scripts.
10
# This file should be used to construct scripts for /etc/init.d.
12
# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
13
# Modified for Debian GNU/Linux
14
# by Ian Murdock <imurdock@gnu.ai.mit.edu>.
16
# Version: @(#)skeleton 1.9 26-Feb-2001 miquels@cistron.nl
19
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
23
DAEMON=/usr/sbin/$NAME
25
PIDFILE="/var/run/asterisk/asterisk.pid"
27
# by default: use real-time priority
31
if [ -r /etc/default/$NAME ]; then . /etc/default/$NAME; fi
33
if [ "$RUNASTERISK" != "yes" ];then
34
echo "Asterisk not yet configured. Edit /etc/default/asterisk first."
38
if [ "$AST_REALTIME" != "no" ]
45
echo "Error: empty USER name"
48
if [ `id -u "$USER"` = 0 ]
50
echo "Starting as root not supported."
53
PARAMS="$PARAMS -U $USER"
55
if [ "x$AST_DEBUG_PARAMS" = x ]
57
AST_DEBUG_PARAMS=-cvvvvvddddd
59
if [ "$RUNASTSAFE" = "yes" ];then
60
# The value of WRAPPER_DAEMON in can be set in /etc/default/asterisk
61
WRAPPER_DAEMON=${WRAPPER_DAEMON:-/usr/sbin/safe_asterisk}
62
REALDAEMON="$WRAPPER_DAEMON"
67
test -x $DAEMON || exit 0
71
if [ ! -e `basename $PIDFILE` ];then
72
mkdir `basename $PIDFILE`
76
plist=`ps auxw | grep "$DAEMON" | grep -v grep | awk '{print $2}' | tr '\012' ' '`
77
if [ "$plist" = "" ]; then
78
echo "$DESC is stopped"
81
echo "$DESC is running: $plist"
88
# we add too many special parameters that I don't want to skip
89
# accidentally. I'm afraid that skipping -U once may cause
90
# confusing results. I also want to maintain the user's choice
92
echo "Debugging $DESC: "
93
$DAEMON $PARAMS $AST_DEBUG_PARAMS
97
if status > /dev/null; then
98
echo "$DESC is already running. Use restart."
101
echo -n "Starting $DESC: "
102
if [ "$RUNASTSAFE" != "yes" ];then
103
# TODO: what if we cought the wrapper just as its asterisk
104
# was killed? status should check for the wrapper if we're in
106
if status > /dev/null; then
107
echo "$DESC is already running. Use restart."
111
echo -n "Starting $DESC: "
112
start-stop-daemon --start --group $GROUP --pidfile "$PIDFILE" \
113
--exec $REALDAEMON -- $PARAMS
117
echo -n "Stopping $DESC: "
118
if [ "$RUNASTSAFE" = "yes" ];then
119
# hopefully this will work. Untested
120
$REALDAEMON -rx 'stop now' > /dev/null || true
123
# this may hang in some cases. Specifically, when the asterisk
124
# processes is stopped. No bother to worry about cleanup:
125
# it will either fail or die when asterisk dies.
126
( $DAEMON -rx 'stop now' > /dev/null 2>&1 & ) &
129
## giving a small grace time to shut down cleanly.
130
#sleep 2 # you can add timeouts in the comma
131
if [ "$RUNASTSAFE" = "yes" ];then
132
start-stop-daemon --quiet --oknodo --stop --exec $WRAPPER_DAEMON
134
# just making sure it's really, really dead.
135
# KILL is necessary just in case there's an asterisk -r in the background
136
start-stop-daemon --stop --quiet --oknodo --retry=0/2/TERM/2/KILL/5 --exec $REALDAEMON
140
echo "Reloading $DESC configuration files."
144
$DAEMON -rx 'logger reload'
147
echo "Reloading $DESC configuration files."
148
$DAEMON -rx 'extensions reload'
150
restart|force-reload)
160
# echo "Usage: $N {start|stop|restart|reload|logger-reload|extensions-reload|force-reload}" >&2
161
echo "Usage: $N {start|stop|status|debug|restart|force-reload}" >&2