-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·239 lines (217 loc) · 5.22 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·239 lines (217 loc) · 5.22 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/sh
# Launch raptor daemons from NFS — run directly on device
# Usage: /mnt/nfs/projects/thingino/raptor/run.sh [-n] [config]
# -n Normal mode (daemonize). Without -n, runs with -f -d (foreground+debug).
#
# If no config given, uses /etc/raptor.conf or generates a minimal one.
DIR="$(cd "$(dirname "$0")" && pwd)"
DEBUG_FLAGS="-f -d"
DEBUG_LOG=1
if [ "$1" = "-n" ]; then
DEBUG_FLAGS=""
DEBUG_LOG=0
shift
fi
CONF="${1:-/etc/raptor.conf}"
log() { echo "[raptor] $*"; }
if [ ! -f "$CONF" ]; then
CONF="/tmp/raptor.conf"
cat > "$CONF" << 'EOF'
[sensor]
[stream0]
fps = 25
codec = h264
profile = 2
bitrate = 2000000
rc_mode = vbr
gop = 50
[stream1]
enabled = true
width = 640
height = 360
fps = 25
codec = h264
profile = 0
bitrate = 500000
rc_mode = cbr
gop = 50
[ring]
main_slots = 32
main_data_mb = 0
sub_slots = 32
sub_data_mb = 0
[audio]
enabled = true
sample_rate = 16000
codec = opus
volume = 80
gain = 25
[rtsp]
enabled = true
port = 554
[http]
enabled = true
port = 8080
[osd]
enabled = true
font = /usr/share/fonts/default.ttf
font_size = 24
font_color = 0xFFFFFFFF
font_stroke = 1
time_enabled = true
time_format = %Y-%m-%d %H:%M:%S
uptime_enabled = true
text_enabled = true
text_string = Camera
stream0_time_pos = top_left
stream0_uptime_pos = top_right
stream0_text_pos = top_center
stream1_time_pos = top_left
stream1_uptime_pos = top_right
stream1_text_pos = top_center
[recording]
enabled = false
mode = both
stream = 0
audio = true
segment_minutes = 1
storage_path = /mnt/mmcblk0p1/raptor
max_storage_mb = 500
prebuffer_sec = 5
clip_length_sec = 60
clip_max_mb = 200
[webrtc]
enabled = true
udp_port = 8443
http_port = 8554
max_clients = 2
cert = /etc/ssl/certs/uhttpd.crt
key = /etc/ssl/private/uhttpd.key
[webtorrent]
enabled = false
[motion]
enabled = false
algorithm = move
sensitivity = 3
grid = 4x4
cooldown_sec = 10
poll_interval_ms = 500
record = true
record_post_sec = 30
[ircut]
enabled = false
[log]
level = info
target = syslog
EOF
log "generated default config: $CONF"
fi
# Kill any running daemons and wait for them to exit
log "stopping running daemons..."
for d in rvd rad rod rsd rhd rmr rmd ric rwd rsp; do
pid=$(pidof $d 2>/dev/null)
if [ -n "$pid" ]; then
log " killing $d (pid $pid)"
kill $pid 2>/dev/null
fi
done
# Wait for all to exit (HAL teardown can take several seconds)
for i in 1 2 3 4 5 6 7 8 9 10; do
alive=0
for d in rvd rad rod rsd rhd rmr rmd ric rwd rsp; do
pidof $d >/dev/null 2>&1 && alive=1 && break
done
[ "$alive" = 0 ] && break
sleep 1
done
# Force-kill anything still alive
for d in rvd rad rod rsd rhd rmr rmd ric rwd rsp; do
pid=$(pidof $d 2>/dev/null)
[ -n "$pid" ] && kill -9 $pid 2>/dev/null && log " force-killed $d"
done
# Clean stale SHM
rm -f /dev/shm/rss_ring_* /dev/shm/rss_osd_* 2>/dev/null
log "config: $CONF"
log "binaries: $DIR"
echo ""
FAILED=""
SKIPPED=""
launch() {
local name="$1"; shift
log "starting $name..."
if [ "$DEBUG_LOG" = 1 ]; then
"$@" >> /tmp/${name}.log 2>&1 &
else
"$@" &
fi
eval "PID_${name}=$!"
}
check() {
local name="$1"
local pid
# Already categorized from a prior check
echo "$SKIPPED $FAILED" | grep -qw "$name" && return 0
eval "pid=\$PID_${name}"
[ -z "$pid" ] && return 0
if kill -0 "$pid" 2>/dev/null; then
return 0
fi
# Process exited — check why
wait "$pid" 2>/dev/null
local rc=$?
if [ "$rc" = 0 ]; then
SKIPPED="$SKIPPED $name"
else
log "ERROR: $name crashed (exit $rc):"
tail -5 /tmp/${name}.log 2>/dev/null | sed 's/^/ /'
FAILED="$FAILED $name"
return 1
fi
return 0
}
# RVD must start first (creates rings, encoder, ISP)
launch rvd $DIR/rvd/rvd -c "$CONF" $DEBUG_FLAGS
sleep 4
check rvd || { log "rvd is required — aborting"; exit 1; }
# Audio producer
launch rad $DIR/rad/rad -c "$CONF" $DEBUG_FLAGS
sleep 2
check rad
# OSD renderer
launch rod $DIR/rod/rod -c "$CONF" $DEBUG_FLAGS
# Stream consumers
launch rsd $DIR/rsd/rsd -c "$CONF" $DEBUG_FLAGS
launch rhd $DIR/rhd/rhd -c "$CONF" $DEBUG_FLAGS
launch rmr $DIR/rmr/rmr -c "$CONF" $DEBUG_FLAGS
launch rwd $DIR/rwd/rwd -c "$CONF" $DEBUG_FLAGS
launch rsp $DIR/rsp/rsp -c "$CONF" $DEBUG_FLAGS
sleep 1
for d in rod rsd rhd rmr rwd rsp; do check $d; done
# Aux daemons
launch ric $DIR/ric/ric -c "$CONF" $DEBUG_FLAGS
launch rmd $DIR/rmd/rmd -c "$CONF" $DEBUG_FLAGS
sleep 2
for d in ric rmd; do check $d; done
# Final settle — catch delayed crashes
sleep 2
log "verifying all daemons survived..."
for d in rvd rad rod rsd rhd rmr rwd rsp ric rmd; do check $d; done
echo ""
for d in rvd rad rod rsd rhd rmr rwd rsp ric rmd; do
pid=$(pidof $d 2>/dev/null)
if [ -n "$pid" ]; then
printf " %-6s pid %-6s OK\n" "$d" "$pid"
elif echo "$SKIPPED" | grep -qw "$d"; then
printf " %-6s %13s SKIPPED\n" "$d" ""
elif echo "$FAILED" | grep -qw "$d"; then
printf " %-6s %13s CRASHED\n" "$d" ""
fi
done
echo ""
[ -n "$SKIPPED" ] && log "skipped (disabled in config):$SKIPPED"
if [ -n "$FAILED" ]; then
log "FAILED:$FAILED"
[ "$DEBUG_LOG" = 1 ] && log "check logs: /tmp/{daemon}.log"
exit 1
fi
[ "$DEBUG_LOG" = 1 ] && log "logs: /tmp/{rvd,rad,rod,rsd,rhd,rmr,rwd,rsp,ric,rmd}.log"