library/haproxy/1.8-alpine/bin/generate_http_sites_list.sh

36 lines
801 B
Bash
Raw Permalink Normal View History

2018-10-27 03:58:37 +00:00
#!/bin/sh
set -e
#domainname backendname
#one.example.com site:one.example.com
#two.example.com site:two.example.com
#etc.domain1.com site:etc.example.com
generate_http_sites_list() {
local HTTP_SITES_MAP_PATH=/etc/haproxy/sites/http-sites.map
local SITES_DIR_PATH=/etc/haproxy/sites
local SITE_NAME=""
local HTTP_SITES_MAP=""
mkdir -p $SITES_DIR_PATH
if [[ ! -f ${HTTP_SITES_MAP_PATH} ]]; then
touch $HTTP_SITES_MAP_PATH
fi
cd $SITES_DIR_PATH
for SITE_FILE_NAME in http-*.cfg; do
if [[ ! -f $SITE_FILE_NAME ]]; then
continue
fi
SITE_NAME=${SITE_FILE_NAME/http-/}
SITE_NAME=${SITE_NAME/.cfg/}
HTTP_SITES_MAP=$HTTP_SITES_MAP"$SITE_NAME site-http:$SITE_NAME\n"
done
echo -e "$HTTP_SITES_MAP" > $HTTP_SITES_MAP_PATH
}
generate_http_sites_list