var refinement
This commit is contained in:
parent
b2c0eef337
commit
34a6e33cab
1 changed files with 28 additions and 15 deletions
|
|
@ -1,30 +1,40 @@
|
|||
#!/bin/bash
|
||||
# Move to the folder where this script lives
|
||||
cd "$(dirname "$0")"
|
||||
cd /docker/keepalived
|
||||
|
||||
# Load the variables Komodo just wrote
|
||||
# 1. SOURCING
|
||||
# Force export of all variables in .env so sed can access them
|
||||
if [ -f .env ]; then
|
||||
export $(grep -v '^#' .env | xargs)
|
||||
echo "Sourcing variables from .env..."
|
||||
set -a
|
||||
source .env
|
||||
set +a
|
||||
else
|
||||
echo "ERROR: .env file not found in $(pwd)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Define paths relative to the current folder
|
||||
CONFIG_DIR="/docker/keepalived/config"
|
||||
CHECKS_DIR="/docker/keepalived/checks"
|
||||
HEADER_TPL="/docker/keepalived/keepalived_header.tpl"
|
||||
SLOT_TPL="/docker/keepalived/keepalived_slot.tpl"
|
||||
# 2. QUOTE CLEANING
|
||||
# Remove literal double quotes from the start/end of the string if they exist
|
||||
SLOT_DEFINITIONS=$(echo "$SLOT_DEFINITIONS" | sed 's/^"//;s/"$//')
|
||||
|
||||
# 3. PATHS
|
||||
CONFIG_DIR="./config"
|
||||
CHECKS_DIR="./checks"
|
||||
HEADER_TPL="./keepalived_header.tpl"
|
||||
SLOT_TPL="./keepalived_slot.tpl"
|
||||
CONFIG_FILE="${CONFIG_DIR}/keepalived.conf"
|
||||
|
||||
mkdir -p "$CONFIG_DIR" "$CHECKS_DIR"
|
||||
|
||||
# Build Header
|
||||
# 4. BUILD HEADER
|
||||
if [ -z "$LXC_NUM" ]; then echo "ERROR: LXC_NUM not found in env"; exit 1; fi
|
||||
|
||||
cp "$HEADER_TPL" "$CONFIG_FILE"
|
||||
sed -i "s/{{LXC_NUM}}/${LXC_NUM}/g" "$CONFIG_FILE"
|
||||
|
||||
# Parse Slots
|
||||
while IFS=',' read -r s_num s_name s_dep s_state s_prio s_peer s_vip junk
|
||||
# 5. PARSE SLOTS
|
||||
# Using echo | while to ensure the cleaned string is parsed line-by-line
|
||||
echo "$SLOT_DEFINITIONS" | while IFS=',' read -r s_num s_name s_dep s_state s_prio s_peer s_vip junk
|
||||
do
|
||||
[[ -z "$s_num" ]] && continue
|
||||
[[ -z "$s_vip" ]] && continue
|
||||
|
|
@ -33,6 +43,7 @@ do
|
|||
TEMP_SLOT="/tmp/slot_${s_num}.conf"
|
||||
cp "$SLOT_TPL" "$TEMP_SLOT"
|
||||
|
||||
# Password logic (8 char limit)
|
||||
FULL_PASS="${BASE_PASSWORD}-${s_num}"
|
||||
SHORT_PASS="${FULL_PASS:0:8}"
|
||||
|
||||
|
|
@ -48,8 +59,10 @@ do
|
|||
|
||||
cat "$TEMP_SLOT" >> "$CONFIG_FILE"
|
||||
rm "$TEMP_SLOT"
|
||||
done <<< "$SLOT_DEFINITIONS"
|
||||
done
|
||||
|
||||
# Move check script to its final home
|
||||
# 6. PERMS
|
||||
cp ./check_services.sh "${CHECKS_DIR}/check_services.sh"
|
||||
chmod +x "${CHECKS_DIR}/check_services.sh"
|
||||
chmod +x "${CHECKS_DIR}/check_services.sh"
|
||||
|
||||
echo "Success: keepalived.conf generated."
|
||||
Loading…
Reference in a new issue