diff --git a/target/d211/demo128_nand/rootfs_overlay/etc/inittab b/target/d211/demo128_nand/rootfs_overlay/etc/inittab new file mode 100644 index 000000000..fff050600 --- /dev/null +++ b/target/d211/demo128_nand/rootfs_overlay/etc/inittab @@ -0,0 +1,42 @@ +# /etc/inittab +# +# Copyright (C) 2001 Erik Andersen +# +# Note: BusyBox init doesn't support runlevels. The runlevels field is +# completely ignored by BusyBox init. If you want runlevels, use +# sysvinit. +# +# Format for each entry: ::: +# +# id == tty to run on, or empty for /dev/console +# runlevels == ignored +# action == one of sysinit, respawn, askfirst, wait, and once +# process == program to run + +# Startup the system +::sysinit:/bin/mount -t proc proc /proc +::sysinit:/bin/mount -o remount,rw / +::sysinit:/bin/mkdir -p /dev/pts /dev/shm +::sysinit:/bin/mount -a +::sysinit:/sbin/swapon -a +null::sysinit:/bin/ln -sf /proc/self/fd /dev/fd +null::sysinit:/bin/ln -sf /proc/self/fd/0 /dev/stdin +null::sysinit:/bin/ln -sf /proc/self/fd/1 /dev/stdout +null::sysinit:/bin/ln -sf /proc/self/fd/2 /dev/stderr +::sysinit:/bin/hostname -F /etc/hostname +# now run any rc scripts +::sysinit:/etc/init.d/rcS + +# e_player monitor and auto-restart +::respawn:/usr/bin/e_player_wrapper + +::sysinit:/bin/cat /etc/issue # Put a getty on the serial port +console::respawn:-/bin/sh # GENERIC_SERIAL + +# Stuff to do for the 3-finger salute +#::ctrlaltdel:/sbin/reboot + +# Stuff to do before rebooting +::shutdown:/etc/init.d/rcK +::shutdown:/sbin/swapoff -a +::shutdown:/bin/umount -a -r diff --git a/target/d211/demo128_nand/rootfs_overlay/usr/bin/e_player_wrapper b/target/d211/demo128_nand/rootfs_overlay/usr/bin/e_player_wrapper new file mode 100755 index 000000000..a4361209a --- /dev/null +++ b/target/d211/demo128_nand/rootfs_overlay/usr/bin/e_player_wrapper @@ -0,0 +1,106 @@ +#!/bin/sh +# e_player 崩溃监控和恢复脚本 + +CRASH_COUNT_FILE="/data/.e_player_crash_count" +STABLE_COUNT_FILE="/data/.e_player_stable_count" +MAX_CRASH=5 +CHECK_INTERVAL=1 +STABLE_CHECKS=120 # 连续检测120s 进程存在才认为稳定 + +if [ ! -f "$CRASH_COUNT_FILE" ]; then + echo 0 > "$CRASH_COUNT_FILE" +fi +if [ ! -f "$STABLE_COUNT_FILE" ]; then + echo 0 > "$STABLE_COUNT_FILE" +fi + +echo "$(date): e_player_wrapper starting, waiting for e_player..." >> /data/crash.log +WAIT_COUNT=0 +while [ $WAIT_COUNT -lt 20 ]; do + if ps | grep -v grep | grep -v e_player_wrapper | grep e_player > /dev/null; then + echo "$(date): e_player detected after ${WAIT_COUNT} checks, starting monitoring..." >> /data/crash.log + break + fi + sleep 3 + WAIT_COUNT=$((WAIT_COUNT + 1)) +done + +if ! ps | grep -v grep | grep -v e_player_wrapper | grep e_player > /dev/null; then + echo "$(date): WARNING - e_player not found after 60s, will monitor anyway..." >> /data/crash.log +fi + +echo "$(date): Starting main monitoring loop..." >> /data/crash.log + +HEARTBEAT=0 +while true; do + HEARTBEAT=$((HEARTBEAT + 1)) + if [ $HEARTBEAT -ge 120 ]; then + echo "$(date): [Heartbeat] Monitoring active, stable_count=$(cat $STABLE_COUNT_FILE)" >> /data/crash.log + HEARTBEAT=0 + fi + + if ! ps | grep -v grep | grep -v e_player_wrapper | grep e_player > /dev/null; then + # 进程不存在,崩溃了 + echo 0 > "$STABLE_COUNT_FILE" # 重置稳定计数 + + COUNT=$(cat "$CRASH_COUNT_FILE") + COUNT=$((COUNT + 1)) + echo $COUNT > "$CRASH_COUNT_FILE" + + echo "$(date): e_player crashed, count: $COUNT" >> /data/crash.log + + if [ $COUNT -ge $MAX_CRASH ]; then + echo "$(date): Crash count exceeded $MAX_CRASH, restoring from factory..." >> /data/crash.log + + # 从factory恢复bin文件 + if [ -f /system/factory/bin/e_player ]; then + cp /system/factory/bin/e_player /data/bin/e_player + chmod +x /data/bin/e_player + echo "$(date): Restored e_player from factory" >> /data/crash.log + fi + + if [ -f /system/factory/bin/lbh_client ]; then + cp /system/factory/bin/lbh_client /data/bin/lbh_client + chmod +x /data/bin/lbh_client + echo "$(date): Restored lbh_client from factory" >> /data/crash.log + fi + + # 恢复配置文件 + if [ -f /system/factory/system_properties.cfg ]; then + cp /system/factory/system_properties.cfg /data/system_properties.cfg + echo "$(date): Restored system_properties.cfg from factory" >> /data/crash.log + fi + + # 重置崩溃计数,重新开始 + echo 0 > "$CRASH_COUNT_FILE" + echo "$(date): Reset crash count, retrying..." >> /data/crash.log + fi + + echo "$(date): Restarting e_player..." >> /data/crash.log + killall -9 e_player 2>/dev/null + sleep 1 + + export LD_LIBRARY_PATH=/data/bin/libs:/vendor/qua/lib:/lib:/usr/lib:$LD_LIBRARY_PATH + cd /data + /data/bin/e_player & + sleep 3 + else + # 进程存在,累加稳定计数 + STABLE=$(cat "$STABLE_COUNT_FILE") + STABLE=$((STABLE + 1)) + echo $STABLE > "$STABLE_COUNT_FILE" + + # 如果稳定运行120秒,重置崩溃计数 + if [ $STABLE -ge $STABLE_CHECKS ]; then + COUNT=$(cat "$CRASH_COUNT_FILE") + if [ $COUNT -gt 0 ]; then + echo "$(date): e_player stable, resetting crash count" >> /data/crash.log + echo 0 > "$CRASH_COUNT_FILE" + fi + echo 0 > "$STABLE_COUNT_FILE" # 重置稳定计数,下次再累计 + fi + fi + + sleep $CHECK_INTERVAL +done +