forked from PaaS-datascience/docker-vertica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verticad
executable file
·126 lines (110 loc) · 4.47 KB
/
verticad
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
# SIGINT trap to shut down the DB properly upon CTRL+C
at_sigint() {
if [[ "$NODE_TYPE" == "master" ]]
then
echo "Received SIGINT on the master node: stopping the database..."
su - dbadmin -c "${VERTICA_HOME}/bin/admintools -t stop_db -d docker --force"
echo "Database has been stopped on the master node".
else
while ! su - dbadmin -c "${VERTICA_HOME}/bin/admintools -t db_status -s DOWN" | grep -q docker && pgrep --exact vertica >/dev/null
do
echo "Waiting for the database to shutdown before stopping the node..."
sleep 2
done
echo "Database not running anymore: shutting down the node."
fi
exit 0
}
set -e
if [[ ! -d "${VERTICA_HOME}" ]]
then
echo "${VERTICA_HOME} does not exist in the guest. Please mount a data volume on ${VERTICA_HOME} and restart the guest."
exit 1
fi
capabilities=$(capsh --print | grep Current)
for capability in SYS_NICE, SYS_RESOURCE
do
if ! echo $capabilities | grep -qi $capability
then
echo "Missing $capability. Start the container with --cap-add $capability."
exit 1
fi
done
if [[ ! -d "${VERTICA_HOME}/catalog" ]] || [[ ! -d "${VERTICA_HOME}/data" ]]
then
echo "Creating data and catalog directories..."
chown -R dbadmin:verticadba ${VERTICA_HOME}
su - dbadmin -c "mkdir -p ${VERTICA_HOME}/catalog -m 0755"
su - dbadmin -c "mkdir -p ${VERTICA_HOME}/data -m 0755"
fi
echo "Data and catalog dirs exist on this node."
# Everything that gets executed in this block should happen once and only once
# Hence the concept of 'master' node, that has no meaning in Vertica itself
if [[ "$NODE_TYPE" == "master" ]]
then
if [[ ! -d "${VERTICA_HOME}/bin" ]]
then
echo "Installing RPM on this node..."
rpm -Uvh /tmp/vertica.rpm
chown -R dbadmin:verticadba ${VERTICA_HOME}/config
chown -R dbadmin:verticadba ${VERTICA_HOME}/log
fi
echo "The RPM is installed."
if [[ ! -e ${VERTICA_HOME}/config/admintools.conf ]]
then
echo "Setting up a Vertica cluster from this master node..."
${VERTICA_HOME}/sbin/install_vertica \
--hosts "$CLUSTER_NODES" \
--rpm /tmp/vertica.rpm \
--no-system-configuration \
--license CE \
--accept-eula \
--dba-user dbadmin \
--dba-user-password-disabled \
--failure-threshold NONE
fi
echo "The cluster is set up."
# Sets up a cluster (a set of nodes sharing the same spread configuration)
if ! su - dbadmin -c "${VERTICA_HOME}/bin/admintools -t view_cluster" | grep -q docker
then
echo "Now creating the database..."
su - dbadmin -c "${VERTICA_HOME}/bin/admintools \
-t create_db \
-s "$CLUSTER_NODES" \
-d docker \
-c ${VERTICA_HOME}/catalog \
-D ${VERTICA_HOME}/data \
--skip-fs-checks"
fi
echo "The docker database has been created on the cluster."
# Starts vertica up if it is not already started
if ! su - dbadmin -c "${VERTICA_HOME}/bin/admintools -t db_status -s UP" | grep -q docker
then
echo "Starting Vertica..."
su - dbadmin -c "${VERTICA_HOME}/bin/admintools -t start_db -d docker --force --noprompts"
fi
echo "Vertica is started."
# Installs the VMart test schema if this has been supplied as environment variable
if [ ${WITH_VMART} = 'true' ]
then
if ! su - dbadmin -c "${VERTICA_HOME}/bin/vsql -qt -c 'select schema_name from schemata'" | grep -q online_sales
then
echo "Importing VMart schema data in this cluster"
su - dbadmin -c "cd /opt/vertica/examples/VMart_Schema/;./vmart_gen >/dev/null 2>&1;/opt/vertica/bin/vsql -q -t -f vmart_define_schema.sql >/dev/null 2>&1;/opt/vertica/bin/vsql -q -t -f vmart_load_data.sql >/dev/null 2>&1"
fi
echo "The VMart schema is imported."
fi
ip=$(hostname --all-ip-addresses | awk '{print $1}')
echo "---------------------------------------------------------------------------------------------------------------------------------------"
echo "You can now connect to the server '${ip}' on port 5433, using the 'docker' database with the user 'dbadmin' without password."
echo "GDBServer can be attached to with \"target extended-remote ${ip}:${GDBSERVER_PORT}\"."
echo "You can attach to the Vertica PID using \"attach $(pgrep -x vertica)\"."
echo "---------------------------------------------------------------------------------------------------------------------------------------"
fi
echo "<!--XSUPERVISOR:BEGIN-->VERTICASTART<!--XSUPERVISOR:END-->"
# Registers a SIGINT trap and sleeps until CTRL+C is pressed
trap at_sigint INT
while true; do
sleep 2
done