update ubus-status.sh

This commit is contained in:
桐话
2024-07-01 23:38:12 +08:00
committed by GitHub
parent 2739789675
commit 719bdfb00b
+15 -24
View File
@@ -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
}