Skip to content

Commit 6b24d6c

Browse files
committed
chore: add test script for postgres installation
1 parent dd57f4a commit 6b24d6c

File tree

6 files changed

+75
-23
lines changed

6 files changed

+75
-23
lines changed

amazon-arm.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"execute_command": "echo 'packer' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'",
5252
"type": "shell",
5353
"scripts": [
54-
"scripts/01-test",
54+
"scripts/01-postgres_check.sh",
5555
"scripts/02-credentials_cleanup.sh",
5656
"scripts/90-cleanup.sh",
5757
"scripts/91-log_cleanup.sh"

amazon.json

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"execute_command": "echo 'packer' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'",
5252
"type": "shell",
5353
"scripts": [
54+
"scripts/01-postgres_check.sh",
5455
"scripts/02-credentials_cleanup.sh",
5556
"scripts/90-cleanup.sh",
5657
"scripts/91-log_cleanup.sh"

ansible/tasks/setup-postgres-init.yml

-12
This file was deleted.

digitalOcean.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
{
3636
"type": "shell",
3737
"scripts": [
38-
"scripts/01-test",
38+
"scripts/01-postgres_check.sh",
3939
"scripts/90-cleanup.sh",
4040
"scripts/91-log_cleanup.sh",
4141
"scripts/99-img_check.sh"

scripts/01-postgres_check.sh

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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

scripts/01-test

-9
This file was deleted.

0 commit comments

Comments
 (0)