Skip to content

Commit

Permalink
chore: break down into functions
Browse files Browse the repository at this point in the history
  • Loading branch information
samrose committed Nov 21, 2024
1 parent a5ca7b2 commit 3216091
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions ansible/files/postgres_prestart.sh.j2
Original file line number Diff line number Diff line change
@@ -1,9 +1,49 @@
#!/bin/bash

check_orioledb_enabled() {
local pg_conf="/etc/postgresql/postgresql.conf"
if [ ! -f "$pg_conf" ]; then
return 0
fi
grep "^shared_preload_libraries" "$pg_conf" | grep -c "orioledb" || return 0
}

get_shared_buffers() {
local opt_conf="/etc/postgresql-custom/generated-optimizations.conf"
if [ ! -f "$opt_conf" ]; then
return 0
fi
grep "^shared_buffers = " "$opt_conf" | cut -d "=" -f2 | tr -d ' ' || return 0
}

update_orioledb_buffers() {
local pg_conf="/etc/postgresql/postgresql.conf"
local value="$1"
if grep -q "^orioledb.main_buffers = " "$pg_conf"; then
sed -i "s/^orioledb.main_buffers = .*/orioledb.main_buffers = $value/" "$pg_conf"
else
echo "orioledb.main_buffers = $value" >> "$pg_conf"
fi
}

main() {
local has_orioledb=$(check_orioledb_enabled)
if [ "$has_orioledb" -lt 1 ]; then
return 0
fi
local shared_buffers_value=$(get_shared_buffers)
if [ ! -z "$shared_buffers_value" ]; then
update_orioledb_buffers "$shared_buffers_value"
fi
}

# Initial locale setup
if [ $(cat /etc/locale.gen | grep -c en_US.UTF-8) -eq 0 ]; then
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
fi

if [ $(locale -a | grep -c en_US.utf8) -eq 0 ]; then
locale-gen
locale-gen
fi

main

0 comments on commit 3216091

Please sign in to comment.