-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice.sh
More file actions
executable file
·64 lines (45 loc) · 1.16 KB
/
Copy pathservice.sh
File metadata and controls
executable file
·64 lines (45 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/system/bin/sh
MODDIR=${0%/*}
DAEMON="$MODDIR/daemon.sh"
SOCAT="$MODDIR/bin/socat"
PROP="$MODDIR/module.prop"
USER_SOCK="/data/local/host.user.sock"
ROOT_SOCK="/data/local/host.root.sock"
LOG="/data/local/hostsocket_watchdog.log"
log() {
echo "[$(date)] $*" >> "$LOG"
}
update_status() {
status="$1"
# rewrite only description line
sed -i "s/^description=.*/description=Unix socket shell bridge (root + non-root) \n$status/" "$PROP"
}
check_health() {
[ -S "$USER_SOCK" ] && [ -S "$ROOT_SOCK" ]
}
#check_health() {
# echo "echo OK" | $SOCAT - UNIX-CONNECT:$USER_SOCK >/dev/null 2>&1
#}
# wait for boot
until [ "$(getprop sys.boot_completed)" = "1" ]; do
sleep 2
done
chmod +x "$SOCAT" "$DAEMON"
log "Watchdog starting..."
while true; do
log "Starting daemon..."
"$DAEMON" &
DAEMON_PID=$!
sleep 2
while kill -0 "$DAEMON_PID" 2>/dev/null; do
if check_health; then
update_status "HostSocket: ✅ Running"
else
update_status "HostSocket: ⚠️ Degraded"
fi
sleep 5
done
log "Daemon died!"
update_status "HostSocket: ❌ Restarting..."
sleep 2
done