Unverified Commit e0cb140c authored by Kroese's avatar Kroese Committed by GitHub
Browse files

Keep previous instances

parent 8fb8054f
Loading
Loading
Loading
Loading
+3 −12
Original line number Diff line number Diff line
@@ -2,16 +2,6 @@
set -eu
trap exit SIGINT SIGTERM

# Close any previous instances
script_name="${BASH_SOURCE[0]}"

for pid in $(pidof -x "$script_name"); do
  if [ "$pid" != $$ ]; then
    kill -15 "$pid" 2> /dev/null
    wait "$pid" 2> /dev/null
  fi
done

# Serve the page
HTML="<HTML><HEAD><STYLE>body {  color: white; background-color: #00BFFF; }</STYLE>\
              </HEAD><BODY><BR><BR><H1><CENTER>$2</CENTER></H1></BODY></HTML>"
@@ -20,5 +10,6 @@ LENGTH="${#HTML}"

RESPONSE="HTTP/1.1 200 OK\nContent-Length: ${LENGTH}\nConnection: close\n\n$HTML\n\n"

echo -en "$RESPONSE" | nc -k -N -lp 80 &
echo -en "$RESPONSE" | nc -k -N -lp "${1:-5000}"
while true; do
  echo -en "$RESPONSE" | nc -N -q 1 -lp "${1:-5000}";
done