GoHome/haproxy/reconfigure-haproxy.sh

39 lines
1.1 KiB
Bash
Raw Normal View History

2022-07-28 22:02:37 +02:00
#!/bin/bash
# Variables
# Funcitons
2022-07-28 23:00:31 +02:00
## Load config from file
2022-07-28 22:02:37 +02:00
function loadconfig {
source config/public
source config/private
}
2022-07-28 23:00:31 +02:00
## 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
}
2022-07-28 22:02:37 +02:00
# Main Script
loadconfig
2022-07-28 23:00:31 +02:00
hostconfig
copytemplates
b2templating