summaryrefslogtreecommitdiffhomepage
path: root/contrib/package/asterisk-xip/files/asterisk.init
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/package/asterisk-xip/files/asterisk.init')
-rwxr-xr-xcontrib/package/asterisk-xip/files/asterisk.init125
1 files changed, 125 insertions, 0 deletions
diff --git a/contrib/package/asterisk-xip/files/asterisk.init b/contrib/package/asterisk-xip/files/asterisk.init
new file mode 100755
index 000000000..64a7d906c
--- /dev/null
+++ b/contrib/package/asterisk-xip/files/asterisk.init
@@ -0,0 +1,125 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2006 OpenWrt.org
+START=50
+STOP=50
+
+DEST=
+OPTIONS=""
+DEFAULT=$DEST/etc/default/asterisk
+UCILIB=$DEST/usr/lib/asterisk/uci
+EXTRAPARAM=$1
+
+export EXTRA_COMMANDS="console check down"
+export EXTRA_HELP="\
+ console Start asterisk console
+ check Test asterisk uci config
+ down Force asterisk to stop"
+
+reboot_ata() {
+ cd /tmp
+ wget -q http://ata.lan/admin/reboot -O - >&- 2>&-
+}
+
+load_ucilib() . ${UCILIB}/asteriskuci
+
+start_uci() {
+ load_ucilib
+
+ start_uci_asterisk $DEST
+}
+restart_uci() {
+ load_ucilib
+
+ restart_uci_asterisk $DEST
+}
+
+stop_uci() {
+ load_ucilib
+
+ stop_uci_asterisk $DEST
+}
+reload_uci() {
+ load_ucilib
+
+ reload_uci_asterisk "$DEST"
+}
+
+start() {
+ [ -f $DEFAULT ] && . $DEFAULT
+ case ${ENABLE_ASTERISK-no} in
+ uci) start_uci ;;
+ yes)
+ [ -d /var/run ] || mkdir -p /var/run
+ [ -d $DEST/var/log/asterisk ] || mkdir -p $DEST/var/log/asterisk
+ [ -d $DEST/var/spool/asterisk ] || mkdir -p $DEST/var/spool/asterisk
+ [ -d /var/spool/asterisk ] || mkdir -p /var/spool/asterisk
+ [ -h $DEST/usr/lib/asterisk/astdb ] || ln -sf /var/spool/asterisk/astdb $DEST/usr/lib/asterisk/astdb
+ $DEST/usr/sbin/asterisk $OPTIONS -f 2>&1 > $DEST/var/log/asterisk/asterisk_proc &
+ ( sleep 5; reboot_ata ) &
+ ;;
+ *) return 1 ;;
+ esac
+}
+
+stop() {
+ [ -f $DEFAULT ] && . $DEFAULT
+ case ${ENABLE_ASTERISK} in
+ uci) stop_uci ;;
+ *) [ -f /var/run/asterisk.pid ] && kill $(cat /var/run/asterisk.pid) 2>&- >&-
+ esac
+}
+
+console() {
+ [ -f $DEFAULT ] && . $DEFAULT
+ case ${ENABLE_ASTERISK} in
+ uci) $DEST/usr/sbin/asterisk $UCIOPTIONS -C /tmp/asterisk/asterisk.conf -r ;;
+ yes) $DEST/usr/sbin/asterisk $OPTIONS -r ;;
+ esac
+
+}
+check() {
+ load_ucilib
+
+ setup_asterisk "$DEST" test "$EXTRAPARAM"
+}
+
+reload() {
+ [ -f $DEFAULT ] && . $DEFAULT
+ case ${ENABLE_ASTERISK-no} in
+ uci) reload_uci ;;
+ yes) restart ;;
+ esac
+
+}
+
+restart() {
+ [ -f $DEFAULT ] && . $DEFAULT
+ case ${ENABLE_ASTERISK-no} in
+ uci) restart_uci ;;
+ yes)
+ if [ -r /var/run/asterisk.ctl ] ; then
+ if $DEST/usr/sbin/asterisk -r -x "restart gracefully" 2>&- >&- ; then
+ echo "Restarting when convenient"
+ return 0
+ fi
+ fi
+ stop
+ start
+ esac
+}
+
+down() {
+ if [ -r /var/run/asterisk.ctl ] ; then
+ [ -f $DEFAULT ] && . $DEFAULT
+ case ${ENABLE_ASTERISK} in
+ uci) $DEST/usr/sbin/asterisk -C /tmp/asterisk/asterisk.conf -r -x "stop now" 2>&- >&- ;;
+ *) $DEST/usr/sbin/asterisk $OPTIONS -r -x "stop now" 2>&- >&-
+ esac
+ [ -f /var/run/asterisk.pid ] && sleep 1
+ fi
+ [ -f /var/run/asterisk.pid ] && kill $(cat /var/run/asterisk.pid) 2>&- >&-
+ [ -f /var/run/asterisk.pid ] && sleep 2
+ [ -f /var/run/asterisk.pid ] && kill -9 $(cat /var/run/asterisk.pid) 2>&- >&-
+}
+
+# vim:ts=2 sw=2