#!/sbin/runscript # Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/net-misc/asterisk/files/1.0.0/asterisk.rc6.sec,v 1.3 2005/05/31 23:19:56 stkn Exp $ depend() { need net use zaptel } start() { local OPTS USER GROUP if [[ -n "${ASTERISK_NICE}" ]]; then if [[ ${ASTERISK_NICE} -ge -20 ]] && \ [[ ${ASTERISK_NICE} -le 19 ]]; then OPTS="--nicelevel ${ASTERISK_NICE}" else eerror "Nice value must be between -20 and 19" fi fi if [[ -n "${ASTERISK_USER}" ]]; then USER=${ASTERISK_USER/:*/} GROUP=$(echo $ASTERISK_USER | awk -F: '/.*:.*/ { print $2 }') if [[ -n "${USER}" ]]; then ASTERISK_OPTS="${ASTERISK_OPTS} -U ${USER}" fi if [[ -n "${GROUP}" ]]; then ASTERISK_OPTS="${ASTERISK_OPTS} -G ${GROUP}" GROUP=":${GROUP}" # make it look nice... fi ebegin "Starting asterisk PBX (as ${USER}${GROUP})" else ebegin "Starting asterisk PBX (as root)" fi start-stop-daemon --start --exec /usr/sbin/asterisk \ ${OPTS} -- ${ASTERISK_OPTS} eend $? } stop() { ebegin "Stopping asterisk PBX" PID=`cat /var/run/asterisk/asterisk.pid 2>/dev/null` start-stop-daemon --stop --pidfile /var/run/asterisk/asterisk.pid # Now we have to wait until asterisk has _really_ stopped. sleep 2 if test -n "$PID" && kill -0 $PID 2>/dev/null then einfon "Waiting ." cnt=0 while kill -0 $PID 2>/dev/null do cnt=`expr $cnt + 1` if [ $cnt -gt 60 ] then # Waited 120 seconds now. Fail. eend 1 "Failed." break fi sleep 2 echo -n "." done echo -n "done." eend 0 else eend 0 fi }