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.9 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 pidfile "${trm_pidfile}"
  21. procd_set_param stdout 1
  22. procd_set_param stderr 1
  23. procd_close_instance
  24. fi
  25. }
  26. reload_service()
  27. {
  28. local ppid pid timeout="$(uci_get travelmate global trm_timeout)"
  29. if [ -s "${trm_pidfile}" ]
  30. then
  31. ppid="$(cat "${trm_pidfile}" 2>/dev/null)"
  32. if [ -n "${ppid}" ]
  33. then
  34. pid="$(pgrep -xnf "sleep ${timeout:-60} 0" -P ${ppid} 2>/dev/null)"
  35. if [ -n "${pid}" ]
  36. then
  37. kill -INT ${pid} 2>/dev/null
  38. fi
  39. fi
  40. fi
  41. }
  42. stop_service()
  43. {
  44. rc_procd "${trm_script}" stop
  45. }
  46. status()
  47. {
  48. local key keylist value rtfile="$(uci_get travelmate global trm_rtfile)"
  49. rtfile="${rtfile:-"/tmp/trm_runtime.json"}"
  50. json_load_file "${rtfile}" >/dev/null 2>&1
  51. json_select data >/dev/null 2>&1
  52. if [ ${?} -eq 0 ]
  53. then
  54. printf "%s\n" "::: travelmate runtime information"
  55. json_get_keys keylist
  56. for key in ${keylist}
  57. do
  58. json_get_var value "${key}"
  59. printf " + %-18s : %s\n" "${key}" "${value}"
  60. done
  61. else
  62. printf "%s\n" "::: no travelmate runtime information available"
  63. fi
  64. }
  65. service_triggers()
  66. {
  67. local trigger="$(uci_get travelmate global trm_iface)"
  68. local delay="$(uci_get travelmate global trm_triggerdelay)"
  69. PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
  70. procd_add_interface_trigger "interface.*.down" "${trigger:-"trm_wwan"}" "${trm_init}" reload
  71. procd_add_config_trigger "config.change" "wireless" "${trm_init}" reload
  72. procd_add_config_trigger "config.change" "travelmate" "${trm_init}" restart
  73. }