updated for static mapping
This commit is contained in:
parent
f1b1003677
commit
6a8c1b8a7a
1 changed files with 24 additions and 22 deletions
|
|
@ -1,37 +1,41 @@
|
|||
#!/bin/bash
|
||||
# --- 1. Setup ---
|
||||
mkdir -p /docker/keepalived/config /docker/keepalived/checks
|
||||
REPO_BASE="/etc/komodo/repos/mapletree-pve${PVE_NUM}lxc${LXC_NUM}/lxc${LXC_NUM}/keepalived"
|
||||
CONFIG_FILE="/docker/keepalived/config/keepalived.conf"
|
||||
# Move to the folder where this script lives
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
# --- 2. Build Header ---
|
||||
if [ ! -f "${REPO_BASE}/keepalived_header.tpl" ]; then
|
||||
echo "ERROR: Header template not found at ${REPO_BASE}"
|
||||
# Load the variables Komodo just wrote
|
||||
if [ -f .env ]; then
|
||||
export $(grep -v '^#' .env | xargs)
|
||||
else
|
||||
echo "ERROR: .env file not found in $(pwd)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp "${REPO_BASE}/keepalived_header.tpl" "$CONFIG_FILE"
|
||||
# Define paths relative to the current folder
|
||||
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
|
||||
cp "$HEADER_TPL" "$CONFIG_FILE"
|
||||
sed -i "s/{{LXC_NUM}}/${LXC_NUM}/g" "$CONFIG_FILE"
|
||||
|
||||
# --- 3. Parse "Hashtable" (SLOT_DEFINITIONS) ---
|
||||
# Use a process substitution to avoid subshell variable scope issues
|
||||
# Parse Slots
|
||||
while IFS=',' read -r s_num s_name s_dep s_state s_prio s_peer s_vip junk
|
||||
do
|
||||
# SANITY CHECKS:
|
||||
# Skip if the line is empty
|
||||
[[ -z "$s_num" ]] && continue
|
||||
# Skip if the line doesn't have enough columns (VIP is our 7th column)
|
||||
[[ -z "$s_vip" ]] && { echo "Skipping malformed line: $s_num"; continue; }
|
||||
[[ -z "$s_vip" ]] && continue
|
||||
|
||||
echo "Processing Slot $s_num: $s_name"
|
||||
TEMP_SLOT="/tmp/slot_${s_num}.conf"
|
||||
cp "${REPO_BASE}/keepalived_slot.tpl" "$TEMP_SLOT"
|
||||
cp "$SLOT_TPL" "$TEMP_SLOT"
|
||||
|
||||
# Handle Password (8 char limit)
|
||||
FULL_PASS="${BASE_PASSWORD}-${s_num}"
|
||||
SHORT_PASS="${FULL_PASS:0:8}"
|
||||
|
||||
# Inject variables
|
||||
sed -i "s/{{SLOT_NUM}}/${s_num}/g" "$TEMP_SLOT"
|
||||
sed -i "s/{{LXC_NUM}}/${LXC_NUM}/g" "$TEMP_SLOT"
|
||||
sed -i "s/{{SVC_NAME}}/${s_name}/g" "$TEMP_SLOT"
|
||||
|
|
@ -46,8 +50,6 @@ do
|
|||
rm "$TEMP_SLOT"
|
||||
done <<< "$SLOT_DEFINITIONS"
|
||||
|
||||
# --- 4. Finalize ---
|
||||
cp "${REPO_BASE}/check_services.sh" /docker/keepalived/checks/check_services.sh
|
||||
chmod +x /docker/keepalived/checks/check_services.sh
|
||||
|
||||
echo "Dynamic configuration generated for LXC
|
||||
# Move check script to its final home
|
||||
cp ./check_services.sh "${CHECKS_DIR}/check_services.sh"
|
||||
chmod +x "${CHECKS_DIR}/check_services.sh"
|
||||
Loading…
Reference in a new issue