Created
November 19, 2014 05:39
-
-
Save thwarted/b156b2f47710ee8e61e8 to your computer and use it in GitHub Desktop.
portserve - simple script used to test haproxy healthcheck settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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