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.

76 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=87
  8. STOP=23
  9. USE_PROCD=1
  10. DEFAULT=/etc/default/nut
  11. UPSCGI_C=/var/etc/nut/hosts.conf
  12. UPSCGI_S=/var/etc/nut/upsset.conf
  13. nut_upscgi_upsset() {
  14. local cfg="$1"
  15. local enable
  16. config_get_bool enable "$cfg" enable 0
  17. if [ "$enable" -eq 1 ]; then
  18. ln -sf /etc/nut/upsset.conf.enable "$UPSCGI_S"
  19. else
  20. ln -sf /etc/nut/upsset.conf.disable "$UPSCGI_S"
  21. fi
  22. }
  23. nut_upscgi_add() {
  24. local cfg="$1"
  25. local upsname
  26. local hostname
  27. local port
  28. local displayname
  29. config_get upsname "$cfg" upsname
  30. config_get hostname "$cfg" hostname localhost
  31. config_get port "$cfg" port
  32. config_get pass "$cfg" password
  33. system="$upsname@$hostname"
  34. if [ -n "$port" ]; then
  35. system="$system:$port";
  36. fi
  37. config_get displayname "$cfg" displayname
  38. echo "MONITOR $system \"$displayname\"" >> "$UPSCGI_C"
  39. }
  40. service_reload() {
  41. mkdir -m 0755 -p "$(dirname "$UPSCGI_C")"
  42. rm -f "$UPSCGI_C"
  43. rm -f "$UPSCGI_S"
  44. config_load nut_cgi
  45. config_foreach nut_upscgi_add host
  46. config_foreach nut_upscgi_upsset upsset
  47. [ -s "$UPSCGI_C" ] && chmod 640 "$UPSCGI_C"
  48. }
  49. start_service() {
  50. service_reload
  51. }
  52. reload_service() {
  53. service_reload
  54. }
  55. stop_service() {
  56. rm -f "$UPSCGI_C"
  57. rm -f "$UPSCGI_S"
  58. ln -sf /etc/nut/upsset.conf.disable "$UPSCGI_S"
  59. }
  60. service_triggers() {
  61. procd_add_reload_trigger "nut_cgi"
  62. }