Skip to content

Commit 3216091

Browse files
committed
chore: break down into functions
1 parent a5ca7b2 commit 3216091

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

ansible/files/postgres_prestart.sh.j2

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,49 @@
11
#!/bin/bash
22

3+
check_orioledb_enabled() {
4+
local pg_conf="/etc/postgresql/postgresql.conf"
5+
if [ ! -f "$pg_conf" ]; then
6+
return 0
7+
fi
8+
grep "^shared_preload_libraries" "$pg_conf" | grep -c "orioledb" || return 0
9+
}
10+
11+
get_shared_buffers() {
12+
local opt_conf="/etc/postgresql-custom/generated-optimizations.conf"
13+
if [ ! -f "$opt_conf" ]; then
14+
return 0
15+
fi
16+
grep "^shared_buffers = " "$opt_conf" | cut -d "=" -f2 | tr -d ' ' || return 0
17+
}
18+
19+
update_orioledb_buffers() {
20+
local pg_conf="/etc/postgresql/postgresql.conf"
21+
local value="$1"
22+
if grep -q "^orioledb.main_buffers = " "$pg_conf"; then
23+
sed -i "s/^orioledb.main_buffers = .*/orioledb.main_buffers = $value/" "$pg_conf"
24+
else
25+
echo "orioledb.main_buffers = $value" >> "$pg_conf"
26+
fi
27+
}
28+
29+
main() {
30+
local has_orioledb=$(check_orioledb_enabled)
31+
if [ "$has_orioledb" -lt 1 ]; then
32+
return 0
33+
fi
34+
local shared_buffers_value=$(get_shared_buffers)
35+
if [ ! -z "$shared_buffers_value" ]; then
36+
update_orioledb_buffers "$shared_buffers_value"
37+
fi
38+
}
39+
40+
# Initial locale setup
341
if [ $(cat /etc/locale.gen | grep -c en_US.UTF-8) -eq 0 ]; then
4-
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
42+
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
543
fi
644

745
if [ $(locale -a | grep -c en_US.utf8) -eq 0 ]; then
8-
locale-gen
46+
locale-gen
947
fi
48+
49+
main

0 commit comments

Comments
 (0)