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.

90 lines
2.1 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=25
  3. USE_PROCD=1
  4. trm_init="/etc/init.d/travelmate"
  5. trm_script="/usr/bin/travelmate.sh"
  6. trm_pidfile="/var/run/travelmate.pid"
  7. boot()
  8. {
  9. local iface="$(uci_get travelmate global trm_iface)"
  10. ubus -t 30 wait_for network.wireless network.interface."${iface:-"trm_wwan"}" 2>/dev/null
  11. rc_procd start_service
  12. }
  13. start_service()
  14. {
  15. if [ $("${trm_init}" enabled; printf "%u" ${?}) -eq 0 ]
  16. then
  17. procd_open_instance "travelmate"
  18. procd_set_param command "${trm_script}" "${@}"
  19. procd_set_param pidfile "${trm_pidfile}"
  20. procd_set_param nice "$(uci_get travelmate extra trm_nice "0")"
  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_service()
  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. if [ -n "${trigger}" ]
  71. then
  72. procd_add_interface_trigger "interface.*.down" "${trigger}" "${trm_init}" reload
  73. else
  74. procd_add_raw_trigger "interface.*.down" ${PROCD_RELOAD_DELAY} "${trm_init}" reload
  75. fi
  76. procd_add_config_trigger "config.change" "wireless" "${trm_init}" reload
  77. procd_add_config_trigger "config.change" "travelmate" "${trm_init}" restart
  78. }