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 <dev@brenken.org>
This commit is contained in:
parent
cf919894d6
commit
80e34d6f73
5 changed files with 95 additions and 60 deletions
|
@ -6,7 +6,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=travelmate
|
PKG_NAME:=travelmate
|
||||||
PKG_VERSION:=0.6.0
|
PKG_VERSION:=0.7.0
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
PKG_LICENSE:=GPL-3.0+
|
PKG_LICENSE:=GPL-3.0+
|
||||||
PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
|
PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
|
||||||
|
|
|
@ -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
|
* 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
|
* support of devices with multiple radios
|
||||||
* procd init and hotplug support
|
* 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
|
* status & debug logging to syslog
|
||||||
|
|
||||||
## Prerequisites
|
## 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
|
* 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)
|
* download the package [here](https://downloads.lede-project.org/snapshots/packages/x86_64/packages)
|
||||||
* install 'travelmate' (_opkg install travelmate_)
|
* install 'travelmate' (_opkg install travelmate_)
|
||||||
* configure your network to support (multiple) wlan uplinks and set travelmate config options (see below)
|
* 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)
|
* download the package [here](https://downloads.lede-project.org/snapshots/packages/x86_64/luci)
|
||||||
* install 'luci-app-travelmate' (_opkg install luci-app-travelmate_)
|
* install 'luci-app-travelmate' (_opkg install luci-app-travelmate_)
|
||||||
* the application is located in LuCI under 'Services' menu
|
* the application is located in LuCI under 'Services' menu
|
||||||
* _Thanks to Hannu Nyman for this great LuCI frontend!_
|
|
||||||
|
|
||||||
## Travelmate config options
|
## Travelmate config options
|
||||||
* 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\_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\_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\_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
|
## Runtime information
|
||||||
|
|
||||||
**receive travelmate information via ubus:**
|
**receive travelmate runtime information:**
|
||||||
<pre><code>
|
<pre><code>
|
||||||
ubus call service get_data '{"name":"travelmate"}'
|
root@adb2go:/tmp# /etc/init.d/travelmate status
|
||||||
This will output the current connection status, e.g.:
|
::: travelmate runtime information
|
||||||
{
|
travelmate_version : 0.7.0
|
||||||
"travelmate": {
|
station_connection : true
|
||||||
"travelmate": {
|
station_ssid : blackhole
|
||||||
"last_rundate": "02.04.2017 07:22:03",
|
station_interface : wwan
|
||||||
"online_status": "true",
|
station_radio : radio1
|
||||||
"station_interface": "wwan",
|
last_rundate : 20.04.2017 08:54:48
|
||||||
"station_radio": "radio1",
|
system : LEDE Reboot SNAPSHOT r3974-56457dbcb7
|
||||||
"station_ssid": "blackhole",
|
|
||||||
"system": "LEDE Reboot SNAPSHOT r3888-8fb39f1682",
|
|
||||||
"travelmate_version": "0.6.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</code></pre>
|
</code></pre>
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
|
@ -5,8 +5,10 @@ config travelmate 'global'
|
||||||
option trm_enabled '0'
|
option trm_enabled '0'
|
||||||
option trm_debug '0'
|
option trm_debug '0'
|
||||||
option trm_iface 'wwan'
|
option trm_iface 'wwan'
|
||||||
|
option trm_triggerdelay '2'
|
||||||
option trm_automatic '1'
|
option trm_automatic '1'
|
||||||
option trm_maxwait '30'
|
option trm_maxwait '30'
|
||||||
option trm_maxretry '3'
|
option trm_maxretry '3'
|
||||||
option trm_timeout '60'
|
option trm_timeout '60'
|
||||||
option trm_iw '1'
|
option trm_iw '1'
|
||||||
|
option trm_rtfile '/tmp/trm_runtime.json'
|
||||||
|
|
|
@ -1,21 +1,29 @@
|
||||||
#!/bin/sh /etc/rc.common
|
#!/bin/sh /etc/rc.common
|
||||||
|
|
||||||
START=85
|
START=35
|
||||||
USE_PROCD=1
|
USE_PROCD=1
|
||||||
|
|
||||||
|
EXTRA_COMMANDS="status"
|
||||||
|
EXTRA_HELP=" status Print runtime information"
|
||||||
|
|
||||||
trm_init="/etc/init.d/travelmate"
|
trm_init="/etc/init.d/travelmate"
|
||||||
trm_script="/usr/bin/travelmate.sh"
|
trm_script="/usr/bin/travelmate.sh"
|
||||||
|
|
||||||
boot()
|
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
|
rc_procd start_service
|
||||||
}
|
}
|
||||||
|
|
||||||
start_service()
|
start_service()
|
||||||
{
|
{
|
||||||
if [ $(/etc/init.d/travelmate enabled; printf ${?}) -eq 0 ]
|
if [ $("${trm_init}" enabled; printf ${?}) -eq 0 ]
|
||||||
then
|
then
|
||||||
|
if [ -n "${trm_boot}" ]
|
||||||
|
then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
procd_open_instance "travelmate"
|
procd_open_instance "travelmate"
|
||||||
procd_set_param command "${trm_script}" "${@}"
|
procd_set_param command "${trm_script}" "${@}"
|
||||||
procd_set_param stdout 1
|
procd_set_param stdout 1
|
||||||
|
@ -24,13 +32,21 @@ start_service()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status()
|
||||||
|
{
|
||||||
|
rc_procd "${trm_script}" status
|
||||||
|
}
|
||||||
|
|
||||||
service_triggers()
|
service_triggers()
|
||||||
{
|
{
|
||||||
local iface="$(uci -q get travelmate.global.trm_iface)"
|
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}
|
for name in ${iface}
|
||||||
do
|
do
|
||||||
procd_add_interface_trigger "interface.*.down" "${name}" "${trm_init}" start
|
procd_add_interface_trigger "interface.*.down" "${name}" "${trm_init}" start
|
||||||
done
|
done
|
||||||
|
PROCD_RELOAD_DELAY=1000
|
||||||
procd_add_config_trigger "config.change" "travelmate" "${trm_init}" start
|
procd_add_config_trigger "config.change" "travelmate" "${trm_init}" start
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,23 +10,25 @@
|
||||||
#
|
#
|
||||||
LC_ALL=C
|
LC_ALL=C
|
||||||
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
|
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_sysver="$(ubus -S call system board | jsonfilter -e '@.release.description')"
|
||||||
trm_enabled=0
|
trm_enabled=0
|
||||||
trm_debug=0
|
trm_debug=0
|
||||||
trm_automatic=0
|
trm_automatic=1
|
||||||
trm_maxwait=30
|
|
||||||
trm_maxretry=3
|
trm_maxretry=3
|
||||||
|
trm_maxwait=30
|
||||||
trm_timeout=60
|
trm_timeout=60
|
||||||
trm_iw=1
|
trm_iw=1
|
||||||
|
trm_rtfile="/tmp/trm_runtime.json"
|
||||||
|
|
||||||
# source required system library
|
# source required system library
|
||||||
#
|
#
|
||||||
if [ -r "/lib/functions.sh" ]
|
if [ -r "/lib/functions.sh" ] && [ -r "/usr/share/libubox/jshn.sh" ]
|
||||||
then
|
then
|
||||||
. "/lib/functions.sh"
|
. "/lib/functions.sh"
|
||||||
|
. "/usr/share/libubox/jshn.sh"
|
||||||
else
|
else
|
||||||
f_log "error" "required system library not found"
|
f_log "error" "system libraries not found"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# f_envload: load travelmate environment
|
# 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_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}
|
json_init
|
||||||
do
|
json_add_object "data"
|
||||||
active_triggers="${active_triggers}[\"interface.*.down\",[\"if\",[\"eq\",\"interface\",\"${name}\"],[\"run_script\",\"/etc/init.d/travelmate\",\"start\"],1000]],"
|
json_add_string "travelmate_version" "${trm_ver}"
|
||||||
done
|
json_add_string "station_connection" "${trm_ifstatus}"
|
||||||
active_triggers="${active_triggers}[\"config.change\",[\"if\",[\"eq\",\"package\",\"travelmate\"],[\"run_script\",\"/etc/init.d/travelmate\",\"start\"],1000]]"
|
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}"
|
||||||
|
}
|
||||||
|
|
||||||
ubus call service add "{\"name\":\"travelmate\",
|
# f_status: output runtime information
|
||||||
\"instances\":{\"travelmate\":{\"command\":[\"/usr/bin/travelmate.sh\"],
|
#
|
||||||
\"data\":{\"travelmate_version\":\"${trm_ver}\",
|
f_status()
|
||||||
\"station_interface\":\"${iface}\",
|
{
|
||||||
\"station_radio\":\"${radio}\",
|
local key keylist value
|
||||||
\"station_ssid\":\"${ssid}\",
|
|
||||||
\"last_rundate\":\"$(/bin/date "+%d.%m.%Y %H:%M:%S")\",
|
if [ -s "${trm_rtfile}" ]
|
||||||
\"online_status\":\"${trm_ifstatus}\",
|
then
|
||||||
\"system\":\"${trm_sysver}\"}}},
|
printf "%s\n" "::: travelmate runtime information"
|
||||||
\"triggers\":[${active_triggers}]}"
|
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
|
# f_log: write to syslog, exit on error
|
||||||
|
@ -191,7 +208,6 @@ f_main()
|
||||||
then
|
then
|
||||||
uci -q commit wireless
|
uci -q commit wireless
|
||||||
ubus call network reload
|
ubus call network reload
|
||||||
sleep 5
|
|
||||||
fi
|
fi
|
||||||
f_check "ap"
|
f_check "ap"
|
||||||
f_log "debug" "ap-list: ${trm_aplist}, sta-list: ${trm_stalist}"
|
f_log "debug" "ap-list: ${trm_aplist}, sta-list: ${trm_stalist}"
|
||||||
|
@ -236,14 +252,13 @@ f_main()
|
||||||
then
|
then
|
||||||
uci -q commit wireless
|
uci -q commit wireless
|
||||||
f_log "info " "interface '${sta_iface}' on '${sta_radio}' connected to uplink '${sta_ssid}' (${trm_sysver})"
|
f_log "info " "interface '${sta_iface}' on '${sta_radio}' connected to uplink '${sta_ssid}' (${trm_sysver})"
|
||||||
sleep 5
|
f_jsnupdate "${sta_iface}" "${sta_radio}" "${sta_ssid}"
|
||||||
f_ubus "${sta_iface}" "${sta_radio}" "${sta_ssid}"
|
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
uci -q revert wireless
|
uci -q revert wireless
|
||||||
ubus call network reload
|
ubus call network reload
|
||||||
f_log "info " "interface '${sta_iface}' on '${sta_radio}' can't connect to uplink '${sta_ssid}' (${trm_sysver})"
|
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
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -255,12 +270,21 @@ f_main()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# handle different travelmate actions
|
||||||
|
#
|
||||||
f_envload
|
f_envload
|
||||||
f_main
|
case "${1}" in
|
||||||
while [ ${trm_automatic} -eq 1 ]
|
status)
|
||||||
do
|
f_status
|
||||||
sleep ${trm_timeout}
|
;;
|
||||||
f_envload
|
*)
|
||||||
f_main
|
f_main
|
||||||
done
|
while [ ${trm_automatic} -eq 1 ]
|
||||||
|
do
|
||||||
|
sleep ${trm_timeout}
|
||||||
|
f_envload
|
||||||
|
f_main
|
||||||
|
done
|
||||||
|
;;
|
||||||
|
esac
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in a new issue