update ubus-status.sh

This commit is contained in:
桐话
2024-06-15 13:22:24 +08:00
committed by GitHub
parent 2b4c70ed59
commit 9bfae74fa8
+16 -2
View File
@@ -2,18 +2,32 @@
while true
do
dbus_status=$(/etc/init.d/dbus status | grep -o "running")
dbus_status=$(/etc/init.d/dbus status)
status_code=$(curl -o /dev/null -s -w "%{http_code}\n" http://127.0.0.1/cgi-bin/luci/ 2>/dev/null)
page_content=$(curl -s http://127.0.0.1/cgi-bin/luci/ 2>/dev/null)
datetime=$(date +"%Y-%m-%d %H:%M:%S")
pidv=$(pgrep "ubusd" | head -n 1)
pidv2=$(pgrep "rpcd" | head -n 1)
if [ -z "$status_code" ]; then
status_code="ERROR"
fi
if [ -z "$page_content" ]; then
page_content="ERROR"
fi
if [ -z "$pidv" ]; then
echo "$datetime / Ubus服务异常,正在重启Ubus。"
/sbin/ubusd &
elif [ -z "$pidv2" ]; then
echo "$datetime / Ubus服务异常,正在重启Ubus。"
/sbin/rpcd -s /var/run/ubus/ubus.sock -t 30 &
elif [ -n "$dbus_status" ]; then
elif ((echo "$page_content" | grep -q "dispatcher.lua:430" || echo "$page_content" | grep -q "dispatcher.lua:") && echo "$dbus_status" | grep -q "running") || ([[ "$status_code" == 500 || "$status_code" == 502 ]] && echo "$dbus_status" | grep -q "running"); then
echo "$datetime / Ubus服务异常,正在重启Ubus。"
killall rpcd
/etc/init.d/rpcd restart
elif echo "$dbus_status" | grep -q "running"; then
echo "$datetime / Ubus服务正在运行,一切正常。"
else
echo "$datetime / Ubus服务异常,正在重启Ubus。"