mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-02-24 13:30:02 +08:00
Trap handler
This commit is contained in:
parent
d6d955f3b1
commit
398b68fd5b
@ -1,13 +1,17 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
trap 'pkill -f nc || true' EXIT
|
stop() {
|
||||||
trap exit SIGINT SIGTERM
|
trap - SIGINT EXIT
|
||||||
|
{ pkill -f nc || true } 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
trap 'stop' EXIT SIGINT SIGTERM SIGHUP
|
||||||
|
|
||||||
if [[ "$2" == "/"* ]]; then
|
if [[ "$2" == "/"* ]]; then
|
||||||
|
|
||||||
while true ; do
|
while true ; do
|
||||||
nc -lp "${1:-5000}" -e "$2" >/dev/null 2>&1 & wait $!
|
nc -lp "${1:-5000}" -e "$2" & wait $!
|
||||||
done
|
done
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -19,7 +23,7 @@ else
|
|||||||
RESPONSE="HTTP/1.1 200 OK\nContent-Length: ${LENGTH}\nConnection: close\n\n$HTML\n\n"
|
RESPONSE="HTTP/1.1 200 OK\nContent-Length: ${LENGTH}\nConnection: close\n\n$HTML\n\n"
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
echo -en "$RESPONSE" | nc -lp "${1:-5000}" >/dev/null 2>&1 & wait $!
|
echo -en "$RESPONSE" | nc -lp "${1:-5000}" & wait $!
|
||||||
done
|
done
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user