From bd790383ca08673b176e8a6e1f836cb725066913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=90=E8=AF=9D?= <49544781+xiaomeng9597@users.noreply.github.com> Date: Sat, 29 Jun 2024 13:28:25 +0800 Subject: [PATCH] update ubus-status.sh --- configfiles/ubus-status.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/configfiles/ubus-status.sh b/configfiles/ubus-status.sh index 77916e2..e8861c8 100644 --- a/configfiles/ubus-status.sh +++ b/configfiles/ubus-status.sh @@ -1,5 +1,15 @@ #!/bin/sh +rpcd_start() { + rpcdstr=$(/sbin/rpcd -s /var/run/ubus/ubus.sock -t 30 &) + if echo "$rpcdstr" | grep -q "Failed" || echo "$rpcdstr" | grep -q "Failed to connect to ubus"; then + killall ubusd 2>/dev/null + sleep 1 + /sbin/ubusd & + /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) @@ -27,19 +37,19 @@ check_ubus() { if [ "$(pgrep rpcd | wc -l)" -eq 0 ] && [ "$(pgrep ubusd | wc -l)" -eq 1 ]; then echo "$datetime / Ubus服务异常,正在重启Ubus。" sleep 1 - /sbin/rpcd -s /var/run/ubus/ubus.sock -t 30 & + rpcd_start elif [[ "$status_code" == 500 || "$status_code" == 502 ]] && echo "$dbus_status" | grep -q "running"; then echo "$datetime / Ubus服务异常,正在重启Ubus。" killall rpcd sleep 1 - /sbin/rpcd -s /var/run/ubus/ubus.sock -t 30 & + rpcd_start elif echo "$dbus_status" | grep -q "running"; then echo "$datetime / Ubus服务正在运行,一切正常。" else echo "$datetime / Ubus服务异常,正在重启Ubus。" killall rpcd sleep 1 - /sbin/rpcd -s /var/run/ubus/ubus.sock -t 30 & + rpcd_start fi }