From 719bdfb00b178c4e8d383ad917a85ea5a2752be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=90=E8=AF=9D?= <49544781+xiaomeng9597@users.noreply.github.com> Date: Mon, 1 Jul 2024 23:38:12 +0800 Subject: [PATCH] update ubus-status.sh --- configfiles/ubus-status.sh | 39 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/configfiles/ubus-status.sh b/configfiles/ubus-status.sh index 63c494c..2f19b90 100644 --- a/configfiles/ubus-status.sh +++ b/configfiles/ubus-status.sh @@ -1,16 +1,5 @@ #!/bin/sh -rpcd_start() { - ubusval=$(/etc/init.d/dbus status 2>&1) - if echo "$ubusval" | grep -q "Failed" || echo "$ubusval" | grep -q "Failed to connect to ubus" || echo "$ubusval" | grep -q "inactive"; then - killall ubusd 2>/dev/null - sleep 1 - /sbin/rpcd -s /var/run/ubus/ubus.sock -t 30 & - else - /sbin/rpcd -s /var/run/ubus/ubus.sock -t 30 & - fi -} - check_ubus() { local pidcount=$(pgrep "ubusd" | wc -l) local pidcount2=$(pgrep "rpcd" | wc -l) @@ -28,29 +17,31 @@ check_ubus() { /sbin/ubusd & fi + if [ "$(pgrep rpcd | wc -l)" -eq 0 ] && [ "$(pgrep ubusd | wc -l)" -eq 1 ]; then + sleep 1 + /sbin/rpcd -s /var/run/ubus/ubus.sock -t 30 & + fi + local datetime=$(date +"%Y-%m-%d %H:%M:%S") - local dbus_status=$(/etc/init.d/dbus status 2>&1) + local rpcd_status=$(/etc/init.d/rpcd 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" fi - if [ "$(pgrep rpcd | wc -l)" -eq 0 ] && [ "$(pgrep ubusd | wc -l)" -eq 1 ]; then - echo "$datetime / Ubus服务异常,正在重启Ubus。" - sleep 1 - rpcd_start - elif [[ "$status_code" == 500 || "$status_code" == 502 ]] && echo "$dbus_status" | grep -q "running"; then + if [[ "$status_code" == 500 || "$status_code" == 502 ]] && echo "$rpcd_status" | grep -q "running"; then echo "$datetime / Ubus服务异常,正在重启Ubus。" killall rpcd 2>/dev/null sleep 1 - rpcd_start - elif echo "$dbus_status" | grep -q "running"; then + /sbin/rpcd -s /var/run/ubus/ubus.sock -t 30 & + elif echo "$rpcd_status" | grep -q "failed" || echo "$rpcd_status" | grep -q "Command failed" || echo "$rpcd_status" | grep -q "Failed" || echo "$rpcd_status" | grep -q "Failed to connect to ubus" || echo "$rpcd_status" | grep -q "inactive"; then + echo "$datetime / Ubus服务异常,正在重启Ubus。" + killall ubusd 2>/dev/null + killall rpcd 2>/dev/null + sleep 1 + /sbin/rpcd -s /var/run/ubus/ubus.sock -t 30 & + elif echo "$rpcd_status" | grep -q "running"; then echo "$datetime / Ubus服务正在运行,一切正常。" - else - echo "$datetime / Ubus服务异常,正在重启Ubus。" - killall rpcd 2>/dev/null - sleep 1 - rpcd_start fi }