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.

75 lines
1.7 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=25
  3. USE_PROCD=1
  4. EXTRA_COMMANDS="status"
  5. EXTRA_HELP=" status Print runtime information"
  6. trm_init="/etc/init.d/travelmate"
  7. trm_script="/usr/bin/travelmate.sh"
  8. trm_pidfile="/var/run/travelmate.pid"
  9. boot()
  10. {
  11. ubus -t 30 wait_for network.interface network.wireless 2>/dev/null
  12. rc_procd start_service
  13. }
  14. start_service()
  15. {
  16. if [ $("${trm_init}" enabled; printf "%u" ${?}) -eq 0 ]
  17. then
  18. procd_open_instance "travelmate"
  19. procd_set_param command "${trm_script}" "${@}"
  20. procd_set_param stdout 1
  21. procd_set_param stderr 1
  22. procd_close_instance
  23. fi
  24. }
  25. reload_service()
  26. {
  27. [ -s "${trm_pidfile}" ] && return 1
  28. "${trm_init}" restart
  29. }
  30. stop_service()
  31. {
  32. local rtfile="$(uci_get travelmate global trm_rtfile)"
  33. rtfile="${rtfile:-"/tmp/trm_runtime.json"}"
  34. > "${rtfile}"
  35. rc_procd start_service
  36. }
  37. status()
  38. {
  39. local key keylist value rtfile="$(uci_get travelmate global trm_rtfile)"
  40. rtfile="${rtfile:-"/tmp/trm_runtime.json"}"
  41. if [ -s "${rtfile}" ]
  42. then
  43. printf "%s\n" "::: travelmate runtime information"
  44. json_load "$(cat "${rtfile}" 2>/dev/null)"
  45. json_select data
  46. json_get_keys keylist
  47. for key in ${keylist}
  48. do
  49. json_get_var value "${key}"
  50. printf " + %-18s : %s\n" "${key}" "${value}"
  51. done
  52. else
  53. printf "%s\n" "::: no travelmate runtime information available"
  54. fi
  55. }
  56. service_triggers()
  57. {
  58. local trigger="$(uci_get travelmate global trm_iface)"
  59. local delay="$(uci_get travelmate global trm_triggerdelay)"
  60. PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
  61. procd_add_interface_trigger "interface.*.down" "${trigger}" "${trm_init}" reload
  62. procd_add_reload_trigger "travelmate"
  63. }