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.

71 lines
1.4 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright © 2012 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. START=51
  8. USE_PROCD=1
  9. DEFAULT=/etc/default/nut
  10. UPSCGI_C=/var/etc/nut/hosts.conf
  11. UPSCGI_S=/var/etc/nut/upsset.conf
  12. nut_upscgi_upsset() {
  13. local cfg="$1"
  14. local enable
  15. config_get_bool enable "$cfg" enable 0
  16. [ $enable -eq 1 ] && {
  17. ln -sf /etc/nut/upsset.conf.enable "$UPSCGI_S"
  18. } || {
  19. ln -sf /etc/nut/upsset.conf.disable "$UPSCGI_S"
  20. }
  21. }
  22. nut_upscgi_add() {
  23. local cfg="$1"
  24. local upsname
  25. local hostname
  26. local port
  27. local displayname
  28. config_get upsname "$cfg" upsname
  29. config_get hostname "$cfg" hostname localhost
  30. config_get port "$cfg" port
  31. config_get pass "$cfg" password
  32. system="$upsname@$hostname"
  33. if [ -n "$port" ]; then
  34. system="$system:$port";
  35. fi
  36. config_get displayname "$cfg" displayname
  37. echo "MONITOR $system \"$displayname\"" >> "$UPSCGI_C"
  38. }
  39. service_reload() {
  40. mkdir -m 0755 -p "$(dirname "$UPSCGI_C")"
  41. rm -f "$UPSCGI_C"
  42. rm -f "$UPSCGI_S"
  43. config_load nut_cgi
  44. config_foreach nut_upscgi_add host
  45. config_foreach nut_upscgi_upsset upsset
  46. chmod 640 /var/etc/nut/hosts.conf
  47. }
  48. start_service() {
  49. service_reload
  50. }
  51. stop_service() {
  52. rm -f "$UPSCGI_C"
  53. rm -f "$UPSCGI_S"
  54. ln -sf /etc/nut/upsset.conf.disable "$UPSCGI_S"
  55. }
  56. service_triggers() {
  57. procd_add_reload_trigger "nut_cgi"
  58. }