GoHome/haproxy/reconfigure-haproxy.sh
2022-07-28 23:00:31 +02:00

39 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Variables
# Funcitons
## Load config from file
function loadconfig {
source config/public
source config/private
}
## Load variables from host
function hostconfig {
H_LOCAL_IP=$(hostname -i | cut -d ' ' -f 1)
}
function copytemplates {
cp ./haproxy/config/haproxy.cfg.b2 ./haproxy/config/haproxy.cfg
cp ./haproxy/haproxy-compose.yaml.b2 ./haproxy/haproxy-compose.yaml
}
## Bajia Tempalting (Bash & Jinja)
function b2templating {
### HAPROXY config
sed -i "s/H_LOCAL_IP/$H_LOCAL_IP/g" ./haproxy/config/haproxy.cfg
sed -i "s/FRONTEND_PORT/$FRONTEND_PORT/g" ./haproxy/config/haproxy.cfg
sed -i "s/BACKEND_PORT/$BACKEND_PORT/g" ./haproxy/config/haproxy.cfg
sed -i "s/HAPROXY_STATS_PORT/$HAPROXY_STATS_PORT/g" ./haproxy/config/haproxy.cfg
sed -i "s/HAPROXY_PORT/$HAPROXY_PORT/g" ./haproxy/config/haproxy.cfg
### Docker Compose
sed -i "s/HAPROXY_PORT/$HAPROXY_PORT/g" ./haproxy/haproxy-compose.yaml
sed -i "s/HAPROXY_STATS_PORT/$HAPROXY_STATS_PORT/g" ./haproxy/haproxy-compose.yaml
}
# Main Script
loadconfig
hostconfig
copytemplates
b2templating