Skip to content

Commit 372fe4c

Browse files
Create a copy of common example scripts to use in backup local examples
Signed-off-by: Rohit Nayak <[email protected]>
1 parent 9717bb2 commit 372fe4c

18 files changed

+702
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# Copyright 2022 The Vitess Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This is an example script that stops the consul server started by consul-up.sh.
18+
19+
source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh"
20+
21+
stop_process "consul" "$VTDATAROOT/tmp/consul.pid"
22+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
# Copyright 2022 The Vitess Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This is an example script that creates a single-node consul datacenter.
18+
19+
source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh"
20+
21+
cell=${CELL:-'test'}
22+
consul_http_port=${CONSUL_HTTP_PORT:-'8500'}
23+
consul_server_port=${CONSUL_SERVER_PORT:-'8300'}
24+
25+
# Check that consul is not already running
26+
curl "http://${CONSUL_SERVER}:${consul_http_port}" &> /dev/null && fail "consul is already running. Exiting."
27+
28+
set -x
29+
consul agent \
30+
-server \
31+
-bootstrap-expect=1 \
32+
-node=vitess-consul \
33+
-bind="${CONSUL_SERVER}" \
34+
-server-port="${consul_server_port}" \
35+
-data-dir="${VTDATAROOT}/consul/" -ui > "${VTDATAROOT}/tmp/consul.out" 2>&1 &
36+
37+
PID=$!
38+
echo $PID > "${VTDATAROOT}/tmp/consul.pid"
39+
sleep 5
40+
41+
# Add the CellInfo description for the cell.
42+
# If the node already exists, it's fine, means we used existing data.
43+
echo "add ${cell} CellInfo"
44+
set +e
45+
# shellcheck disable=SC2086
46+
command vtctldclient --server internal --topo-implementation consul --topo-global-server-address "${CONSUL_SERVER}:${consul_http_port}" AddCellInfo \
47+
--root "/vitess/${cell}" \
48+
--server-address "${CONSUL_SERVER}:${consul_http_port}" \
49+
"${cell}"
50+
set -e
51+
52+
echo "consul start done..."
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# Copyright 2019 The Vitess Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This is an example script that stops the etcd servers started by etcd-up.sh.
18+
19+
source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh"
20+
21+
stop_process "etcd" "$VTDATAROOT/tmp/etcd.pid"
22+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
# Copyright 2019 The Vitess Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This is an example script that creates a quorum of Etcd servers.
18+
19+
source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh"
20+
21+
cell=${CELL:-'test'}
22+
23+
echo "Starting etcd..."
24+
25+
# Check that etcd is not already running
26+
curl "http://${ETCD_SERVER}" > /dev/null 2>&1 && fail "etcd is already running. Exiting."
27+
28+
etcd --data-dir "${VTDATAROOT}/etcd/" --listen-client-urls "http://${ETCD_SERVER}" --advertise-client-urls "http://${ETCD_SERVER}" > "${VTDATAROOT}"/tmp/etcd.out 2>&1 &
29+
PID=$!
30+
echo $PID > "${VTDATAROOT}/tmp/etcd.pid"
31+
sleep 5
32+
33+
# And also add the CellInfo description for the cell.
34+
# If the node already exists, it's fine, means we used existing data.
35+
echo "add ${cell} CellInfo"
36+
set +e
37+
command vtctldclient --server internal AddCellInfo \
38+
--root "/vitess/${cell}" \
39+
--server-address "${ETCD_SERVER}" \
40+
"${cell}"
41+
set -e
42+
43+
echo "etcd is running!"
44+
45+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# Copyright 2019 The Vitess Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This is an example script that stops the mysqld and vttablet instances
18+
# created by vttablet-up.sh
19+
20+
source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh"
21+
22+
cell=${CELL:-'test'}
23+
uid=$TABLET_UID
24+
printf -v alias '%s-%010d' $cell $uid
25+
echo "Shutting down MySQL for tablet $alias..."
26+
27+
mysqlctl --tablet_uid $uid shutdown
28+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
# Copyright 2019 The Vitess Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This is an example script that creates a single shard vttablet deployment.
18+
19+
source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh"
20+
21+
cell=${CELL:-'test'}
22+
uid=$TABLET_UID
23+
mysql_port=$[17000 + $uid]
24+
printf -v alias '%s-%010d' $cell $uid
25+
printf -v tablet_dir 'vt_%010d' $uid
26+
27+
mkdir -p $VTDATAROOT/backups
28+
29+
echo "Starting MySQL for tablet $alias..."
30+
action="init"
31+
32+
if [ -d $VTDATAROOT/$tablet_dir ]; then
33+
echo "Resuming from existing vttablet dir:"
34+
echo " $VTDATAROOT/$tablet_dir"
35+
action='start'
36+
fi
37+
38+
mysqlctl \
39+
--log_dir $VTDATAROOT/tmp \
40+
--tablet_uid $uid \
41+
--mysql_port $mysql_port \
42+
$action
43+
44+
echo -e "MySQL for tablet $alias is running!"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# Copyright 2023 The Vitess Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh"
18+
19+
stop_process "vtadmin-web" "$VTDATAROOT/tmp/vtadmin-web.pid"
20+
stop_process "vtadmin-api" "$VTDATAROOT/tmp/vtadmin-api.pid"
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
3+
# Copyright 2023 The Vitess Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
function output() {
18+
echo -e "$@"
19+
}
20+
21+
script_dir="$(dirname "${BASH_SOURCE[0]:-$0}")"
22+
source "${script_dir}/../env.sh"
23+
24+
cluster_name="local"
25+
log_dir="${VTDATAROOT}/tmp"
26+
web_dir="${script_dir}/../../../web/vtadmin"
27+
28+
vtadmin_api_port=14200
29+
vtadmin_web_port=14201
30+
31+
case_insensitive_hostname=$(echo "$hostname" | tr '[:upper:]' '[:lower:]')
32+
33+
output "\n\033[1;32mvtadmin-api expects vtadmin-web at, and set http-origin to \"http://${case_insensitive_hostname}:${vtadmin_web_port}\"\033[0m"
34+
35+
vtadmin \
36+
--addr "${case_insensitive_hostname}:${vtadmin_api_port}" \
37+
--http-origin "http://${case_insensitive_hostname}:${vtadmin_web_port}" \
38+
--http-tablet-url-tmpl "http://{{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }}" \
39+
--tracer "opentracing-jaeger" \
40+
--grpc-tracing \
41+
--http-tracing \
42+
--logtostderr \
43+
--alsologtostderr \
44+
--rbac \
45+
--rbac-config="${script_dir}/../vtadmin/rbac.yaml" \
46+
--cluster "id=${cluster_name},name=${cluster_name},discovery=staticfile,discovery-staticfile-path=${script_dir}/../vtadmin/discovery.json,tablet-fqdn-tmpl=http://{{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }},schema-cache-default-expiration=1m" \
47+
> "${log_dir}/vtadmin-api.out" 2>&1 &
48+
49+
vtadmin_api_pid=$!
50+
echo ${vtadmin_api_pid} > "${log_dir}/vtadmin-api.pid"
51+
52+
echo "\
53+
vtadmin-api is running!
54+
- API: http://${case_insensitive_hostname}:${vtadmin_api_port}
55+
- Logs: ${log_dir}/vtadmin-api.out
56+
- PID: ${vtadmin_api_pid}
57+
"
58+
59+
echo "Building vtadmin-web..."
60+
source "${web_dir}/build.sh"
61+
62+
# Wait for vtadmin to successfully discover the cluster
63+
expected_cluster_result="{\"result\":{\"clusters\":[{\"id\":\"${cluster_name}\",\"name\":\"${cluster_name}\"}]},\"ok\":true}"
64+
for _ in {0..100}; do
65+
result=$(curl -s "http://${case_insensitive_hostname}:${vtadmin_api_port}/api/clusters")
66+
if [[ ${result} == "${expected_cluster_result}" ]]; then
67+
break
68+
fi
69+
sleep 0.1
70+
done
71+
72+
# Check one last time
73+
[[ $(curl -s "http://${case_insensitive_hostname}:${vtadmin_api_port}/api/clusters") == "${expected_cluster_result}" ]] || fail "vtadmin failed to discover the running example Vitess cluster."
74+
75+
[[ ! -d "$web_dir/build" ]] && fail "Please make sure the VTAdmin files are built in $web_dir/build, using 'make build'"
76+
77+
"${web_dir}/node_modules/.bin/serve" --no-clipboard -l $vtadmin_web_port -s "${web_dir}/build" \
78+
> "${log_dir}/vtadmin-web.out" 2>&1 &
79+
80+
vtadmin_web_pid=$!
81+
echo ${vtadmin_web_pid} > "${log_dir}/vtadmin-web.pid"
82+
83+
echo "\
84+
vtadmin-web is running!
85+
- Browser: http://${case_insensitive_hostname}:${vtadmin_web_port}
86+
- Logs: ${log_dir}/vtadmin-web.out
87+
- PID: ${vtadmin_web_pid}
88+
"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# Copyright 2019 The Vitess Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This is an example script that stops vtctld.
18+
19+
source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh"
20+
21+
stop_process "vtctld" "$VTDATAROOT/tmp/vtctld.pid"
22+

0 commit comments

Comments
 (0)