bandwidthd.init (2269B)
1 #!/bin/sh /etc/rc.common 2 # Copyright (C) 2008-2017 OpenWrt.org 3 4 START=99 5 6 USE_PROCD=1 7 8 CONFIGNAME="bandwidthd" 9 CONFIGFILE="/tmp/etc/bandwidthd.conf" 10 11 config_cb() { 12 local cfg_type="$1" 13 local cfg_name="$2" 14 15 case "$cfg_type" in 16 bandwidthd) 17 append cfgs "$cfg_name" 18 ;; 19 esac 20 } 21 22 export_bool() { 23 local option="$1" 24 local section="$2" 25 local _loctmp 26 config_get_bool _loctmp "$section" "$option" 27 if [ -n "$_loctmp" ]; then 28 conffile="${conffile}$option " 29 if [ 1 -eq "$_loctmp" ]; then 30 conffile="${conffile}true" 31 else 32 conffile="${conffile}false" 33 fi 34 conffile="${conffile}\n" 35 fi 36 } 37 38 export_number() { 39 local option="$1" 40 local section="$2" 41 local _loctmp 42 config_get _loctmp "$section" "$option" 43 if [ -n "$_loctmp" ]; then 44 conffile="${conffile}$option ${_loctmp}\n" 45 fi 46 } 47 48 export_string() { 49 local option="$1" 50 local section="$2" 51 local _loctmp 52 config_get _loctmp "$section" "$option" 53 if [ -n "$_loctmp" ]; then 54 conffile="${conffile}$option \"${_loctmp}\"\n" 55 fi 56 } 57 58 set_conf_file() { 59 local subnet conffile 60 61 [ -d /tmp/bandwidthd ] || mkdir -p /tmp/bandwidthd && cp /www/legend.gif /www/logo.gif /tmp/bandwidthd/ 62 [ -e /htdocs ] || ln -s /tmp/bandwidthd /htdocs 63 [ -e /www/bandwidthd ] || ln -s /tmp/bandwidthd /www/bandwidthd 64 rm -f $CONFIGFILE 65 touch $CONFIGFILE 66 [ -e /etc/bandwidthd.conf ] || ln -s $CONFIGFILE /etc/bandwidthd.conf 67 68 config_load $CONFIGNAME 69 for cfg in $cfgs; do 70 config_get subnets $cfg subnets 71 for subnet in $subnets; do 72 conffile="${conffile}subnet ${subnet}\n" 73 done 74 export_string dev $cfg 75 export_number skip_intervals $cfg 76 export_number graph_cutoff $cfg 77 export_bool promiscuous $cfg 78 export_bool output_cdf $cfg 79 export_bool recover_cdf $cfg 80 export_string filter $cfg 81 export_bool graph $cfg 82 export_number meta_refresh $cfg 83 export_string pgsql_connect_string $cfg 84 export_string sqlite_filename $cfg 85 export_string sensor_id $cfg 86 [ -n "$conffile" ] && echo -e "$conffile" >>$CONFIGFILE 87 unset conffile 88 done 89 cd / 90 } 91 92 service_triggers() 93 { 94 procd_add_reload_trigger $CONFIGNAME 95 } 96 97 start_service() { 98 set_conf_file 99 procd_open_instance 100 procd_set_param command /usr/sbin/bandwidthd 101 procd_close_instance 102 } 103 104 stop_service() { 105 service_stop /usr/sbin/bandwidthd 106 }