#! /bin/sh
#
# asterisk start the asterisk PBX
# (c) Mark Purcell <[email protected]>
# 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 <[email protected]>.
# Modified for Debian GNU/Linux
# by Ian Murdock <[email protected]>.
#
# Version: @(#)skeleton 1.9 26-Feb-2001 [email protected]
#
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 [ "$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: "
# By Fant (bei bei eingebauten HFC-Karte)
#/sbin/modprobe crc-ccitt
#/sbin/insmod "/lib/modules/`uname -r`/misc/zaptel.ko" || exit 1
# Für 2 Karten (NT+TE)
#/sbin/insmod "/lib/modules/`uname -r`/misc/zaphfc.ko" modes=2 || exit
# Für eine Karte (NT)
#/sbin/insmod "/lib/modules/`uname -r`/misc/zaphfc.ko" modes=1 || exit
#/sbin/ztcfg -v
#chown asterisk /dev/zap/*
#sleep 5
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
# by Fant
#rmmod zaphfc
#rmmod zaptel
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