summaryrefslogtreecommitdiffhomepage
path: root/contrib/package/asterisk-xip/files/asterisk.init
blob: 64a7d906ca7dd192fa11ae5e22393c8766732d8e (plain)
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
114
115
116
117
118
119
120
121
122
123
124
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