update ubus-status.sh

This commit is contained in:
桐话
2024-06-21 13:13:12 +08:00
committed by GitHub
parent 28d1b9bf04
commit 66ec46b0eb
+21 -27
View File
@@ -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