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.

63 lines
1.4 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2017-2019 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_instance() {
  11. local cfg="$1"
  12. [ "$disabled" = 0 ] || return 0
  13. [ -x "$command" ] || {
  14. echo "$command is not executable" >&2
  15. return 1
  16. }
  17. procd_open_instance "$name"
  18. procd_set_param command "$command"
  19. procd_set_param stderr "$stderr"
  20. procd_set_param stdout "$stdout"
  21. procd_set_param respawn "$respawn_threshold" "$respawn_timeout" "$respawn_maxfail"
  22. [ -z "$args" ] || config_list_foreach "$cfg" args pservice_list_cb command
  23. if [ -n "$env" ]; then
  24. procd_set_param env
  25. config_list_foreach "$cfg" env pservice_list_cb env
  26. fi
  27. if [ -n "$file" ]; then
  28. procd_set_param file
  29. config_list_foreach "$cfg" file pservice_list_cb file
  30. fi
  31. procd_close_instance
  32. }
  33. start_service() {
  34. config_load 'pservice'
  35. config_foreach validate_pservice_section pservice pservice_instance
  36. }
  37. service_triggers() {
  38. procd_add_validation validate_pservice_section
  39. }
  40. validate_pservice_section() {
  41. uci_load_validate pservice pservice "$1" "$2" \
  42. "disabled:bool:0" \
  43. "name:string" \
  44. "env:regex('^[a-zA-Z_][a-zA-Z0-9_]*=.*$')" \
  45. "command:file" \
  46. "args:string" \
  47. "stderr:bool:0" \
  48. "stdout:bool:0" \
  49. "respawn_threshold:uinteger:3600" \
  50. "respawn_timeout:uinteger:5" \
  51. "respawn_maxfail:uinteger:5" \
  52. "file:string"
  53. }