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