Commit 16c4cd10 authored by Stephan's avatar Stephan
Browse files

Merge branch 'se-timeout-bmxd' into 'master'

bmxd,sshkey,led

See merge request !130
parents eb2e40ac f42a0181
Pipeline #1686 passed with stages
in 102 minutes and 39 seconds
......@@ -73,6 +73,7 @@
"selector-config":"18.06", # used to select config
"selector-feeds":"18.06", # used to select feeds
"selector-patches":"18.06", # used to select patches
"selector-files":"18.06",
"feeds" : [
{"type":"src-link", "name":"ddmesh_own", "src":"feeds-own" },
{"type":"src-git", "name":"packages", "src":"https://git.openwrt.org/feed/packages.git", "rev":"de3766173"},
......@@ -90,6 +91,7 @@
"selector-config":"18.06", # used to select config
"selector-feeds":"18.06", # used to select feeds
"selector-patches":"18.06", # used to select patches
"selector-files":"18.06",
"feeds" : [
{"type":"src-link", "name":"ddmesh_own", "src":"feeds-own" },
{"type":"src-git", "name":"packages", "src":"https://git.openwrt.org/feed/packages.git", "rev":"de3766173"},
......@@ -153,6 +155,7 @@
"selector-config":"18.06", # used to select config
"selector-feeds":"18.06", # used to select feeds
"selector-patches":"18.06", # used to select patches
"selector-files":"18.06",
"feeds" : [
{"type":"src-link", "name":"ddmesh_own", "src":"feeds-own" },
{"type":"src-git", "name":"packages", "src":"https://git.openwrt.org/feed/packages.git", "rev":"de3766173"},
......
......@@ -154,11 +154,6 @@ show_progress()
tput cup $(( $row - 3)) 0
}
if [ "$_TERM" = "1" ]; then
trap clean_up SIGINT SIGTERM
trap show_progress WINCH
fi
############# build.sh functions ####################
......@@ -463,6 +458,11 @@ fi
echo "### target-regex:[$regex] MENUCONFIG=$MENUCONFIG CLEAN=$MAKE_CLEAN REBUILD_ON_FAILURE=$REBUILD_ON_FAILURE"
if [ "$_TERM" = "1" ]; then
trap clean_up SIGINT SIGTERM
trap show_progress WINCH
fi
setup_buildroot ()
{
buildroot=$1
......@@ -529,15 +529,17 @@ setup_buildroot ()
rm -f $buildroot/dl
ln -s ../../$openwrt_dl_dir $buildroot/dl
# -------- common files -----------
# copy common files first
echo -e "$C_PURPLE copy rootfs $C_NONE: $C_GREEN common $C_NONE"
echo -e "${C_PURPLE}copy rootfs ${C_NONE}: ${C_GREEN} common ${C_NONE}"
rm -rf $buildroot/files
mkdir -p $buildroot/files
cp -a $RUN_DIR/files/common/* $buildroot/files/
# -------- specific files -----------
# copy specific files over (may overwrite common)
echo -e "$C_PURPLE copy specific files $C_NONE: $C_GREEN $firmware_files $C_NONE"
test -d "$RUN_DIR/files/$firmware_files)" && cp -a $RUN_DIR/files/$firmware_files/* $buildroot/files/
echo -e "${C_PURPLE}copy specific files ${C_NONE}: ${C_GREEN}${firmware_files}${C_NONE}"
test -d "$RUN_DIR/files/$firmware_files" && cp -a $RUN_DIR/files/$firmware_files/* $buildroot/files/
echo -e $C_PURPLE"create rootfs/etc/built_info file"$C_NONE
mkdir -p $buildroot/files/etc
......@@ -712,7 +714,6 @@ do
test -z "$filterred" && continue
if [ "$_TERM" = "1" ]; then
echo $progress_counter $progress_max
show_progress $progress_counter $progress_max
progress_counter=$(( $progress_counter + 1 ))
echo ""
......
2021-04-00 7.0.3
--------------------------------------------------
bmxd - improvments to bmxd watchdog
gui - minor text corrections
ssh - add ssh-key (authorized_keys) support
led - improve LED detection
2021-04-00 7.0.2
--------------------------------------------------
bmxd - add keep alive watchdog
......
#!/bin/sh
ARG1=$1
ARG2=$2
DAEMON=bmxd
DAEMON_PATH=/usr/bin
TIMEOUT="$(which timeout)"
test -x $DAEMON_PATH/$DAEMON || exit 0
DB_PATH=/var/lib/ddmesh/bmxd
STAT_DIR=/var/statistic
WD_FILE=/tmp/state/bmxd.watchdog
TAG="bmxd"
# maximal parallel instances (used internally and gui)
bmxd_max_instances=5
mkdir -p $DB_PATH
mkdir -p $STAT_DIR
touch $DB_PATH/links
touch $DB_PATH/gateways
touch $DB_PATH/originators
touch $DB_PATH/status
touch $DB_PATH/networks # network ids
touch $STAT_DIR/gateway_usage
eval $(/usr/lib/ddmesh/ddmesh-ipcalc.sh -n $(uci get ddmesh.system.node))
if [ "$ARG1" = "start" -o "$ARG1" = "no_gateway" ]; then
ROUTING_CLASS="$(uci -q get ddmesh.bmxd.routing_class)"
ROUTING_CLASS="${ROUTING_CLASS:-3}"
ROUTING_CLASS="-r $ROUTING_CLASS --gateway_hysteresis 20"
fi
if [ "$ARG1" = "start" -o "$ARG1" = "gateway" ]; then
GATEWAY_CLASS="$(uci -q get ddmesh.bmxd.gateway_class)"
GATEWAY_CLASS="${GATEWAY_CLASS:-512/512}"
GATEWAY_CLASS="-g $GATEWAY_CLASS"
fi
case "$ARG1" in
start)
MESH_NETWORK_ID="$(uci -q get ddmesh.network.mesh_network_id)"
MESH_NETWORK_ID="${MESH_NETWORK_ID:-0}"
PREFERRED_GATEWAY="$(uci -q get ddmesh.bmxd.preferred_gateway | sed -n '/^[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+$/p')"
test -n "$PREFERRED_GATEWAY" && PREFERRED_GATEWAY="-p $PREFERRED_GATEWAY"
# create a virtual interface for primary interface. loopback has
# 127er IP which would be broadcasted
PRIMARY_IF="bmx_prime"
FASTD_IF="tbb_fastd"
LAN_IF="br-mesh_lan"
WAN_IF="br-mesh_wan"
brctl addbr $PRIMARY_IF
ip addr add $_ddmesh_ip/$_ddmesh_netpre broadcast $_ddmesh_broadcast dev $PRIMARY_IF
ip link set dev $PRIMARY_IF up
_IF="dev=$PRIMARY_IF /linklayer 0 dev=$FASTD_IF /linklayer 1 dev=$LAN_IF /linklayer 1 dev=$WAN_IF /linklayer 1"
# needed during async boot
/usr/lib/ddmesh/ddmesh-utils-network-info.sh update
#add wifi, if hotplug event did occur before starting bmxd
eval $(/usr/lib/ddmesh/ddmesh-utils-network-info.sh wifi_adhoc)
if [ -n "$net_ifname" ]; then
_IF="$_IF dev=$net_ifname /linklayer 2"
fi
eval $(/usr/lib/ddmesh/ddmesh-utils-network-info.sh wifi_mesh2g)
if [ -n "$net_ifname" ]; then
_IF="$_IF dev=$net_ifname /linklayer 2"
fi
eval $(/usr/lib/ddmesh/ddmesh-utils-network-info.sh wifi_mesh5g)
if [ -n "$net_ifname" ]; then
_IF="$_IF dev=$net_ifname /linklayer 2"
fi
#default start with no gatway.will be updated by gateway_check.sh
#SPECIAL_OPTS="--throw-rules 0 --prio-rules 0 --meshNetworkIdPreferred $MESH_NETWORK_ID"
SPECIAL_OPTS="--throw-rules 0 --prio-rules 0"
TUNNEL_OPTS="--gateway_tunnel_network $_ddmesh_network/$_ddmesh_netpre --one-way-tunnel 1"
TUNING_OPTS="--purge_timeout 20"
DAEMON_OPTS="$SPECIAL_OPTS $TUNNEL_OPTS $TUNING_OPTS $ROUTING_CLASS $PREFERRED_GATEWAY $_IF"
# set initial wifi ssid to "FF no-inet"
/usr/lib/bmxd/bmxd-gateway.sh init
echo "Starting $DAEMON: opt: $DAEMON_OPTS"
$DAEMON_PATH/$DAEMON $DAEMON_OPTS
;;
stop)
echo "Stopping $DAEMON: "
killall -9 $DAEMON
;;
restart)
$0 stop
sleep 1
$0 start
;;
gateway)
echo $DAEMON -c $GATEWAY_CLASS
$DAEMON_PATH/$DAEMON -c $GATEWAY_CLASS
;;
no_gateway)
echo $DAEMON -c $ROUTING_CLASS
$DAEMON_PATH/$DAEMON -c $ROUTING_CLASS
;;
add_if)
$DAEMON_PATH/$DAEMON -c dev=$ARG2 /linklayer 2
;;
del_if)
$DAEMON_PATH/$DAEMON -c dev=-$ARG2
;;
runcheck)
bmxd_restart=0
# watchdog timestamp check: bmxd present as process, but dead
# or present as zombi process "[bmxd]"
# devel: run "bmxd -lcd4&" more than 12 times will create this situation
MAX_BMXD_TIME=300
cur=$(date '+%s')
wd=$cur # default,keep diff small after start
if [ -f $WD_FILE ]; then
wd=$(cat $WD_FILE)
fi
d=$(( $cur - $wd))
if [ "$d" -gt $MAX_BMXD_TIME ]; then
logger -s -t "$TAG" "bmxd: kill bmxd (diff $d)"
# delete file, to reset timeout
rm $WD_FILE
killall -9 $DAEMON
bmxd_restart=1
fi
# connection check; if bmxd hangs, kill it
# check for existance of "timeout" cmd, else bmxd will be killed every time
if [ -n "$TIMEOUT" ]; then
$TIMEOUT -t 10 -s 9 $DAEMON -c --status >/dev/null
if [ $? != 0 ]; then
logger -s -t "$TAG" "bmxd: connection failed"
killall -9 $DAEMON
bmxd_restart=1
fi
fi
# too many instances running (count no zombies)
bmxd_count=$(ps | awk '{ if(match($4,"Z")==0 && (match($5,"^bmxd$") || match($5,"^/usr/bin/bmxd$")) ){print $5}}' | wc -l)
test "$bmxd_count" -gt $bmxd_max_instances && logger -s -t "$TAG" "bmxd: too many instances ($bmxd_count/$bmxd_max_instances)" && bmxd_restart=1
test $bmxd_restart = 1 && logger -s -t "$TAG" "$DAEMON not running - restart" && $0 restart
;;
update_infos)
$DAEMON_PATH/$DAEMON -c --gateways > $DB_PATH/gateways
$DAEMON_PATH/$DAEMON -c --links > $DB_PATH/links
$DAEMON_PATH/$DAEMON -c --originators > $DB_PATH/originators
$DAEMON_PATH/$DAEMON -c --status > $DB_PATH/status
# $DAEMON_PATH/$DAEMON -c --networks > $DB_PATH/networks
$DAEMON_PATH/$DAEMON -ci > $DB_PATH/info
;;
*)
echo "Usage: $0 {start|stop|restart|gateway|no_gateway|runcheck|update_infos|add_if|del_if}" >&2
exit 1 ;;
esac
exit 0
......@@ -5,12 +5,16 @@ ARG2=$2
DAEMON=bmxd
DAEMON_PATH=/usr/bin
TIMEOUT="$(which timeout)"
test -x $DAEMON_PATH/$DAEMON || exit 0
RUN_STATUS_FILE=/var/run/batman-status-running
DB_PATH=/var/lib/ddmesh/bmxd
STAT_DIR=/var/statistic
WD_FILE=/tmp/state/bmxd.watchdog
TAG="bmxd"
# maximal parallel instances (used internally and gui)
bmxd_max_instances=5
mkdir -p $DB_PATH
mkdir -p $STAT_DIR
......@@ -100,18 +104,12 @@ case "$ARG1" in
killall -9 $DAEMON
;;
restart|force-reload)
restart)
$0 stop
sleep 1
$0 start
;;
nightly)
logger -t bmx-nightly "bmxd restart bat0: $(ip addr show bat0 | grep 'inet')"
$0 stop
$0 start
;;
gateway)
echo $DAEMON -c $GATEWAY_CLASS
$DAEMON_PATH/$DAEMON -c $GATEWAY_CLASS
......@@ -127,23 +125,62 @@ case "$ARG1" in
del_if)
$DAEMON_PATH/$DAEMON -c dev=-$ARG2
;;
check)
test -z "$(pidof $DAEMON)" && logger -s "$DAEMON not running - restart" && $0 restart && exit
test -n "$(pidof $DAEMON)" && test ! -f "$RUN_STATUS_FILE" && (
touch $RUN_STATUS_FILE
runcheck)
bmxd_restart=0
# watchdog timestamp check: bmxd present as process, but dead
# or present as zombi process "[bmxd]"
# devel: run "bmxd -lcd4&" more than 12 times will create this situation
MAX_BMXD_TIME=300
cur=$(date '+%s')
wd=$cur # default,keep diff small after start
if [ -f $WD_FILE ]; then
wd=$(cat $WD_FILE)
fi
d=$(( $cur - $wd))
if [ "$d" -gt $MAX_BMXD_TIME ]; then
logger -s -t "$TAG" "bmxd: kill bmxd (diff $d)"
# delete file, to reset timeout
rm $WD_FILE
killall -9 $DAEMON
bmxd_restart=1
fi
# connection check; if bmxd hangs, kill it
# check for existance of "timeout" cmd, else bmxd will be killed every time
if [ -n "$TIMEOUT" ]; then
$TIMEOUT -s 9 10 $DAEMON -c --status >/dev/null
if [ $? != 0 ]; then
logger -s -t "$TAG" "bmxd: connection failed"
killall -9 $DAEMON
bmxd_restart=1
fi
fi
# too many instances running (count no zombies)
bmxd_count=$(ps | awk '{ if(match($4,"Z")==0 && (match($5,"^bmxd$") || match($5,"^/usr/bin/bmxd$")) ){print $5}}' | wc -l)
test "$bmxd_count" -gt $bmxd_max_instances && logger -s -t "$TAG" "bmxd: too many instances ($bmxd_count/$bmxd_max_instances)" && bmxd_restart=1
test $bmxd_restart = 1 && logger -s -t "$TAG" "$DAEMON not running - restart" && $0 restart
;;
update_infos)
$DAEMON_PATH/$DAEMON -c --gateways > $DB_PATH/gateways
$DAEMON_PATH/$DAEMON -c --links > $DB_PATH/links
$DAEMON_PATH/$DAEMON -c --originators > $DB_PATH/originators
$DAEMON_PATH/$DAEMON -c --status > $DB_PATH/status
# $DAEMON_PATH/$DAEMON -c --networks > $DB_PATH/networks
$DAEMON_PATH/$DAEMON -ci > $DB_PATH/info
rm $RUN_STATUS_FILE
)
;;
*)
echo "Usage: $0 {start|stop|restart|gateway|no_gateway|check|add_if|del_if}" >&2
echo "Usage: $0 {start|stop|restart|gateway|no_gateway|runcheck|update_infos|add_if|del_if}" >&2
exit 1 ;;
......
......@@ -133,7 +133,7 @@ POST /geoloc HTTP/1.1
User-Agent: Wget/1.17.1 (linux-gnu)
Accept: */*
Accept-Encoding: identity
Host: api.main.freifunk-dresden.de
Host: api.freifunk-dresden.de
Connection: Keep-Alive
Content-Type: application/json
Content-Length: $SIZE
......
......@@ -18,127 +18,141 @@ eval $(cat /etc/openwrt_release)
platform="${DISTRIB_TARGET%/*}"
boardname=$(board_name) # function in function.sh
#echo "platform: $platform"
#echo "board: $boardname"
echo "platform: $platform"
echo "board: $boardname"
# try to detect led (keep order)
eval $(ddmesh-utils-wifi-info.sh)
#---- wifi2g
# "link2" nanostation
for i in wifi wlan wlan2g link2 ${wifi_status_radio2g_phy} usb
do
tmp="$(ls -d /sys/class/leds/*${i} 2>/dev/null | sed -n '1p')"
test -n "$tmp" && break
done
_led_wifi2g="$(echo $tmp | sed -n '1s#/sys/class/leds/##p')"
#---- wifi5g
for i in wlan5g ${wifi_status_radio5g_phy}
do
tmp="$(ls -d /sys/class/leds/*${i} 2>/dev/null | sed -n '1p')"
test -n "$tmp" && break
done
_led_wifi5g="$(echo $tmp | sed -n '1s#/sys/class/leds/##p')"
#---- status
# "link1" nanostation
for i in system info power wps usb link1
do
tmp="$(ls -d /sys/class/leds/*${i} 2>/dev/null | sed -n '1p')"
test -n "$tmp" && break
done
_led_status="$(echo $tmp | sed -n '1s#/sys/class/leds/##p')"
#---- wwan
_led_wwan=""
case "$platform" in
ar71xx)
. /etc/diag.sh
get_status_led # /etc/diag.sh
case "$boardname" in
gl-mifi) _led_wwan="$(uci -q get system.led_wwan.sysfs)"
test -z "$_led_wwan" && _led_wwan="gl-mifi:green:net"
_led_status="$(uci -q get system.led_wan.sysfs)"
;;
*) _led_wifi="$(uci -q get system.led_wlan.sysfs)"
test -z "$_led_wifi" && _led_wifi="$(uci -q get system.led_rssimediumlow.sysfs)"
_led_status=$status_led
_led_wwan=""
;;
esac
;;
ath79)
case "$boardname" in
"ubnt,unifi") _led_wifi="ubnt:orange:dome"
"ubnt,unifi") _led_wifi2g="ubnt:orange:dome"
_led_status="ubnt:green:dome"
;;
*) _led_wifi="$(uci -q get system.led_wlan.sysfs)"
;;
esac
;;
lantiq|ipq40xx)
case "$boardname" in
*)
for i in wifi wlan
do
tmp="$(ls -d /sys/class/leds/*:$i 2>/dev/null)"
test -n "$tmp" && break
done
_led_wifi="$(echo $tmp | sed -n '1s#/sys/class/leds/##p')"
_led_status="$(uci -q get system.led_dsl.sysfs)"
;;
esac
;;
ramips)
case "$boardname" in
*)
_led_wifi="$(echo /sys/class/leds/*:*:usb | sed -n '1s#/sys/class/leds/##p')"
;;
esac
;;
*)
echo "$(basename $0): platform '$platform' not supported"
exit 1
;;
esac
#echo "_led_status: $_led_status"
#echo "_led_wifi: $_led_wifi"
#echo "_led_wwan: $_led_wwan"
echo "_led_status: $_led_status"
echo "_led_wifi2g: $_led_wifi2g"
echo "_led_wifi5g: $_led_wifi5g"
echo "_led_wwan: $_led_wwan"
case $1 in
case "$1" in
wifi)
case $2 in
off)
led_off $_led_wifi
;;
alive)
led_timer $_led_wifi 30 1000
;;
freifunk)
led_timer $_led_wifi 200 200
;;
gateway)
led_timer $_led_wifi 60 60
;;
esac
if [ -n "$_led_wifi2g" ]; then
case $2 in
off)
led_off $_led_wifi2g
;;
alive)
led_timer $_led_wifi2g 30 1000
;;
freifunk)
led_timer $_led_wifi2g 200 200
;;
gateway)
led_timer $_led_wifi2g 60 60
;;
esac
fi
if [ -n "$_led_wifi5g" ]; then
case $2 in
off)
led_off $_led_wifi5g
;;
alive)
led_timer $_led_wifi5g 30 1000
;;
freifunk)
led_timer $_led_wifi5g 200 200
;;
gateway)
led_timer $_led_wifi5g 60 60
;;
esac
fi
;;
status)
case $2 in
boot1) led_timer $_led_status 30 30
;;
boot2) led_timer $_led_status 60 60
;;
boot3) led_timer $_led_status 110 110
;;
done)
case "$boardname" in
"ubnt,unifi"|"gl-mifi")
# one LED: turn green off to enable orange
led_off $_led_status
;;
*)
led_on $_led_status
;;
esac
;;
esac
if [ -n "$_led_status" ]; then
case $2 in
boot1) led_timer $_led_status 50 50
;;
boot2) led_timer $_led_status 100 100
;;
boot3) led_timer $_led_status 150 150
;;
done) led_off $_led_status
;;
esac
fi
;;
wwan)
case $2 in
off)
led_off $_led_wwan
;;
2g)
led_timer $_led_wwan 1000 1000
;;
3g)
led_timer $_led_wwan 300 200
;;
4g)
led_timer $_led_wwan 40 40
;;
esac
if [ -n "$_led_wwan" ]; then