blob: f1f6b63d8ec366b7e5ef712f885c12ed19ab05e4 (
plain) (
blame)
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
|
#!/bin/ash
ERRLOG="/run/dnbd3-proxy.err"
if [ -s "$ERRLOG" ]; then
exec "$(which dnbd3-server)" -n --errormsg "$(cat "$ERRLOG")" -c /etc/dnbd3-server
fi
if [ -d "/mnt/dnbd3" ]; then
set -- -m /mnt/dnbd3
else
set --
fi
# Force immediate switch to localhost for stage4 if applicable
if [ -d "/mnt/dnbd3" ] && [ -b /dev/dnbd0 ] \
&& [ "$( cat /sys/block/dnbd0/net/rid )" -gt 0 ]; then
(
DNBD3_PORT=5003
# give it some time to start
usleep 250000
if ! grep -q -F 127.0.0.1 /sys/block/dnbd0/net/alt_servers; then
# add the server
if ! dnbd3-client -A "127.0.0.1:$DNBD3_PORT" -d /dev/dnbd0; then
echo "WARN: Cannot add localhost to dnbd0" >&2
fi
fi
for i in 1 2 3 4 5 6 7; do
echo | busybox timeout 1 busybox nc 127.0.0.1 "$DNBD3_PORT" && break
echo "WARN: port wait fail #$i"
usleep ${i}00000 # tenths of a second
done
if ! dnbd3-client -s "127.0.0.1:$DNBD3_PORT" -d /dev/dnbd0; then
echo "ERROR: Cannot switch dnbd0 to localhost" >&2
fi
) &
fi
exec "$(which dnbd3-server)" -n -c /etc/dnbd3-server "$@"
exit 1
|