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
|
#! /bin/sh
#
# asterisk start the asterisk PBX
# (c) Mark Purcell <msp@debian.org>
# May be distributed under the terms of this General Public License
#
# Based on:
#
# skeleton example file to build /etc/init.d/ scripts.
# This file should be used to construct scripts for /etc/init.d.
#
# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
# Modified for Debian GNU/Linux
# by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version: @(#)skeleton 1.9 26-Feb-2001 miquels@cistron.nl
#
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=asterisk
USER=$NAME
DESC="Asterisk PBX"
PIDFILE="/var/run/asterisk/asterisk.pid"
# by default: use real-time priority
PARAMS=""
AST_REALTIME="yes"
RUNASTERISK="no"
MODULEINIT=""
if [ -r /etc/default/asterisk ]; then . /etc/default/asterisk; fi
if [ "$RUNASTERISK" != "yes" ];then
echo "Asterisk not yet configured. Edit /etc/default/asterisk first."
exit 1
fi
if [ "$AST_REALTIME" != "no" ]
then
PARAMS="$PARAMS -p"
fi
if [ "x$USER" = "x" ]
then
echo "Error: empty USER name"
exit 1
fi
if [ `id -u "$USER"` = 0 ]
then
echo "Starting as root not supported."
exit 1
fi
PARAMS="$PARAMS -U $USER"
if [ "x$RUNASTSAFE" = "xyes" ];then
DAEMON=/usr/sbin/safe_asterisk
REALDAEMON=/usr/sbin/asterisk
else
DAEMON=/usr/sbin/asterisk
fi
test -x $DAEMON || exit 0
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --pidfile "$PIDFILE" --exec $DAEMON -- $PARAMS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
if [ "$RUNASTSAFE" = "yes" ];then
# hopefully this will work. Untested
$REALDAEMON -rx 'stop now' > /dev/null || true
else
# Try gracefully
$DAEMON -rx 'stop now' > /dev/null 2>&1 || true
fi
echo -n "$NAME"
# giving a small grace time to shut down cleanly.
sleep 2
if [ "$RUNASTSAFE" = "yes" ];then
start-stop-daemon --quiet --oknodo --stop --exec $DAEMON
fi
# just making sure it's really, really dead.
# KILL is necessary just in case there's an asterisk -r in the background
start-stop-daemon --stop --quiet --oknodo --retry=0/2/TERM/2/KILL/5 --exec $DAEMON
echo "."
;;
reload)
echo "Reloading $DESC configuration files."
$DAEMON -rx 'reload'
;;
logger-reload)
$DAEMON -rx 'logger reload'
;;
extensions-reload)
echo "Reloading $DESC configuration files."
$DAEMON -rx 'extensions reload'
;;
restart|force-reload)
$0 stop
$0 start
;;
*)
N=/etc/init.d/$NAME
# echo "Usage: $N {start|stop|restart|reload|logger-reload|extensions-reload|force-reload}" >&2
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
|