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.

72 lines
1.5 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=99
  3. USE_PROCD=1
  4. NAME=frps
  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. echo "$option = $value" >> "$conf_file"
  20. }
  21. list_cb() {
  22. local name="$1"
  23. local value="$2"
  24. [ "$name" = "_" ] && echo "$value" >> "$conf_file"
  25. }
  26. else
  27. [ "$type" = "init" ] && init_cfg="$name"
  28. option_cb() { return 0; }
  29. list_cb() { return 0; }
  30. fi
  31. }
  32. start_service() {
  33. local init_cfg=" "
  34. local conf_file="/var/etc/$NAME.ini"
  35. > "$conf_file"
  36. config_load "$NAME"
  37. local stdout stderr user group respawn env conf_inc
  38. uci_validate_section "$NAME" init "$init_cfg" \
  39. 'stdout:bool:1' \
  40. 'stderr:bool:1' \
  41. 'user:string' \
  42. 'group:string' \
  43. 'respawn:bool:1' \
  44. 'env:list(string)' \
  45. 'conf_inc:list(string)'
  46. local err=$?
  47. [ $err -ne 0 ] && {
  48. _err "uci_validate_section returned $err"
  49. return 1
  50. }
  51. [ -n "$conf_inc" ] && config_list_foreach "$init_cfg" conf_inc cat >> "$conf_file"
  52. procd_open_instance
  53. procd_set_param command "$PROG" -c "$conf_file"
  54. procd_set_param stdout $stdout
  55. procd_set_param stderr $stderr
  56. [ -n "$user" ] && procd_set_param user "$user"
  57. [ -n "$group" ] && procd_set_param group "$group"
  58. [ $respawn -eq 1 ] && procd_set_param respawn
  59. [ -n "$env" ] && config_list_foreach "$init_cfg" env "procd_append_param env"
  60. procd_close_instance
  61. }