Skip to content

Instantly share code, notes, and snippets.

@thwarted
Created November 19, 2014 05:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thwarted/b156b2f47710ee8e61e8 to your computer and use it in GitHub Desktop.
Save thwarted/b156b2f47710ee8e61e8 to your computer and use it in GitHub Desktop.
portserve - simple script used to test haproxy healthcheck settings
#!/bin/bash
if [[ "$2" ]]; then
msg="serving port $1"
size=$( echo "$msg" | wc -c )
read request
while /bin/true; do
read x
if [[ "$x" == "" ]]; then
break
fi
done
case "$request" in
*/check* )
if [[ -e "/tmp/down-$1" ]]; then
echo 'HTTP/1.0 500 Server Error'
echo 'Content-type: text/plain'
echo
echo "DOWN"
else
echo 'HTTP/1.0 200 OK'
echo 'Content-type: text/plain'
echo
echo "UP"
fi
;;
* )
echo 'HTTP/1.0 200 OK'
echo 'Content-type: text/plain'
echo 'Content-length: '"$size"
echo 'Connection: close'
echo
echo "$msg"
;;
esac
elif [[ "$1" ]]; then
socat -T 1 -d -d tcp-l:$1,reuseaddr,fork,crlf exec:"$0 $1 http"
else
for port in 9001 9002 9003 9004; do
"$0" "$port" &
done
read
killall socat
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment