You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
1.7 KiB

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