feat: 新增功能允许用户自定义 inotifyd 要监测的事件(默认是 c),允许通过配置文件和 webui 修改

This commit is contained in:
YuleBest committed 2026-04-06 04:30:45 +08:00
1 parent 8431079246
commit b1d2a444c8
8 files changed
+81 -28

No files matched your search

+11 -7
View File
@@ -1,5 +1,6 @@
#!/system/bin/sh
# LuminPro 守护进程 (Watchdog)
#shellcheck shell=ash
# LuminPro 守护进程
# 使用 readlink 获取脚本真实绝对路径
REAL_PATH="$(readlink -f "$0")"
@@ -31,14 +32,16 @@ get_config() {
# 获取当前配置的哈希值(用于检测配置变化)
get_config_hash() {
local now_file="$(get_config "$PATH_CONFIG_DIR/now_bri_file.txt" "$DEFAULT_NOW_BRI_FILE")"
echo "$now_file"
local now_file events
now_file="$(get_config "$PATH_CONFIG_DIR/now_bri_file.txt" "$DEFAULT_NOW_BRI_FILE")"
events="$(get_config "$CONFIG_DIR/inotify_events.txt" "c")"
echo "${now_file}|${events}"
}
# 日志函数
_log() {
local level="${2:-INFO}"
printf '[%s] [%-8s] [%-8s] %s\n' "$(date '+%m-%d %H:%M:%S')" "daemon" "$level" "$1" >>"$log_file"
printf '[%s] [%s] [%s] %s\n' "$(date '+%m-%d %H:%M:%S')" "daemon" "$level" "$1" >>"$log_file"
}
# 确保环境就绪
@@ -86,18 +89,19 @@ while true; do
# 正常启动并监听
_log "→ 启动 inotifyd 监听..." "INFO"
now_bri_file="$current_config"
now_bri_file="${current_config%|*}"
inotify_events="${current_config#*|}"
# 更新缓存,让 up.sh 知道当前监听的是哪个文件
echo -n "$now_bri_file" >"$PATH_CONFIG_DIR/.cached_path"
# 启动并重定向 (不再使用子进程管道以保证 PID 抓取准确)
inotifyd "$MODDIR/script/up.sh" "$now_bri_file:c" >>"$log_file" 2>&1 &
inotifyd "$MODDIR/script/up.sh" "$now_bri_file:$inotify_events" >>"$log_file" 2>&1 &
inotify_pid=$!
echo "$inotify_pid" >"$pid_file"
_log "✓ inotifyd 已启动 (PID: $inotify_pid)" "SUCCESS"
_log " 监听文件: $now_bri_file" "INFO"
_log " 监听文件: $now_bri_file, 事件: $inotify_events" "INFO"
# 3. 通过 wait 阻塞,实时感知进程死亡 (兼容所有 BusyBox 环境)
wait "$inotify_pid"
+1 -1
View File
@@ -8,7 +8,7 @@ flag_file="$PID_DIR/up.flag"
log_file="$MODDIR/service.log"
_log() {
printf '[%s] [service.restart] %s\n' "$(date '+%d %H:%M:%S.%3N')" "$1" >>"$log_file"
printf '[%s] [restart] %s\n' "$(date '+%d %H:%M:%S.%3N')" "$1" >>"$log_file"
}
_log "正在手动重启服务..."
+5 -6
View File
@@ -13,7 +13,6 @@ pause_file="$PID_DIR/daemon.pause"
# 默认设备路径
DEFAULT_NOW_BRI_FILE="/sys/class/backlight/panel0-backlight/brightness"
DEFAULT_MAX_BRI_FILE="/sys/class/backlight/panel0-backlight/max_brightness"
# 读取配置函数
get_config() {
@@ -28,7 +27,6 @@ get_config() {
# 获取亮度文件路径
now_bri_file="$(get_config "$PATH_CONFIG_DIR/now_bri_file.txt" "$DEFAULT_NOW_BRI_FILE")"
max_bri_file="$(get_config "$PATH_CONFIG_DIR/max_bri_file.txt" "$DEFAULT_MAX_BRI_FILE")"
# 日志函数
_log() {
@@ -48,11 +46,11 @@ _log() {
local cur_size
cur_size=$(du -k "$log_file" | cut -f1)
if [ "$cur_size" -ge "$max_size" ]; then
printf '[%s] [%-8s] [%-8s] %s\n' "$(date '+%m-%d %H:%M:%S')" "up" "WARN" "日志过大 ($cur_size KB), 自动重置" >"$log_file"
printf '[%s] [%s] [%s] %s\n' "$(date '+%m-%d %H:%M:%S')" "up" "WARN" "日志过大 ($cur_size KB), 自动重置" >"$log_file"
fi
fi
printf '[%s] [%-8s] [%-8s] %s\n' "$(date '+%m-%d %H:%M:%S')" "up" "$level" "$1" >>"$log_file"
printf '[%s] [%s] [%s] %s\n' "$(date '+%m-%d %H:%M:%S')" "up" "$level" "$1" >>"$log_file"
}
_log "[*] 收到 inotifyd 通知 (PID: $$)" "INFO"
@@ -187,8 +185,9 @@ MAIN() {
rm -f "$pause_file" # 解锁守护进程,让它自动拉起 inotifyd
# 如果配置文件被修改了,杀掉 inotifyd 让 daemon 重启并重新读取配置
local current_now_bri="$(cat "$PATH_CONFIG_DIR/now_bri_file.txt" 2>/dev/null || echo "$DEFAULT_NOW_BRI_FILE")"
local cached_now_bri="$(cat "$PATH_CONFIG_DIR/.cached_path" 2>/dev/null || echo "$DEFAULT_NOW_BRI_FILE")"
local current_now_bri cached_now_bri
current_now_bri="$(cat "$PATH_CONFIG_DIR/now_bri_file.txt" 2>/dev/null || echo "$DEFAULT_NOW_BRI_FILE")"
cached_now_bri="$(cat "$PATH_CONFIG_DIR/.cached_path" 2>/dev/null || echo "$DEFAULT_NOW_BRI_FILE")"
if [ "$current_now_bri" != "$cached_now_bri" ]; then
_log "[*] 配置已更新,重启 inotifyd..." "WARN"