2021-10-01 02:17:38 +08:00
|
|
|
#!/bin/sh /etc/rc.common
|
|
|
|
|
2022-10-18 20:28:10 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2020-2022 sirpdboy <herboy2008@gmail.com> https://github.com/sirpdboy/netspeedtest
|
|
|
|
#
|
|
|
|
# This file is part of ddns-go .
|
|
|
|
#
|
|
|
|
# This is free software, licensed under the Apache License, Version 2.0 .
|
|
|
|
#
|
2021-10-01 02:17:38 +08:00
|
|
|
|
2022-10-18 20:28:10 +08:00
|
|
|
START=99
|
|
|
|
USE_PROCD=1
|
|
|
|
|
|
|
|
|
|
|
|
PROG=/usr/bin/speedtest-web
|
2021-10-01 02:17:38 +08:00
|
|
|
EXTRA_COMMANDS="nstest"
|
2022-10-18 20:28:10 +08:00
|
|
|
|
|
|
|
TMP_T=/var/netspeedtest.tmp
|
|
|
|
LOCK=/var/lock/netspeedtest.lock
|
|
|
|
LOG=/var/log/netspeedtest.log
|
2021-10-01 02:17:38 +08:00
|
|
|
|
|
|
|
limit_log() {
|
|
|
|
local logf=$1
|
|
|
|
[ ! -f "$logf" ] && return
|
|
|
|
local sc=100
|
|
|
|
[ -n "$2" ] && sc=$2
|
|
|
|
local count=$(grep -c "" $logf)
|
|
|
|
if [ $count -gt $sc ];then
|
|
|
|
let count=count-$sc
|
|
|
|
sed -i "1,$count d" $logf
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
init_env() {
|
2022-10-18 20:28:10 +08:00
|
|
|
[ ! -f "$LOG" ] && echo "" > $LOG
|
|
|
|
echo 1 > $TMP_T
|
2021-10-01 02:17:38 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
nstest() {
|
2022-10-18 20:28:10 +08:00
|
|
|
[ -f $LOCK ] && exit
|
|
|
|
limit_log $LOG 200
|
2021-10-01 02:17:38 +08:00
|
|
|
init_env
|
2022-10-18 20:28:10 +08:00
|
|
|
touch $LOCK
|
|
|
|
/usr/bin/speedtest --share > $TMP_T
|
|
|
|
echo -ne "\n 测服信息:$(cat $TMP_T | grep 'Hosted by'| cut -c10- | awk -F: '{printf $1}') 延时:$(cat $TMP_T | grep 'Hosted by' | awk -F: '{printf $2}')" >> $LOG
|
|
|
|
echo -ne "\n 下行速率:$(cat $TMP_T | grep 'Download:' |awk -F: '{printf $2}' )" >> $LOG
|
|
|
|
echo -ne " ---- 上行速率:$(cat $TMP_T | grep 'Upload:' |awk -F: '{printf $2}' )" >> $LOG
|
|
|
|
echo -ne "\n 测试时间: " >> $LOG
|
|
|
|
echo $(date +%Y-%m-%d" "%H:%M:%S) >> $LOG
|
|
|
|
echo -ne " ————————————————————————————\n" >> $LOG
|
|
|
|
echo -ne $(cat $TMP_T | grep 'results:' | cut -c16- )
|
|
|
|
rm -f $LOCK
|
2021-10-01 02:17:38 +08:00
|
|
|
}
|
|
|
|
|
2022-10-18 20:28:10 +08:00
|
|
|
get_config() {
|
|
|
|
config_get_bool enabled $1 enabled 1
|
|
|
|
config_get_bool logger $1 logger 1
|
|
|
|
config_get port $1 port 8989
|
2021-10-01 02:17:38 +08:00
|
|
|
}
|
|
|
|
|
2022-10-18 20:28:10 +08:00
|
|
|
speedtestweb_prepare() {
|
|
|
|
pgrep -f speedtest-web | xargs kill -9 >/dev/null 2>&1
|
|
|
|
logger -t netspeedtest -p warn "Netspeedtest speedtest-web is stop."
|
|
|
|
}
|
|
|
|
|
|
|
|
stop_service() {
|
|
|
|
speedtestweb_prepare
|
|
|
|
echo "Netspeedtest speedtest-web is stop."
|
|
|
|
}
|
|
|
|
|
|
|
|
start_service() {
|
|
|
|
speedtestweb_prepare
|
|
|
|
config_load netspeedtest
|
|
|
|
config_foreach get_config speedtestweb
|
|
|
|
[ x$enabled == x1 ] || return 1
|
|
|
|
logger -t netspeedtest -p warn "Netspeedtest speedtest-web is start."
|
|
|
|
echo "Netspeedtest speedtest-web is start."
|
|
|
|
procd_open_instance
|
|
|
|
procd_set_param command $PROG --listen_port "${port}"
|
|
|
|
[ "x$logger" == x1 ] && procd_set_param stderr 1
|
|
|
|
procd_set_param respawn
|
|
|
|
procd_close_instance
|
2021-10-01 02:17:38 +08:00
|
|
|
}
|
2022-10-18 20:28:10 +08:00
|
|
|
|
|
|
|
service_triggers() {
|
|
|
|
procd_add_reload_trigger "speedtest-web"
|
|
|
|
}
|
|
|
|
|