forked from jbfavre/docker-vertica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
executable file
·49 lines (41 loc) · 1.55 KB
/
docker-entrypoint.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
#!/bin/bash
set -e
# Vertica should be shut down properly
function shut_down() {
echo "Shutting Down"
vertica_proper_shutdown
echo 'Saving configuration'
mkdir -p ${VERTICADATA}/config
/bin/cp /opt/vertica/config/admintools.conf ${VERTICADATA}/config/admintools.conf
}
function vertica_proper_shutdown() {
echo 'Vertica: Closing active sessions'
/bin/su - dbadmin -c '/opt/vertica/bin/vsql -U dbadmin -d docker -c "SELECT CLOSE_ALL_SESSIONS();"'
echo 'Vertica: Flushing everything on disk'
/bin/su - dbadmin -c '/opt/vertica/bin/vsql -U dbadmin -d docker -c "SELECT MAKE_AHM_NOW();"'
echo 'Vertica: Stopping database'
/bin/su - dbadmin -c '/opt/vertica/bin/admintools -t stop_db -d docker -i'
}
function fix_filesystem_permissions() {
chown -R dbadmin:verticadba "${VERTICADATA}"
chown dbadmin:verticadba /opt/vertica/config/admintools.conf
}
trap "shut_down" SIGKILL SIGTERM SIGHUP SIGINT EXIT
echo 'Starting up'
if [ -z "$(ls -A "${VERTICADATA}")" ]; then
echo 'Fixing filesystem permissions'
fix_filesystem_permissions
echo 'Creating database'
su - dbadmin -c "/opt/vertica/bin/admintools -t create_db --skip-fs-checks -s localhost -d docker -c ${VERTICADATA}/catalog -D ${VERTICADATA}/data"
else
echo 'Restoring configuration'
cp ${VERTICADATA}/config/admintools.conf /opt/vertica/config/admintools.conf
echo 'Fixing filesystem permissions'
fix_filesystem_permissions
echo 'Starting Database'
su - dbadmin -c '/opt/vertica/bin/admintools -t start_db -d docker -i'
fi
echo "Vertica is now running"
while true; do
sleep 1
done