# Start the Kea process. Do not start the process if there is an instance
# already running.
start_server() {
- binary_path=${1} # Full path to the binary.
- full_command=("${@}") # Binary and arguments.
+ binary_path=${1} # Full path to the binary.
# Extract the name of the binary from the path.
local binary_name
binary_name=$(basename -- "${binary_path}")
log_info "${binary_name} appears to be running, see: \
PID ${_pid}, PID file: ${_pid_file}."
else
- log_info "Starting ${full_command[*]}"
+ log_info "Starting ${*}"
# Start the process.
- "${full_command[@]}" &
+ "${@}" &
fi
}
. "@abs_top_builddir@/src/bin/admin/admin-utils.sh"
fi
-# Save the command line arguments for later use.
-cqlargs=("${@}")
-
# Need a path for temporary files created during upgrade data migration
# Use the state directory in the install path directory if it exists, otherwise
# use the build tree
# Ensures the current schema version is 2.0. If not it exits.
check_version() {
- version=$(cql_version "${cqlargs[@]}")
+ version=$(cql_version "${@}")
if [ "${version}" != "2.0" ]; then
printf "This script upgrades 2.0 to 3.0. Reported version is %s. Skipping upgrade.\n" "${version}"
# Peforms the schema changes from 2.0 to 3.0
update_schema() {
- cqlsh "${cqlargs[@]}" <<EOF
+ cqlsh "${@}" <<EOF
-- This line starts database upgrade to version 3.0
-- Add a column holding leases for user context.
(id, host_ipv4_subnet_id, host_ipv6_subnet_id, option_subnet_id)\
TO '$export_file'"
- if ! cqlsh "${cqlargs[@]}" -e "$query"
+ if ! cqlsh "${@}" -e "$query"
then
exit_now 1 "Cassandra export failed! Could not migrate data!"
fi
# We have at least one update in the update file, so submit it # to cqlsh.
echo "$update_cnt update statements written to $update_file"
echo "Running the updates..."
- if ! cqlsh "${cqlargs[@]}" -f "$update_file"
+ if ! cqlsh "${@}" -f "$update_file"
then
exit_now 1 "Cassandra updates failed"
fi
exit_now 0 "Updated $update_cnt of $line_cnt records"
}
-check_version
-if ! update_schema; then
+check_version "{@}"
+if ! update_schema "{@}"; then
printf 'Schema update FAILED!\n'
exit 1
fi
-migrate_host_data
+migrate_host_data "${@}"
temp_file_dir="@abs_top_builddir@/src/share/database/scripts/cql"
fi
-# Save the command line arguments for later use.
-cqlargs=("${@}")
-
# Ensures the current schema version is 3.0. If not it exits.
check_version() {
- version=$(cql_version "${cqlargs[@]}")
+ version=$(cql_version "${@}")
if [ "${version}" != "3.0" ]; then
printf "This script upgrades 3.0 to 4.0. Reported version is %s. Skipping upgrade.\n" "${version}"
# Peforms the schema changes from 3.0 to 4.0
update_schema() {
- cqlsh "${cqlargs[@]}" <<EOF
+ cqlsh "${@}" <<EOF
-- This line starts database upgrade to version 4.0
-- -----------------------------------------------------
# Peforms the clean up schema changes from 3.0 to 4.0
clean_up_schema() {
- cqlsh "${cqlargs[@]}" <<EOF
+ cqlsh "${@}" <<EOF
DROP TABLE IF EXISTS host_reservations;
DROP INDEX IF EXISTS host_reservationsindex1;
# status - integer value to pass to sh:exit
# explanation - "quoted" text message to emit to stdout
exit_now() {
- status=$1;shift
- explanation=$1
+ status=$1; shift
+ explanation=$1; shift
clean_up
if [ "$status" -eq 0 ]
then
- clean_up_schema
+ clean_up_schema "${@}"
echo "Data Migration SUCCESS! $explanation"
else
echo "Data Migration FAILURE! $explanation"
TO '$export_file'"
- if ! cqlsh "${cqlargs[@]}" -e "$query"
+ if ! cqlsh "${@}" -e "$query"
then
- exit_now 1 "Cassandra export failed! Could not migrate data!"
+ exit_now 1 "Cassandra export failed! Could not migrate data!" "{@}"
fi
# Strip the carriage returns that CQL insists on adding.
mv $export_file.2 $export_file
else
# Shouldn't happen but then again we're talking about CQL here
- exit_now 1 "Cassandra export file $export_file is missing?"
+ exit_now 1 "Cassandra export file $export_file is missing?" "{@}"
fi
# Iterate through the exported data, accumulating update statements,
# If we didn't record any updates, then hey, we're good to go!
if [ "$update_cnt" -eq 0 ]
then
- exit_now 0 "Completed successfully: No updates were needed"
+ exit_now 0 "Completed successfully: No updates were needed" "{@}"
fi
# We have at least one update in the update file, so submit it # to cqlsh.
option_scope_id) \
FROM '$update_file'"
- if ! cqlsh "${cqlargs[@]}" -e "$query"
+ if ! cqlsh "${@}" -e "$query"
then
- exit_now 1 "Cassandra updates failed"
+ exit_now 1 "Cassandra updates failed" "{@}"
fi
- exit_now 0 "Updated $update_cnt of $line_cnt records"
+ exit_now 0 "Updated $update_cnt of $line_cnt records" "{@}"
}
-check_version
-if ! update_schema; then
+check_version "${@}"
+if ! update_schema "${@}"; then
printf 'Schema update FAILED!\n'
exit 1
fi
-migrate_host_data
+migrate_host_data "${@}"
. "@abs_top_builddir@/src/bin/admin/admin-utils.sh"
fi
-# Save the command line arguments for later use.
-cqlargs=("${@}")
-
# Need a path for temporary files created during data update
# Use the state directory in the install path directory if it exists, otherwise
# use the build tree
# Ensures the current schema version is 4.0. If not it exits.
check_version() {
- version=$(cql_version "${cqlargs[@]}")
+ version=$(cql_version "${@}")
if [ "${version}" != "4.0" ]; then
printf "This script upgrades 4.0 to 5.0. Reported version is %s. Skipping upgrade.\n" "${version}"
# Peforms the schema changes from 4.0 to 5.0
update_schema() {
- cqlsh "${cqlargs[@]}" <<EOF
+ cqlsh "${@}" <<EOF
-- This line starts database upgrade to version 5.0
-- Add the lower case hostname column to reservations.
query="COPY hosts (key, id, hostname) TO '$host_export_file'"
- if ! cqlsh "${cqlargs[@]}" -e "$query"
+ if ! cqlsh "${@}" -e "$query"
then
exit_now 1 "Cassandra get hostname failed! Could not update host!"
fi
echo "$update_cnt host update statements written to $host_update_file"
echo "Running the updates..."
- if ! cqlsh "${cqlargs[@]}" -f "$host_update_file"
+ if ! cqlsh "${@}" -f "$host_update_file"
then
exit_now 1 "Cassandra host updates failed"
fi
query="COPY lease4 (address, hostname) TO '$lease4_export_file'"
- if ! cqlsh "${cqlargs[@]}" -e "$query"
+ if ! cqlsh "${@}" -e "$query"
then
exit_now 1 "Cassandra get hostname failed! Could not update lease4!"
fi
echo "$update_cnt lease4 update statements written to $lease4_update_file"
echo "Running the updates..."
- if ! cqlsh "${cqlargs[@]}" -f "$lease4_update_file"
+ if ! cqlsh "${@}" -f "$lease4_update_file"
then
exit_now 1 "Cassandra lease4 updates failed"
fi
echo "Exporting hostnames to $lease6_export_file ..."
query="COPY lease6 (address, hostname) TO '$lease6_export_file'"
- if ! cqlsh "${cqlargs[@]}" -e "$query"
+ if ! cqlsh "${@}" -e "$query"
then
exit_now 1 "Cassandra get hostname failed! Could not update lease6!"
fi
echo "$update_cnt lease6 update statements written to $lease6_update_file"
echo "Running the updates..."
- if ! cqlsh "${cqlargs[@]}" -f "$lease6_update_file"
+ if ! cqlsh "${@}" -f "$lease6_update_file"
then
exit_now 1 "Cassandra lease6 updates failed"
fi
lease6_export_file="$temp_file_dir/cql_lease6_export.csv"
lease6_update_file="$temp_file_dir/cql_lease6_update.cql"
-check_version
-if ! update_schema; then
+check_version "${@}"
+if ! update_schema "${@}"; then
printf 'Schema update FAILED!\n'
exit 1
fi
-update_host_data
-update_lease4_data
-update_lease6_data
+update_host_data "${@}"
+update_lease4_data "${@}"
+update_lease6_data "${@}"
fi
# Save the command line args, as we use these later change_column function.
-cmdargs=("${@}")
# Function to rename a column in a table.
change_column() {
# First let's find out if the column name in the table actually needs updating.
sql="select count(column_name) from information_schema.columns where table_schema='$schema' and table_name = '$table' and column_name = '$ocolumn'"
- if ! count=$(mysql -N -B "${cmdargs[@]}" -e "$sql")
+ if ! count=$(mysql -N -B "${@}" -e "${sql}")
then
printf 'change_column: schema query failed [%s]\n' "${sql}"
exit 255
if [ "$count" -eq 1 ]
then
sql="ALTER TABLE $table CHANGE COLUMN $ocolumn $ncolumn"
- if ! mysql -N -B "${cmdargs[@]}" -e "$sql"
+ if ! mysql -N -B "${@}" -e "${sql}"
then
printf 'change_column: alter query failed [%s]\n' "${sql}"
exit 255
# We need to rename the columns in the option def tables because "array" is
# a MySQL keyword as of 8.0.17
-change_column "${schema}" dhcp4_option_def array "is_array TINYINT(1) NOT NULL"
-change_column "${schema}" dhcp6_option_def array "is_array TINYINT(1) NOT NULL"
+change_column "${schema}" dhcp4_option_def array "is_array TINYINT(1) NOT NULL" "${@}"
+change_column "${schema}" dhcp6_option_def array "is_array TINYINT(1) NOT NULL" "${@}"