-
-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy path01-postgres_check.sh
72 lines (63 loc) · 2.22 KB
/
01-postgres_check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
#
# Scripts in this directory are run during the build process.
# each script will be uploaded to /tmp on your build droplet,
# given execute permissions and run. The cleanup process will
# remove the scripts from your build system after they have run
# if you use the build_image task.
#
echo "Commencing Checks"
function check_database_is_ready {
echo -e "\nChecking if database is ready and accepting connections:"
if [ "$(pg_isready)" = "/tmp:5432 - accepting connections" ]; then
echo "Database is ready"
else
echo "Error: Database is not ready. Exiting"
exit 1
fi
}
function check_postgres_owned_dir_exists {
DIR=$1
USER="postgres"
echo -e "\nChecking if $DIR exists and owned by postgres user:"
if [ -d "$DIR" ]; then
echo "$DIR exists"
if [ $(stat -c '%U' $DIR) = "$USER" ]; then
echo "$DIR is owned by $USER"
else
echo "Error: $DIR is not owned by $USER"
exit 1
fi
else
echo "Error: ${DIR} not found. Exiting."
exit 1
fi
}
function check_lse_enabled {
ARCH=$(uname -m)
if [ $ARCH = "aarch64" ]; then
echo -e "\nArchitecture is $ARCH. Checking for LSE:"
LSE_COUNT=$(objdump -d /usr/lib/postgresql/bin/postgres | grep -i 'ldxr\|ldaxr\|stxr\|stlxr' | wc -l)
MOUTLINE_ATOMICS_COUNT=$(nm /usr/lib/postgresql/bin/postgres | grep __aarch64_have_lse_atomics | wc -l)
# Checking for load and store exclusives
if [ $LSE_COUNT -gt 0 ]; then
echo "Postgres has LSE enabled"
else
echo "Error: Postgres failed to be compiled with LSE. Exiting"
exit 1
fi
# Checking if successfully compiled with -moutline-atomics
if [ $MOUTLINE_ATOMICS_COUNT -gt 0 ]; then
echo "Postgres has been compiled with -moutline-atomics"
else
echo "Error: Postgres failed to be compiled with -moutline-atomics. Exiting"
exit 1
fi
else
echo "Architecture is $ARCH. Not checking for LSE."
fi
}
check_database_is_ready
check_postgres_owned_dir_exists "/var/lib/postgresql"
check_postgres_owned_dir_exists "/etc/postgresql"
check_lse_enabled