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.

85 lines
1.7 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2017 Yousong Zhou
  3. START=99
  4. USE_PROCD=1
  5. pservice_list_cb() {
  6. local val="$1"; shift
  7. local param="$1"; shift
  8. procd_append_param "$param" "$val"
  9. }
  10. pservice() {
  11. local cfg="$1"
  12. eval "$(validate_pservice_section "$cfg" pservice_validate_mklocal)"
  13. validate_pservice_section "$cfg" || return 1
  14. [ "$disabled" = 0 ] || return 0
  15. [ -x "$command" ] || return 1
  16. procd_open_instance "$name"
  17. procd_set_param command "$command"
  18. procd_set_param stderr "$stderr"
  19. procd_set_param stdout "$stdout"
  20. procd_set_param respawn "$respawn_threshold" "$respawn_timeout" "$respawn_maxfail"
  21. [ -z "$args" ] || config_list_foreach "$cfg" args pservice_list_cb command
  22. if [ -n "$env" ]; then
  23. procd_set_param env
  24. config_list_foreach "$cfg" env pservice_list_cb env
  25. fi
  26. if [ -n "$file" ]; then
  27. procd_set_param file
  28. config_list_foreach "$cfg" file pservice_list_cb file
  29. fi
  30. procd_close_instance
  31. }
  32. start_service() {
  33. config_load 'pservice'
  34. config_foreach pservice pservice
  35. }
  36. stop_service() {
  37. true
  38. }
  39. service_triggers() {
  40. procd_open_validate
  41. validate_pservice_section
  42. procd_close_validate
  43. }
  44. pservice_validate_mklocal() {
  45. local tuple opts
  46. shift 2
  47. for tuple in "$@"; do
  48. opts="${tuple%%:*} $opts"
  49. done
  50. [ -z "$opts" ] || echo "local $opts"
  51. }
  52. pservice_validate() {
  53. uci_validate_section pservice "$@"
  54. }
  55. validate_pservice_section() {
  56. local cfg="$1"; shift
  57. local func="$1"; shift
  58. "${func:-pservice_validate}" pservice "$cfg" \
  59. "disabled:bool:0" \
  60. "name:string" \
  61. "env:regex('^[a-zA-Z_][a-zA-Z0-9_]*=.*$')" \
  62. "command:file" \
  63. "args:list(string)" \
  64. "stderr:bool:0" \
  65. "stdout:bool:0" \
  66. "respawn_threshold:uinteger:3600" \
  67. "respawn_timeout:uinteger:5" \
  68. "respawn_maxfail:uinteger:5" \
  69. "file:string"
  70. }