Files
spark/tools/sparkd.sh
T

102 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
##
# @file sparkd.sh
#
# @brief Run sparkd. Renames log file with timestamp so each run has its
# own log.
##
get_unique_file() {
filename="$1"
unique_filename="$filename"
declare -i count=1
declare -ir MAX_COUNT=60
while [ -e "$unique_filename" ]; do
unique_filename="$filename($count)"
count=$count+1
if [ $count -eq $MAX_COUNT ]; then
echo "Failed to make unique name for '$filename'"
exit 1
fi
done
echo "$unique_filename"
}
roll_over_log() {
log_dir="/home/bts/sparkdata/data/logging.sparkd"
log_file="$log_dir/log"
if [ ! -f "$log_file" ]; then
return
fi
archived_log_file="$(get_unique_file "${log_file}_$(date "+%Y%m%d-%H%M")")"
echo "Renaming existing log file $archived_log_file"
mv "$log_file" "$archived_log_file"
}
declare build_type=""
declare compiler=""
declare -a sparkd_args
while [[ $# -gt 0 ]]; do
declare -l arg="$1"
case "$arg" in
debug)
;&
--debug)
build_type="debug"
shift 1
;;
release)
;&
--release)
build_type="release"
shift 1
;;
clang)
;&
--clang)
compiler="clang"
shift 1
;;
gcc)
;&
--gcc)
compiler="gcc"
shift 1
;;
roll-logs)
roll_over_log
exit
;;
--)
shift 1
sparkd_args=($@)
shift ${#@}
;;
*)
sparkd_args+=("$1")
shift 1
;;
esac
done
if [ -z "$build_type" ]; then
build_type="debug"
fi
if [ -z "$compiler" ]; then
if [ "$build_type" = "debug" ]; then
compiler="clang"
else
compiler="gcc"
fi
fi
this_dir="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")"
sparkd_dir="$(realpath "$this_dir/../build/sparkd-${build_type}-${compiler}/server")"
roll_over_log
echo "Running sparkd ${build_type} ${compiler}"
echo "------------------------------------------------------------------------"
cd $sparkd_dir
./sparkd ${sparkd_args[@]}