1
0

owserver.init 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2009-2015 OpenWrt.org
  3. START=90
  4. USE_PROCD=1
  5. PROG=/usr/bin/owserver
  6. append_arg() {
  7. local cfg="$1"
  8. local var="$2"
  9. local opt="$3"
  10. local def="$4"
  11. local val
  12. config_get val "$cfg" "$var"
  13. [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}"
  14. }
  15. append_bool() {
  16. local cfg="$1"
  17. local var="$2"
  18. local opt="$3"
  19. local def="$4"
  20. local val
  21. config_get_bool val "$cfg" "$var" "$def"
  22. [ "$val" = 1 ] && procd_append_param command "$opt"
  23. }
  24. append_plain() {
  25. procd_append_param command "$1"
  26. }
  27. append_param() {
  28. local cfg="$1"
  29. local var="$2"
  30. local opt="$3"
  31. local def="$4"
  32. local val
  33. config_get val "$cfg" "$var"
  34. [ -n "$val" -o -n "$def" ] && procd_append_param "$opt" "${val:-$def}"
  35. }
  36. start_instance() {
  37. local cfg="$1"
  38. local enabled
  39. config_get_bool enabled "$cfg" 'enabled' '0'
  40. [ "$enabled" = 0 ] && return 1
  41. procd_open_instance
  42. procd_set_param command "$PROG" --foreground --error_print=1
  43. # common parameters
  44. append_bool "$cfg" readonly "--readonly"
  45. append_arg "$cfg" error_level "--error_level"
  46. config_list_foreach "$cfg" options append_plain
  47. config_list_foreach "$cfg" devices append_plain
  48. append_param "$cfg" user user
  49. # owserver-specific
  50. append_arg "$cfg" port "--port"
  51. append_arg "$cfg" max_connections "--max_connections"
  52. procd_set_param respawn
  53. procd_close_instance
  54. }
  55. service_triggers() {
  56. procd_add_reload_trigger owserver
  57. }
  58. start_service() {
  59. config_load owserver
  60. config_foreach start_instance owserver
  61. }