From 66ec46b0ebd75b3a96c618e9c4c9f5297e9003d7 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 13:13:12 +0800 Subject: [PATCH] update ubus-status.sh --- configfiles/ubus-status.sh | 48 +++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/configfiles/ubus-status.sh b/configfiles/ubus-status.sh index e739ac4..eb41830 100644 --- a/configfiles/ubus-status.sh +++ b/configfiles/ubus-status.sh @@ -2,39 +2,33 @@ while true do + pidcount=$(pgrep "ubusd" | wc -l) + pidcount2=$(pgrep "rpcd" | wc -l) + + if [ "$pidcount" -gt 1 ]; then + killall ubusd + fi + + if [ "$pidcount2" -gt 2 ] && [ "$pidcount" -eq 1 ]; then + killall rpcd + fi + + if [ "$(pgrep ubusd | wc -l)" -eq 0 ]; then + /sbin/ubusd & + fi + + if [ "$(pgrep rpcd | wc -l)" -eq 0 ] && [ "$(pgrep ubusd | wc -l)" -eq 1 ]; then + /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) if [ -z "$status_code" ]; then status_code="ERROR" fi - datetime=$(date +"%Y-%m-%d %H:%M:%S") - pidcount=$(pgrep "ubusd" | wc -l) - pidcount2=$(pgrep "rpcd" | wc -l) - - if [ "$pidcount" -gt 1 ]; then - killall ubusd - killall rpcd - sleep 1 - /sbin/rpcd -s /var/run/ubus/ubus.sock -t 30 & - fi - - if [ "$pidcount2" -gt 1 ] && [ "$pidcount" -eq 1 ]; then - killall rpcd - fi - - if [ "$(pgrep ubusd | wc -l)" -eq 0 ]; then - /sbin/ubusd & - killall rpcd - sleep 1 - /sbin/rpcd -s /var/run/ubus/ubus.sock -t 30 & - fi - - if [ "$(pgrep rpcd | wc -l)" -eq 0 ] && [ "$pidcount" -eq 1 ]; then - echo "$datetime / Ubus服务异常,正在重启Ubus。" - sleep 1 - /sbin/rpcd -s /var/run/ubus/ubus.sock -t 30 & - elif [[ "$status_code" == 500 || "$status_code" == 502 ]] && echo "$dbus_status" | grep -q "running"; then + if [[ "$status_code" == 500 || "$status_code" == 502 ]] && echo "$dbus_status" | grep -q "running"; then echo "$datetime / Ubus服务异常,正在重启Ubus。" killall rpcd sleep 1