Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples: only terminate vtadmin if it was started #13433

Merged
merged 14 commits into from
Jul 5, 2023
25 changes: 25 additions & 0 deletions examples/common/lib/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,31 @@ function wait_for_healthy_shard() {
wait_for_shard_vreplication_engine "${keyspace}" "${shard}"
}

# Stop the specified vtadmin binary name using the provided PID file.
# Example:
# stop_vtadmin_process "vtadmin-web" "$VTDATAROOT/tmp/vtadmin-web.pid"
function stop_vtadmin_process() {
jfg956 marked this conversation as resolved.
Show resolved Hide resolved
if [[ -z ${1} || -z ${2} ]]; then
fail "A binary name and PID file must be specified when attempting to shutdown vtadmin"
mattlord marked this conversation as resolved.
Show resolved Hide resolved
fi

local binary_name="${1}"
local pidfile="${2}"
local pid=""

if [[ -e "${pidfile}" ]]; then
pid=$(cat "${pidfile}")
mattlord marked this conversation as resolved.
Show resolved Hide resolved
echo "Stopping ${binary_name}..."
kill "${pid}"
# Wait for the process to terminate
while ps -p "${pid}" > /dev/null; do
sleep 1
done
else
echo "Skipping stopping ${binary_name} because the specified PID file (${pidfile}) does not exist."
fi
}

# Print error message and exit with error code.
function fail() {
echo "ERROR: ${1}"
Expand Down
24 changes: 2 additions & 22 deletions examples/common/scripts/vtadmin-down.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,5 @@

mattlord marked this conversation as resolved.
Show resolved Hide resolved
source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh"

function stop_vtadmin() {
local name="$1"
local file="$2"

if [[ -z ${1} || -z ${2} ]]; then
fail "A binary name and PID file must be specified when attempting to shutdown vtadmin"
fi
if [[ -e "$file" ]]; then
echo "Stopping $name..."
local pid=$(cat "$file")
kill $pid
# Wait for the process to terminate
while ps -p $pid > /dev/null; do
sleep 1
done
else
echo "Skipping stopping $name because no pid file."
fi
}

stop_vtadmin "vtadmin-web" "$VTDATAROOT/tmp/vtadmin-web.pid"
stop_vtadmin "vtadmin-api" "$VTDATAROOT/tmp/vtadmin-api.pid"
stop_vtadmin_process "vtadmin-web" "$VTDATAROOT/tmp/vtadmin-web.pid"
stop_vtadmin_process "vtadmin-api" "$VTDATAROOT/tmp/vtadmin-api.pid"