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.

82 lines
1.6 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. service_triggers()
  33. {
  34. procd_add_reload_trigger "$NAME"
  35. }
  36. start_service() {
  37. local init_cfg=" "
  38. local conf_file="/var/etc/$NAME.ini"
  39. > "$conf_file"
  40. config_load "$NAME"
  41. local stdout stderr user group respawn env conf_inc
  42. uci_validate_section "$NAME" init "$init_cfg" \
  43. 'stdout:bool:1' \
  44. 'stderr:bool:1' \
  45. 'user:string' \
  46. 'group:string' \
  47. 'respawn:bool:1' \
  48. 'env:list(string)' \
  49. 'conf_inc:list(string)'
  50. local err=$?
  51. [ $err -ne 0 ] && {
  52. _err "uci_validate_section returned $err"
  53. return 1
  54. }
  55. [ -n "$conf_inc" ] && config_list_foreach "$init_cfg" conf_inc cat >> "$conf_file"
  56. procd_open_instance
  57. procd_set_param command "$PROG" -c "$conf_file"
  58. procd_set_param stdout $stdout
  59. procd_set_param stderr $stderr
  60. [ -n "$user" ] && procd_set_param user "$user"
  61. [ -n "$group" ] && procd_set_param group "$group"
  62. [ $respawn -eq 1 ] && procd_set_param respawn
  63. [ -n "$env" ] && config_list_foreach "$init_cfg" env "procd_append_param env"
  64. procd_close_instance
  65. }
  66. reload_service() {
  67. stop
  68. start
  69. }