10659712a0360b7e771654feaa1f2add961749b9
[packages.git] / utils / bandwidthd / files / bandwidthd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 OpenWrt.org
3 START=99
4
5 config_cb() {
6         local cfg_type="$1"
7         local cfg_name="$2"
8
9         case "$cfg_type" in
10                 bandwidthd)
11                         append cfgs "$cfg_name"
12                 ;;
13         esac
14 }
15
16 start() {
17         [ -d /tmp/bandwidthd ] || mkdir -p /tmp/bandwidthd && cp /www/legend.gif /tmp/bandwidthd/
18         [ -e /htdocs ] || ln -s /tmp/bandwidthd /htdocs
19         [ -e /www/bandwidthd ] || ln -s /tmp/bandwidthd /www/bandwidthd
20         rm -f /tmp/bandwidthd.conf
21         touch /tmp/bandwidthd.conf
22         [ -e /etc/bandwidthd.conf ] || ln -s /tmp/bandwidthd.conf /etc/bandwidthd.conf
23         
24         
25         config_load bandwidthd
26         for cfg in $cfgs; do
27                 config_get interface $cfg interface
28                 config_get subnets $cfg interface
29                 config_get skip_intervals $cfg skip_intervals
30                 config_get graph_cutoff $cfg graph_cutoff
31                 config_get promiscuous $cfg promiscuous
32                 config_get output_cdf $cfg output_cdf
33                 config_get recover_cdf $cfg recover_cdf
34                 config_get filter $cfg filter
35                 config_get graph $cfg graph
36                 config_get meta_refresh $cfg meta_refresh
37                         for subnet in $subnets; do
38                                 echo "subnet $subnet">> /tmp/bandwidthd.conf
39                         done
40                 cat >> /tmp/bandwidthd.conf <<EOF
41 ${interface:+ dev "$interface"}
42 ${skip_intervals:+ skip_intervals $skip_intervals}
43 ${graph_cutoff:+ graph_cutoff $graph_cutoff}
44 ${promiscuous:+ promiscuous $promiscuous}
45 ${output_cdf:+ output_cdf $output_cdf}
46 ${recover_cdf:+ recover_cdf $recover_cdf}
47 ${filter:+ filter $filter}
48 ${graph:+ graph $graph}
49 ${meta_refresh:+ meta_refresh $meta_refresh}
50 EOF
51         done
52         cd /
53         bandwidthd
54 }
55
56 stop() {
57         killall bandwidthd
58 }