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.

91 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. 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. }