# asterix This shell script takes care of starting and stopping
# Asterisk PBX
#
-# chkconfig: 345 90 25
+# chkconfig: 345 90 10
#
# description: Asterisk is an Open Source PBX and telephony development platform that \ \
# can both replace a conventional PBX and act as a platform for \
# content over a telephone similarly to how one can deliver dynamic \
# content through a web browser using CGI and a web server.
#
-# pidfile: /var/run/asterisk.pid
+# pidfile: /var/run/asterisk/asterisk.pid
# config: /etc/asterisk/asterisk.conf
-
-# Sanity check
-[ -f /etc/asterisk/asterisk.conf ] || exit 0
-
# Source function library
. /etc/rc.d/init.d/functions
# Get network config
. /etc/sysconfig/network
+# Specify the configuration file
+AST_CONFIG=/etc/asterisk/asterisk.conf
+
+# The user that Asterisk will run as.
+AST_USER="asterisk"
+
+# If a user is specified above, Asterisk will change the group it runs
+# as to the primary group of the user, as well as initialize the
+# supplementary groups. If you want to run Asterisk as a different
+# group, set AST_GROUP to the group that Asterisk should run as. Note
+# that this may break DAHDI devices as supplementary groups will not
+# be initialized.
+#AST_GROUP="asterisk"
+
# Get service config
[ -f /etc/sysconfig/asterisk ] && . /etc/sysconfig/asterisk
fi
msg_starting "Asterisk"
- daemon /usr/sbin/asterisk $ASTERISK_OPTS
+ if [ $AST_USER ] ; then
+ AST_ARGS="-U $AST_USER"
+ fi
+ if [ $AST_GROUP ] ; then
+ AST_ARGS="$AST_ARGS -G $AST_GROUP"
+ fi
+ if [ $AST_CONFIG ]; then
+ AST_ARGS="$AST_ARGS -C $AST_CONFIG"
+ fi
+ daemon /usr/sbin/asterisk -F $AST_ARGS $ASTERISK_OPTS
+
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/asterisk
}
rm -f /var/lock/subsys/asterisk >/dev/null 2>&1
}
+condrestart() {
+ if [ ! -f /var/lock/subsys/asterisk ]; then
+ msg_not_running "Asterisk"
+ RETVAL=$1
+ return
+ fi
+
+ stop
+ start
+}
+
+reload() {
+ if [ ! -f /var/lock/subsys/asterisk ]; then
+ msg_not_running "Asterisk"
+ RETVAL=1
+ return
+ fi
+
+ msg_reloading "Asterisk"; busy
+ /usr/sbin/asterisk -rx reload > /dev/null 2>&1
+ RETVAL=$?
+ if [ $RETVAL -eq 0 ]; then
+ touch /var/lock/subsys/asterisk
+ ok
+ else
+ fail
+ fi
+}
+
+ael-reload() {
+ local res
+ res=$(aelparse -n -q | grep -F Error)
+ if [ "$res" ]; then
+ echo >&2 "$res"
+ RETVAL=1
+ return
+ fi
+
+ if [ ! -f /var/lock/subsys/asterisk ]; then
+ msg_not_running "Asterisk"
+ RETVAL=1
+ return
+ fi
+
+ /usr/sbin/asterisk -rx "ael reload"
+}
+
RETVAL=0
# See how we were called.
case "$1" in
start)
- start
+ start
;;
stop)
- stop
+ stop
;;
- restart|force-reload)
+ restart)
stop
start
;;
- reload)
- if [ -f /var/lock/subsys/asterisk ]; then
- msg_reloading "Asterisk"
- busy
- /usr/sbin/asterisk -rx reload > /dev/null 2>&1
- RETVAL=$?
- [ $RETVAL -eq 0 ] && touch /var/lock/subsys/asterisk
- ok
- else
- msg_not_running "Asterisk"
- exit 1
- fi
+ try-restart)
+ condrestart 0
+ ;;
+ reload|force-reload)
+ reload
+ ;;
+ dialplan-reload)
+ /usr/sbin/asterisk -rx "dialplan reload"
+ ;;
+ ael-reload)
+ ael-reload
;;
logger-reload)
- /usr/sbin/asterisk -rx "logger reload"
- ;;
+ /usr/sbin/asterisk -rx "logger reload"
+ ;;
status)
status asterisk
exit $?
;;
*)
- msg_usage "$0 {start|stop|restart|force-reload|status}"
+ msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|dialplan-reload|ael-reload|logger-reload|status}"
exit 3
esac