From 80e34d6f7368435110e0b69fd55b97358dd5f617 Mon Sep 17 00:00:00 2001 From: Dirk Brenken Date: Thu, 20 Apr 2017 09:22:22 +0200 Subject: [PATCH] travelmate: update 0.7.0 * no longer misuse ubus/procd service object for travelmate runtime information, now save all required information directly in a JSON file/format * new 'status' init command to print runtime information * add a configurable interface trigger timeout for nested & slow modem/router setups, set 'trm_triggerdelay' accordingly * change start priority & refine reload timings * cosmetics Signed-off-by: Dirk Brenken --- net/travelmate/Makefile | 2 +- net/travelmate/files/README.md | 37 +++++------ net/travelmate/files/travelmate.conf | 2 + net/travelmate/files/travelmate.init | 22 ++++++- net/travelmate/files/travelmate.sh | 92 ++++++++++++++++++---------- 5 files changed, 95 insertions(+), 60 deletions(-) diff --git a/net/travelmate/Makefile b/net/travelmate/Makefile index 911a3f922..c4a13778c 100644 --- a/net/travelmate/Makefile +++ b/net/travelmate/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=travelmate -PKG_VERSION:=0.6.0 +PKG_VERSION:=0.7.0 PKG_RELEASE:=1 PKG_LICENSE:=GPL-3.0+ PKG_MAINTAINER:=Dirk Brenken diff --git a/net/travelmate/files/README.md b/net/travelmate/files/README.md index b77f8d6b3..626956452 100644 --- a/net/travelmate/files/README.md +++ b/net/travelmate/files/README.md @@ -12,14 +12,14 @@ To avoid these kind of deadlocks, travelmate set all station interfaces in an "a * manual / automatic mode support, the latter one checks the existing uplink connection regardless of ifdown event trigger every n seconds * support of devices with multiple radios * procd init and hotplug support -* runtime information accessible via ubus service call +* runtime information available via LuCI & via 'status' init command * status & debug logging to syslog ## Prerequisites -* [OpenWrt](https://openwrt.org) or [LEDE](https://www.lede-project.org) trunk +* [LEDE](https://www.lede-project.org) 17.01 or latest snapshot * iw (default) or iwinfo for wlan scanning -## OpenWrt / LEDE trunk Installation & Usage +## LEDE trunk Installation & Usage * download the package [here](https://downloads.lede-project.org/snapshots/packages/x86_64/packages) * install 'travelmate' (_opkg install travelmate_) * configure your network to support (multiple) wlan uplinks and set travelmate config options (see below) @@ -30,7 +30,6 @@ To avoid these kind of deadlocks, travelmate set all station interfaces in an "a * download the package [here](https://downloads.lede-project.org/snapshots/packages/x86_64/luci) * install 'luci-app-travelmate' (_opkg install luci-app-travelmate_) * the application is located in LuCI under 'Services' menu -* _Thanks to Hannu Nyman for this great LuCI frontend!_ ## Travelmate config options * travelmate config options: @@ -42,28 +41,22 @@ To avoid these kind of deadlocks, travelmate set all station interfaces in an "a * trm\_timeout => timeout in seconds for "automatic mode" (default: '60') * trm\_iw => set this option to '0' to use iwinfo for wlan scanning (default: '1', use iw) * trm\_radio => limit travelmate to a dedicated radio, e.g. 'radio0' (default: not set, use all radios) - * trm\_iface => restrict the procd interface trigger to a (list of) certain wan interface(s) or disable it at all (default: wan wwan) - + * trm\_iface => restrict the procd interface trigger to a (list of) certain wan interface(s) or disable it at all (default: wwan) + * trm\_triggerdelay => additional trigger delay in seconds before travelmate processing starts (default: '2') ## Runtime information -**receive travelmate information via ubus:** +**receive travelmate runtime information:**

-ubus call service get_data '{"name":"travelmate"}'
-This will output the current connection status, e.g.:
-{
-    "travelmate": {
-        "travelmate": {
-            "last_rundate": "02.04.2017 07:22:03",
-            "online_status": "true",
-            "station_interface": "wwan",
-            "station_radio": "radio1",
-            "station_ssid": "blackhole",
-            "system": "LEDE Reboot SNAPSHOT r3888-8fb39f1682",
-            "travelmate_version": "0.6.0"
-        }
-    }
-}
+root@adb2go:/tmp# /etc/init.d/travelmate status
+::: travelmate runtime information
+ travelmate_version : 0.7.0
+ station_connection : true
+ station_ssid       : blackhole
+ station_interface  : wwan
+ station_radio      : radio1
+ last_rundate       : 20.04.2017 08:54:48
+ system             : LEDE Reboot SNAPSHOT r3974-56457dbcb7
 
## Setup diff --git a/net/travelmate/files/travelmate.conf b/net/travelmate/files/travelmate.conf index 00b7b127c..91b426f1b 100644 --- a/net/travelmate/files/travelmate.conf +++ b/net/travelmate/files/travelmate.conf @@ -5,8 +5,10 @@ config travelmate 'global' option trm_enabled '0' option trm_debug '0' option trm_iface 'wwan' + option trm_triggerdelay '2' option trm_automatic '1' option trm_maxwait '30' option trm_maxretry '3' option trm_timeout '60' option trm_iw '1' + option trm_rtfile '/tmp/trm_runtime.json' diff --git a/net/travelmate/files/travelmate.init b/net/travelmate/files/travelmate.init index f0a6a6787..8b988dbd1 100755 --- a/net/travelmate/files/travelmate.init +++ b/net/travelmate/files/travelmate.init @@ -1,21 +1,29 @@ #!/bin/sh /etc/rc.common -START=85 +START=35 USE_PROCD=1 +EXTRA_COMMANDS="status" +EXTRA_HELP=" status Print runtime information" + trm_init="/etc/init.d/travelmate" trm_script="/usr/bin/travelmate.sh" boot() { - ubus -t 30 wait_for network.interface + trm_boot=1 + ubus -t 30 wait_for network.interface 2>/dev/null rc_procd start_service } start_service() { - if [ $(/etc/init.d/travelmate enabled; printf ${?}) -eq 0 ] + if [ $("${trm_init}" enabled; printf ${?}) -eq 0 ] then + if [ -n "${trm_boot}" ] + then + return 0 + fi procd_open_instance "travelmate" procd_set_param command "${trm_script}" "${@}" procd_set_param stdout 1 @@ -24,13 +32,21 @@ start_service() fi } +status() +{ + rc_procd "${trm_script}" status +} + service_triggers() { local iface="$(uci -q get travelmate.global.trm_iface)" + local delay="$(uci -q get travelmate.global.trm_triggerdelay)" + PROCD_RELOAD_DELAY=$((${delay:=2} * 1000)) for name in ${iface} do procd_add_interface_trigger "interface.*.down" "${name}" "${trm_init}" start done + PROCD_RELOAD_DELAY=1000 procd_add_config_trigger "config.change" "travelmate" "${trm_init}" start } diff --git a/net/travelmate/files/travelmate.sh b/net/travelmate/files/travelmate.sh index b9d728b88..2859a1049 100755 --- a/net/travelmate/files/travelmate.sh +++ b/net/travelmate/files/travelmate.sh @@ -10,23 +10,25 @@ # LC_ALL=C PATH="/usr/sbin:/usr/bin:/sbin:/bin" -trm_ver="0.6.0" +trm_ver="0.7.0" trm_sysver="$(ubus -S call system board | jsonfilter -e '@.release.description')" trm_enabled=0 trm_debug=0 -trm_automatic=0 -trm_maxwait=30 +trm_automatic=1 trm_maxretry=3 +trm_maxwait=30 trm_timeout=60 trm_iw=1 +trm_rtfile="/tmp/trm_runtime.json" # source required system library # -if [ -r "/lib/functions.sh" ] +if [ -r "/lib/functions.sh" ] && [ -r "/usr/share/libubox/jshn.sh" ] then . "/lib/functions.sh" + . "/usr/share/libubox/jshn.sh" else - f_log "error" "required system library not found" + f_log "error" "system libraries not found" fi # f_envload: load travelmate environment @@ -134,28 +136,43 @@ f_check() f_log "debug" "mode: ${mode}, name: ${ifname}, status: ${trm_ifstatus}, count: ${cnt}, max-wait: ${trm_maxwait}, automatic: ${trm_automatic}" } -# f_ubus: update ubus service +# f_jsnupdate: update runtime information # -f_ubus() +f_jsnupdate() { - local active_triggers iface="${1}" radio="${2}" ssid="${3}" + local iface="${1}" radio="${2}" ssid="${3}" - for name in ${trm_iface} - do - active_triggers="${active_triggers}[\"interface.*.down\",[\"if\",[\"eq\",\"interface\",\"${name}\"],[\"run_script\",\"/etc/init.d/travelmate\",\"start\"],1000]]," - done - active_triggers="${active_triggers}[\"config.change\",[\"if\",[\"eq\",\"package\",\"travelmate\"],[\"run_script\",\"/etc/init.d/travelmate\",\"start\"],1000]]" + json_init + json_add_object "data" + json_add_string "travelmate_version" "${trm_ver}" + json_add_string "station_connection" "${trm_ifstatus}" + json_add_string "station_ssid" "${ssid}" + json_add_string "station_interface" "${iface}" + json_add_string "station_radio" "${radio}" + json_add_string "last_rundate" "$(/bin/date "+%d.%m.%Y %H:%M:%S")" + json_add_string "system" "${trm_sysver}" + json_close_object + json_dump > "${trm_rtfile}" +} + +# f_status: output runtime information +# +f_status() +{ + local key keylist value - ubus call service add "{\"name\":\"travelmate\", - \"instances\":{\"travelmate\":{\"command\":[\"/usr/bin/travelmate.sh\"], - \"data\":{\"travelmate_version\":\"${trm_ver}\", - \"station_interface\":\"${iface}\", - \"station_radio\":\"${radio}\", - \"station_ssid\":\"${ssid}\", - \"last_rundate\":\"$(/bin/date "+%d.%m.%Y %H:%M:%S")\", - \"online_status\":\"${trm_ifstatus}\", - \"system\":\"${trm_sysver}\"}}}, - \"triggers\":[${active_triggers}]}" + if [ -s "${trm_rtfile}" ] + then + printf "%s\n" "::: travelmate runtime information" + json_load "$(cat "${trm_rtfile}" 2>/dev/null)" + json_select data + json_get_keys keylist + for key in ${keylist} + do + json_get_var value ${key} + printf " %-18s : %s\n" "${key}" "${value}" + done + fi } # f_log: write to syslog, exit on error @@ -191,7 +208,6 @@ f_main() then uci -q commit wireless ubus call network reload - sleep 5 fi f_check "ap" f_log "debug" "ap-list: ${trm_aplist}, sta-list: ${trm_stalist}" @@ -236,14 +252,13 @@ f_main() then uci -q commit wireless f_log "info " "interface '${sta_iface}' on '${sta_radio}' connected to uplink '${sta_ssid}' (${trm_sysver})" - sleep 5 - f_ubus "${sta_iface}" "${sta_radio}" "${sta_ssid}" + f_jsnupdate "${sta_iface}" "${sta_radio}" "${sta_ssid}" return 0 else uci -q revert wireless ubus call network reload f_log "info " "interface '${sta_iface}' on '${sta_radio}' can't connect to uplink '${sta_ssid}' (${trm_sysver})" - f_ubus "${sta_iface}" "${sta_radio}" "${sta_ssid}" + f_jsnupdate "${sta_iface}" "${sta_radio}" "${sta_ssid}" fi fi done @@ -255,12 +270,21 @@ f_main() fi } +# handle different travelmate actions +# f_envload -f_main -while [ ${trm_automatic} -eq 1 ] -do - sleep ${trm_timeout} - f_envload - f_main -done +case "${1}" in + status) + f_status + ;; + *) + f_main + while [ ${trm_automatic} -eq 1 ] + do + sleep ${trm_timeout} + f_envload + f_main + done + ;; +esac exit 0