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.

92 lines
2.1 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=25
  3. USE_PROCD=1
  4. EXTRA_COMMANDS="status_service"
  5. trm_init="/etc/init.d/travelmate"
  6. trm_script="/usr/bin/travelmate.sh"
  7. trm_pidfile="/var/run/travelmate.pid"
  8. boot()
  9. {
  10. local iface="$(uci_get travelmate global trm_iface)"
  11. ubus -t 30 wait_for network.wireless network.interface."${iface:-"trm_wwan"}" 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 nice "$(uci_get travelmate extra trm_nice "0")"
  22. procd_set_param stdout 1
  23. procd_set_param stderr 1
  24. procd_close_instance
  25. fi
  26. }
  27. reload_service()
  28. {
  29. local ppid pid timeout="$(uci_get travelmate global trm_timeout)"
  30. if [ -s "${trm_pidfile}" ]
  31. then
  32. ppid="$(cat "${trm_pidfile}" 2>/dev/null)"
  33. if [ -n "${ppid}" ]
  34. then
  35. pid="$(pgrep -xnf "sleep ${timeout:-60} 0" -P ${ppid} 2>/dev/null)"
  36. if [ -n "${pid}" ]
  37. then
  38. kill -INT ${pid} 2>/dev/null
  39. fi
  40. fi
  41. fi
  42. }
  43. stop_service()
  44. {
  45. rc_procd "${trm_script}" stop
  46. }
  47. status_service()
  48. {
  49. local key keylist value rtfile="$(uci_get travelmate global trm_rtfile)"
  50. rtfile="${rtfile:-"/tmp/trm_runtime.json"}"
  51. json_load_file "${rtfile}" >/dev/null 2>&1
  52. json_select data >/dev/null 2>&1
  53. if [ ${?} -eq 0 ]
  54. then
  55. printf "%s\n" "::: travelmate runtime information"
  56. json_get_keys keylist
  57. for key in ${keylist}
  58. do
  59. json_get_var value "${key}"
  60. printf " + %-18s : %s\n" "${key}" "${value}"
  61. done
  62. else
  63. printf "%s\n" "::: no travelmate runtime information available"
  64. fi
  65. }
  66. service_triggers()
  67. {
  68. local trigger="$(uci_get travelmate global trm_iface)"
  69. local delay="$(uci_get travelmate global trm_triggerdelay)"
  70. PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
  71. if [ -n "${trigger}" ]
  72. then
  73. procd_add_interface_trigger "interface.*.down" "${trigger}" "${trm_init}" reload
  74. else
  75. procd_add_raw_trigger "interface.*.down" ${PROCD_RELOAD_DELAY} "${trm_init}" reload
  76. fi
  77. procd_add_config_trigger "config.change" "wireless" "${trm_init}" reload
  78. procd_add_config_trigger "config.change" "travelmate" "${trm_init}" restart
  79. }