#!/bin/bash -xu

config_file=/var/lib/haproxy/conf/haproxy.config
pid_file=/var/lib/haproxy/run/haproxy.pid
old_pid=""
path_map_file=/var/lib/haproxy/conf/os_http_be.map

# sort the path based map file for the haproxy map_beg function
sort -r $path_map_file -o $path_map_file

if [ -f $pid_file ]; then
  old_pid=$(<$pid_file)
fi

if [ -n "$old_pid" ]; then
  /usr/sbin/haproxy -f $config_file -p $pid_file -sf $old_pid
else
  /usr/sbin/haproxy -f $config_file -p $pid_file
fi
