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.

84 lines
1.7 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=99
  3. USE_PROCD=1
  4. NAME=frpc
  5. PROG=/usr/bin/$NAME
  6. _err() {
  7. echo "$*" >&2
  8. logger -p daemon.err -t "$NAME" "$*"
  9. }
  10. config_cb() {
  11. [ $# -eq 0 ] && return
  12. local type="$1"
  13. local name="$2"
  14. if [ "$type" = "conf" ]; then
  15. echo "[$name]" >> "$conf_file"
  16. option_cb() {
  17. local option="$1"
  18. local value="$2"
  19. [ "$option" = "name" ] && \
  20. sed -i "s/$CONFIG_SECTION/$value/g" "$conf_file" || \
  21. echo "$option = $value" >> "$conf_file";
  22. }
  23. list_cb() {
  24. local name="$1"
  25. local value="$2"
  26. [ "$name" = "_" ] && echo "$value" >> "$conf_file"
  27. }
  28. else
  29. [ "$type" = "init" ] && init_cfg="$name"
  30. option_cb() { return 0; }
  31. list_cb() { return 0; }
  32. fi
  33. }
  34. service_triggers()
  35. {
  36. procd_add_reload_trigger "$NAME"
  37. }
  38. start_service() {
  39. local init_cfg=" "
  40. local conf_file="/var/etc/$NAME.ini"
  41. > "$conf_file"
  42. config_load "$NAME"
  43. local stdout stderr user group respawn env conf_inc
  44. uci_validate_section "$NAME" init "$init_cfg" \
  45. 'stdout:bool:1' \
  46. 'stderr:bool:1' \
  47. 'user:string' \
  48. 'group:string' \
  49. 'respawn:bool:1' \
  50. 'env:list(string)' \
  51. 'conf_inc:list(string)'
  52. local err=$?
  53. [ $err -ne 0 ] && {
  54. _err "uci_validate_section returned $err"
  55. return 1
  56. }
  57. [ -n "$conf_inc" ] && config_list_foreach "$init_cfg" conf_inc cat >> "$conf_file"
  58. procd_open_instance
  59. procd_set_param command "$PROG" -c "$conf_file"
  60. procd_set_param stdout $stdout
  61. procd_set_param stderr $stderr
  62. [ -n "$user" ] && procd_set_param user "$user"
  63. [ -n "$group" ] && procd_set_param group "$group"
  64. [ $respawn -eq 1 ] && procd_set_param respawn
  65. [ -n "$env" ] && config_list_foreach "$init_cfg" env "procd_append_param env"
  66. procd_close_instance
  67. }
  68. reload_service() {
  69. stop
  70. start
  71. }