virtual-dsm/run/server.sh
2023-04-20 15:26:22 +02:00

25 lines
521 B
Bash

#!/usr/bin/env bash
set -eu
# 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
trap exit SIGINT SIGTERM
# Serve the page
HTML="<HTML><BODY><H1><CENTER>$2</CENTER></H1></BODY></HTML>"
RESPONSE="HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n$HTML\r\n"
while { echo -en "$RESPONSE"; } | nc -lN "${1:-8080}"; do
echo "================================================"
done