-
Notifications
You must be signed in to change notification settings - Fork 15
/
verticad
executable file
·183 lines (159 loc) · 6.03 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/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
}
cluster_is_up() {
su - dbadmin -c "${VERTICA_HOME}/bin/admintools -t db_status -s UP" | grep -q docker
}
start_cluster() {
su - dbadmin -c "${VERTICA_HOME}/bin/admintools -t start_db -d docker --force --noprompts"
}
get_vertica_pid() {
pgrep -x vertica
}
nb_down_nodes() {
su - dbadmin -c "/opt/vertica/bin/admintools -t view_cluster -x | grep docker | grep -v UP | wc -l"
}
restart_down_nodes() {
su - dbadmin -c "/opt/vertica/bin/admintools -t view_cluster -x | awk '/docker/ && ! /UP/{print \$3}' | paste -s -d, - | xargs /opt/vertica/bin/admintools -t restart_node -d docker -s "
}
print_info_message() {
echo "---------------------------------------------------------------------------------------------------------------------------------------"
cat $1
echo "---------------------------------------------------------------------------------------------------------------------------------------"
}
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
LICENSE="CE"
if [[ -f "/tmp/license.dat" ]]
then
LICENSE="/tmp/license.dat"
fi
echo "Setting up a Vertica cluster from this master node... License : $LICENSE"
INSTALL_COMMAND="${VERTICA_HOME}/sbin/install_vertica \
--hosts "$CLUSTER_NODES" \
--rpm /tmp/vertica.rpm \
--no-system-configuration \
--license "$LICENSE" \
--accept-eula \
--dba-user dbadmin \
--dba-user-password-disabled \
--failure-threshold NONE \
--point-to-point \
--ignore-aws-instance-type"
if [[ ! -z "$VERTICA_LARGE_CLUSTER" ]]
then
INSTALL_COMMAND="$INSTALL_COMMAND --large-cluster $VERTICA_LARGE_CLUSTER"
fi
echo "RUNNING $INSTALL_COMMAND"
eval $INSTALL_COMMAND
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 the cluster if not already started
echo "Checking cluster status..."
if ! cluster_is_up
then
echo "Starting Vertica..."
start_cluster
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}')
print_info_message <<EOM
You can now connect to the server '${ip}' on port 5433, using the 'docker' database with the user 'dbadmin' without password.
GDBServer can be attached to with "target extended-remote ${ip}:${GDBSERVER_PORT}".
You can attach to the Vertica PID using "attach $(get_vertica_pid)".
EOM
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
# If the database should be restarted automatically, check for the status every 5 sec
if [ "${NODE_TYPE}" = "master" ] && [ "${ENABLE_WATCHDOG}" = 'true' ]
then
if ! cluster_is_up
then
echo "The whole cluster is down! Restarting..."
start_cluster && print_info_message <(echo "You can attach to the new Vertica PID using \"attach $(get_vertica_pid) \".")
fi
nb_down=$(nb_down_nodes)
if cluster_is_up && [ $nb_down -gt 0 ]
then
echo "$nb_down node(s) down! Restarting..."
restart_down_nodes && print_info_message <(echo "You can attach to the new Vertica PID using \"attach $(get_vertica_pid) \".")
fi
fi
sleep 5
done