nlbwmon.init 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/sh /etc/rc.common
  2. START=60
  3. USE_PROCD=1
  4. NAME=nlbwmon
  5. PROG=/usr/sbin/nlbwmon
  6. NICEPRIO=19
  7. add_subnet() {
  8. local network="$1"
  9. local range ranges
  10. case "$network" in
  11. *.*|*:*)
  12. procd_append_param command '-s' "$network"
  13. ;;
  14. *)
  15. if network_get_subnets ranges "$network"; then
  16. for range in $ranges; do
  17. procd_append_param command '-s' "$range"
  18. done
  19. fi
  20. if network_get_subnets6 ranges "$network"; then
  21. for range in $ranges; do
  22. procd_append_param command '-s' "$range"
  23. done
  24. fi
  25. ;;
  26. esac
  27. }
  28. add_option() {
  29. local cfg="$1"
  30. local flag="$2"
  31. local option="$3"
  32. local default="$4"
  33. local value
  34. config_get value "$cfg" "$option" "$default"
  35. [ -n "$value" ] && procd_append_param command "$flag" "$value"
  36. }
  37. add_bool() {
  38. local cfg="$1"
  39. local flag="$2"
  40. local option="$3"
  41. local default="$4"
  42. local value
  43. config_get_bool value "$cfg" "$option" "$default"
  44. [ $value -eq 1 ] && procd_append_param command "$flag"
  45. }
  46. parse_config() {
  47. . /lib/functions/network.sh
  48. local cfg="$1"
  49. local dir
  50. config_get dir "$cfg" database_directory /var/lib/nlbwmon
  51. mkdir -p "$dir"
  52. procd_append_param command -o "$dir"
  53. add_option "$cfg" -i commit_interval 24h
  54. add_option "$cfg" -r refresh_interval 30s
  55. add_option "$cfg" -p protocol_database /usr/share/nlbwmon/protocols
  56. add_option "$cfg" -G database_generations 10
  57. add_option "$cfg" -I database_interval 1
  58. add_option "$cfg" -L database_limit 10000
  59. add_bool "$cfg" -P database_prealloc 0
  60. add_bool "$cfg" -Z database_compress 1
  61. config_list_foreach "$cfg" local_network add_subnet
  62. }
  63. start_service() {
  64. procd_open_instance
  65. procd_set_param stderr 1
  66. procd_set_param command "$PROG"
  67. procd_set_param nice "$NICEPRIO"
  68. config_load nlbwmon
  69. config_foreach parse_config nlbwmon
  70. procd_close_instance
  71. }
  72. add_interface_trigger() {
  73. local interface ignore
  74. config_get interface "$1" interface
  75. config_get_bool ignore "$1" ignore 0
  76. [ -n "$interface" -a $ignore -eq 0 ] && procd_add_interface_trigger "interface.*" "$interface" /etc/init.d/nlbwmon reload
  77. }
  78. service_triggers() {
  79. procd_add_reload_trigger "dhcp" "system"
  80. config_load dhcp
  81. config_foreach add_interface_trigger dhcp
  82. }