From 01319da558a98015278ee27037418e8363032013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=90=E8=AF=9D?= <49544781+xiaomeng9597@users.noreply.github.com> Date: Fri, 21 Jun 2024 16:50:19 +0800 Subject: [PATCH] update ubus-status.sh --- configfiles/ubus-status.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/configfiles/ubus-status.sh b/configfiles/ubus-status.sh index eb41830..8232fae 100644 --- a/configfiles/ubus-status.sh +++ b/configfiles/ubus-status.sh @@ -1,9 +1,8 @@ #!/bin/sh -while true -do - pidcount=$(pgrep "ubusd" | wc -l) - pidcount2=$(pgrep "rpcd" | wc -l) +check_ubus() { + local pidcount=$(pgrep "ubusd" | wc -l) + local pidcount2=$(pgrep "rpcd" | wc -l) if [ "$pidcount" -gt 1 ]; then killall ubusd @@ -21,11 +20,11 @@ do /sbin/rpcd -s /var/run/ubus/ubus.sock -t 30 & fi - datetime=$(date +"%Y-%m-%d %H:%M:%S") - dbus_status=$(/etc/init.d/dbus status 2>&1) - status_code=$(curl -o /dev/null -s -w "%{http_code}\n" http://127.0.0.1/cgi-bin/luci/ 2>/dev/null) + local datetime=$(date +"%Y-%m-%d %H:%M:%S") + local dbus_status=$(/etc/init.d/dbus status 2>&1) + local status_code=$(curl -o /dev/null -s -w "%{http_code}\n" http://127.0.0.1/cgi-bin/luci/ 2>/dev/null) if [ -z "$status_code" ]; then - status_code="ERROR" + local status_code="ERROR" fi if [[ "$status_code" == 500 || "$status_code" == 502 ]] && echo "$dbus_status" | grep -q "running"; then @@ -42,5 +41,9 @@ do sleep 1 /sbin/rpcd -s /var/run/ubus/ubus.sock -t 30 & fi +} + +while true; do +check_ubus sleep 60 done