[package] siproxd: update to 0.8.1
[openwrt/svn-archive/archive.git] / net / siproxd / files / siproxd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 Alina Friedrichsen
3 # Copyright (C) 2011 OpenWrt.org
4
5 START=50
6 siproxd_bin="/usr/sbin/siproxd"
7 siproxd_conf_dir="/var/etc/"
8 siproxd_conf_prefix="$siproxd_conf_dir"siproxd-
9 siproxd_registration_dir="/var/lib/siproxd/"
10 siproxd_pid_dir="/var/run/"
11
12 start_instance()
13 {
14 local cfg="$1"
15 config_get if_inbound "$cfg" if_inbound
16 config_get if_outbound "$cfg" if_outbound
17 config_get host_outbound "$cfg" host_outbound
18 config_get hosts_allow_reg "$cfg" hosts_allow_reg
19 config_get hosts_allow_sip "$cfg" hosts_allow_sip
20 config_get hosts_deny_sip "$cfg" hosts_deny_sip
21 config_get sip_listen_port "$cfg" sip_listen_port 5060
22 config_get_bool daemonize "$cfg" daemonize 1
23 config_get silence_log "$cfg" silence_log 4
24 config_get user "$cfg" user nobody
25 config_get chrootjail "$cfg" chrootjail
26 config_get registration_file "$cfg" registration_file "$siproxd_registration_dir"siproxd_registrations-"$cfg"
27 config_get autosave_registrations "$cfg" autosave_registrations 300
28 config_get pid_file "$cfg" pid_file "$siproxd_pid_dir"siproxd-"$cfg".pid
29 config_get_bool rtp_proxy_enable "$cfg" rtp_proxy_enable 1
30 config_get rtp_port_low "$cfg" rtp_port_low 7070
31 config_get rtp_port_high "$cfg" rtp_port_high 7089
32 config_get rtp_timeout "$cfg" rtp_timeout 300
33 config_get rtp_dscp "$cfg" rtp_dscp 46
34 config_get default_expires "$cfg" default_expires 600
35 config_get proxy_auth_realm "$cfg" proxy_auth_realm
36 config_get proxy_auth_passwd "$cfg" proxy_auth_passwd
37 config_get proxy_auth_pwfile "$cfg" proxy_auth_pwfile
38 config_get debug_level "$cfg" debug_level 0x00000000
39 config_get debug_port "$cfg" debug_port 0
40 config_get mask_host "$cfg" mask_host
41 config_get masked_host "$cfg" masked_host
42 config_get ua_string "$cfg" ua_string Siproxd-UA
43 config_get use_rport "$cfg" use_rport 0
44 config_get outbound_proxy_host "$cfg" outbound_proxy_host
45 config_get outbound_proxy_port "$cfg" outbound_proxy_port
46 config_get outbound_domain_name "$cfg" outbound_domain_name
47 config_get outbound_domain_host "$cfg" outbound_domain_host
48 config_get outbound_domain_port "$cfg" outbound_domain_port
49
50 if [ ! -d "$siproxd_conf_dir" ]; then
51 mkdir -p "$siproxd_conf_dir"
52 chmod 0755 "$siproxd_conf_dir"
53 fi
54 if [ -f "$siproxd_conf_prefix$cfg" ]; then
55 rm "$siproxd_conf_prefix$cfg"
56 fi
57 if [ -n "$if_inbound" ]; then
58 echo if_inbound = "$if_inbound" >> "$siproxd_conf_prefix$cfg"
59 fi
60 if [ -n "$if_outbound" ]; then
61 echo if_outbound = "$if_outbound" >> "$siproxd_conf_prefix$cfg"
62 fi
63 if [ -n "$host_outbound" ]; then
64 echo host_outbound = "$host_outbound" >> "$siproxd_conf_prefix$cfg"
65 fi
66 if [ -n "$hosts_allow_reg" ]; then
67 echo hosts_allow_reg = "$hosts_allow_reg" >> "$siproxd_conf_prefix$cfg"
68 fi
69 if [ -n "$hosts_allow_sip" ]; then
70 echo hosts_allow_sip = "$hosts_allow_sip" >> "$siproxd_conf_prefix$cfg"
71 fi
72 if [ -n "$hosts_deny_sip" ]; then
73 echo hosts_deny_sip = "$hosts_deny_sip" >> "$siproxd_conf_prefix$cfg"
74 fi
75 echo sip_listen_port = "$sip_listen_port" >> "$siproxd_conf_prefix$cfg"
76 echo daemonize = "$daemonize" >> "$siproxd_conf_prefix$cfg"
77 echo silence_log = "$silence_log" >> "$siproxd_conf_prefix$cfg"
78 echo user = "$user" >> "$siproxd_conf_prefix$cfg"
79 if [ -n "$chrootjail" ]; then
80 if [ ! -d "$chrootjail" ]; then
81 mkdir -p "$chrootjail"
82 chmod 0755 "$chrootjail"
83 fi
84 echo chrootjail = "$chrootjail" >> "$siproxd_conf_prefix$cfg"
85 fi
86 if [ ! -d "$siproxd_registration_dir" ]; then
87 mkdir -p "$siproxd_registration_dir"
88 chmod 0755 "$siproxd_registration_dir"
89 fi
90 echo registration_file = "$registration_file" >> "$siproxd_conf_prefix$cfg"
91 echo autosave_registrations = "$autosave_registrations" >> "$siproxd_conf_prefix$cfg"
92 if [ ! -d "$siproxd_pid_dir" ]; then
93 mkdir -p "$siproxd_pid_dir"
94 chmod 0755 "$siproxd_pid_dir"
95 fi
96 echo pid_file = "$pid_file" >> "$siproxd_conf_prefix$cfg"
97 echo rtp_proxy_enable = "$rtp_proxy_enable" >> "$siproxd_conf_prefix$cfg"
98 echo rtp_port_low = "$rtp_port_low" >> "$siproxd_conf_prefix$cfg"
99 echo rtp_port_high = "$rtp_port_high" >> "$siproxd_conf_prefix$cfg"
100 echo rtp_timeout = "$rtp_timeout" >> "$siproxd_conf_prefix$cfg"
101 echo rtp_dscp = "$rtp_dscp" >> "$siproxd_conf_prefix$cfg"
102 echo default_expires = "$default_expires" >> "$siproxd_conf_prefix$cfg"
103 if [ -n "$proxy_auth_realm" ]; then
104 echo proxy_auth_realm = "$proxy_auth_realm" >> "$siproxd_conf_prefix$cfg"
105 fi
106 if [ -n "$proxy_auth_passwd" ]; then
107 echo proxy_auth_passwd = "$proxy_auth_passwd" >> "$siproxd_conf_prefix$cfg"
108 fi
109 if [ -n "$proxy_auth_pwfile" ]; then
110 echo proxy_auth_pwfile = "$proxy_auth_pwfile" >> "$siproxd_conf_prefix$cfg"
111 fi
112 echo debug_level = "$debug_level" >> "$siproxd_conf_prefix$cfg"
113 echo debug_port = "$debug_port" >> "$siproxd_conf_prefix$cfg"
114 if [ -n "$mask_host" ]; then
115 echo mask_host = "$mask_host" >> "$siproxd_conf_prefix$cfg"
116 fi
117 if [ -n "$masked_host" ]; then
118 echo masked_host = "$masked_host" >> "$siproxd_conf_prefix$cfg"
119 fi
120 echo ua_string = "$ua_string" >> "$siproxd_conf_prefix$cfg"
121 echo use_rport = "$use_rport" >> "$siproxd_conf_prefix$cfg"
122 if [ -n "$outbound_proxy_host" ]; then
123 echo oubound_proxy_host = "$outbound_proxy_host" >> "$siproxd_conf_prefix$cfg"
124 fi
125 if [ -n "$outbound_proxy_port" ]; then
126 echo outbound_proxy_port = "$outbound_proxy_port" >> "$siproxd_conf_prefix$cfg"
127 fi
128 if [ -n "$outbound_domain_name" ]; then
129 echo outbound_domain_name = "$outbound_domain_name" >> "$siproxd_conf_prefix$cfg"
130 fi
131 if [ -n "$outbound_domain_host" ]; then
132 echo outbound_domain_host = "$outbound_domain_host" >> "$siproxd_conf_prefix$cfg"
133 fi
134 if [ -n "$outbound_domain_port" ]; then
135 echo outbound_domain_port = "$outbound_domain_port" >> "$siproxd_conf_prefix$cfg"
136 fi
137
138 $siproxd_bin --config "$siproxd_conf_prefix$cfg"
139 }
140
141 stop_instance()
142 {
143 local cfg="$1"
144
145 [ -f "$siproxd_pid_dir"siproxd-"$cfg".pid ] && {
146 start-stop-daemon -K -q -n ${siproxd_bin##*/} \
147 -p "$siproxd_pid_dir"siproxd-"$cfg".pid -s TERM
148
149 rm "$siproxd_pid_dir"siproxd-"$cfg".pid
150 }
151 }
152
153 start() {
154 config_load siproxd
155 config_foreach start_instance siproxd
156 }
157
158 stop() {
159 config_load siproxd
160 config_foreach stop_instance siproxd
161 # for case when pid file was not written
162 # because of permission issues
163 pkill ${siproxd_bin##*/}
164 }