net/chan-sccp-b: version bump and fixes
[feed/telephony.git] / net / rtpproxy / files / rtpproxy.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2014 CESNET, z.s.p.o
3
4 START=99
5 RTPPROXY_BIN="/usr/bin/rtpproxy"
6
7 run_instance(){
8 local params="$1"
9
10 ${RTPPROXY_BIN} $1
11 echo "[INFO] rtpproxy instance $2 has started"
12 }
13
14 check_param(){
15 local param="$1"
16 local value="$2"
17 local default_value="$3"
18
19 if [ "$value" != "" ]; then
20 rtpproxy_options=$rtpproxy_options" $param $value"
21 else
22 if [ "$default_value" != "" ]; then
23 rtpproxy_options=$rtpproxy_options" $param $default_value"
24 fi
25 fi
26 }
27
28 check_special_param(){
29 local param="$1"
30
31 if [ "$param" != "" ]; then
32 rtpproxy_options=$rtpproxy_options" $param"
33 fi
34 }
35
36 handle_instance() {
37 local site="$1"
38 local socket opts ipaddr ip6addr rtpproxy_options
39
40 config_get socket "$site" socket
41 config_get opts "$site" opts
42 config_get ipaddr "$site" ipaddr
43 config_get ip6addr "$site" ip6addr
44 config_get user "$site" user
45
46 check_param "-s" "$socket"
47 check_param "-l" "$ipaddr"
48 check_param "-6" "$ip6addr"
49 check_param "-u" "$user" "nobody"
50 check_special_param "$opts"
51
52 run_instance "$rtpproxy_options" "$site"
53 }
54
55 start(){
56 config_load rtpproxy
57 local section="global"
58 config_get_bool enabled global enabled 0
59
60 if [ "$enabled" -eq 1 ]; then
61 config_foreach handle_instance instance
62 else
63 echo "[WARNING] rtpproxy not yet configured. Edit /etc/config/rtpproxy first."
64 fi
65 }
66
67 stop() {
68 killall rtpproxy
69 }
70