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.

75 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=60
  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. [ -s "$UPSCGI_C" ] && chmod 640 "$UPSCGI_C"
  47. }
  48. start_service() {
  49. service_reload
  50. }
  51. reload_service() {
  52. service_reload
  53. }
  54. stop_service() {
  55. rm -f "$UPSCGI_C"
  56. rm -f "$UPSCGI_S"
  57. ln -sf /etc/nut/upsset.conf.disable "$UPSCGI_S"
  58. }
  59. service_triggers() {
  60. procd_add_reload_trigger "nut_cgi"
  61. }