Configure AAI HA Proxy to distribute the load to multiple AAI service replicas. Added...
[aai/aai-common.git] / aai-common-docker / aai-haproxy-image / src / main / docker / docker-entrypoint.sh
1 #!/bin/sh
2 set -e
3
4 # first arg is `-f` or `--some-option`
5 if [ "${1#-}" != "$1" ]; then
6     set -- haproxy "$@"
7 fi
8
9 NAMESERVER_IP=$(cat /etc/resolv.conf  | grep 'nameserver' | head -1 | awk '{ print $2; }');
10
11 sed -i 's/${ONAP_NAMESERVER_CLUSTER_IP}/'${NAMESERVER_IP}'/g' /usr/local/etc/haproxy/resolvers.conf || {
12     echo "Unable to overwrite the nameserver in the haproxy configuration file";
13     exit 1;
14 }
15
16 if [ "$1" = 'haproxy' ]; then
17         shift # "haproxy"
18         # if the user wants "haproxy", let's add a couple useful flags
19         #   -W  -- "master-worker mode" (similar to the old "haproxy-systemd-wrapper"; allows for reload via "SIGUSR2")
20         #   -db -- disables background mode
21         set -- haproxy -W -db "$@"
22 fi
23
24 exec "$@"