2015-12-19 13:59:45 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2021-07-29 10:30:55 +01:00
|
|
|
# -----------------------------------------------
|
|
|
|
|
# User input
|
|
|
|
|
# -----------------------------------------------
|
|
|
|
|
|
|
|
|
|
function printHelp() {
|
2021-09-06 16:17:11 +02:00
|
|
|
echo "Wrapper for simplifying execution of Hal Server.
|
2021-07-29 10:30:55 +01:00
|
|
|
Usage:
|
|
|
|
|
|
|
|
|
|
$(basename $0)
|
|
|
|
|
[-f|--foreground]
|
2024-10-01 23:38:21 +02:00
|
|
|
[-b|--background]
|
|
|
|
|
[--no-color]
|
2021-09-06 16:17:11 +02:00
|
|
|
[-h|--help]
|
2021-07-29 10:30:55 +01:00
|
|
|
|
|
|
|
|
Where:
|
2024-10-01 23:38:21 +02:00
|
|
|
--foreground (Default) Run Hal Server in the foreground instead of detaching a new screen.
|
|
|
|
|
--background Run Hal Server in the background through screen.
|
|
|
|
|
--no-color Disable color printout on the console.
|
2021-07-29 10:30:55 +01:00
|
|
|
--help Print this help message.
|
|
|
|
|
"
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-27 23:33:56 +01:00
|
|
|
MODE="FOREGROUND"
|
2023-05-16 01:43:16 +02:00
|
|
|
GRADLE_COLOR="--console=rich"
|
2021-07-29 10:30:55 +01:00
|
|
|
|
|
|
|
|
until [[ $# -eq 0 ]]; do
|
|
|
|
|
case "$1" in
|
2021-09-15 16:29:59 +02:00
|
|
|
-f|--foreground)
|
|
|
|
|
MODE="FOREGROUND"
|
2021-07-29 10:30:55 +01:00
|
|
|
;;
|
|
|
|
|
|
2023-02-27 23:33:56 +01:00
|
|
|
-b|--background)
|
|
|
|
|
MODE="BACKGROUND"
|
|
|
|
|
;;
|
|
|
|
|
|
2023-05-16 01:43:16 +02:00
|
|
|
--no-color)
|
2024-07-16 23:44:46 +02:00
|
|
|
echo "INFO: Running with plain console."
|
2023-09-28 22:14:13 +02:00
|
|
|
GRADLE_COLOR="--console=plain"
|
2023-05-16 01:43:16 +02:00
|
|
|
;;
|
|
|
|
|
|
2021-09-06 16:17:11 +02:00
|
|
|
-h|--help)
|
|
|
|
|
printHelp
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
|
2021-07-29 10:30:55 +01:00
|
|
|
*)
|
|
|
|
|
echo "ERROR: Unknown input parameter: $1=$2"
|
2021-09-06 16:17:11 +02:00
|
|
|
echo ""
|
|
|
|
|
printHelp
|
2021-07-29 10:30:55 +01:00
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
shift
|
|
|
|
|
done
|
|
|
|
|
|
2023-02-27 23:33:56 +01:00
|
|
|
# -----------------------------------------------
|
|
|
|
|
# Functions
|
|
|
|
|
# -----------------------------------------------
|
|
|
|
|
|
|
|
|
|
function startHal {
|
|
|
|
|
local ARGS=$1
|
|
|
|
|
local CLASSPATH="$(cd "${INSTALL_DIR}" && find . -name "*.jar" -type f -printf '%p:')"
|
|
|
|
|
CLASSPATH=${CLASSPATH::-1}
|
|
|
|
|
|
|
|
|
|
(set -x && cd "${INSTALL_DIR}" && java -classpath "${CLASSPATH}" se.hal.HalServer ${ARGS})
|
|
|
|
|
local EXIT_CODE=$?
|
|
|
|
|
|
|
|
|
|
return ${EXIT_CODE}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createSymLink {
|
|
|
|
|
local file=$1
|
|
|
|
|
|
|
|
|
|
if [[ -f "./${file}" ]]; then
|
|
|
|
|
echo "INFO: Creating symlink for: ${file}"
|
|
|
|
|
ln -s -f "$(realpath "./${file}")" "${INSTALL_DIR}/${file}"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-29 10:30:55 +01:00
|
|
|
# -----------------------------------------------
|
|
|
|
|
# Execute
|
|
|
|
|
# -----------------------------------------------
|
2023-02-27 23:33:56 +01:00
|
|
|
# Prepare execution
|
2021-07-29 10:30:55 +01:00
|
|
|
|
2021-09-06 16:17:11 +02:00
|
|
|
# gradle returns normally when doing ctr-c so we need to add a
|
|
|
|
|
# trap where the bash script exits instead of continuing.
|
|
|
|
|
trap 'exit 130' INT
|
|
|
|
|
|
2023-02-27 23:33:56 +01:00
|
|
|
INSTALL_DIR="."
|
|
|
|
|
|
|
|
|
|
if [[ -d "./hal-core/src" ]]; then
|
|
|
|
|
# We are operating on source code so build Hal
|
|
|
|
|
echo "INFO: Operating in source directory, will build Hal."
|
|
|
|
|
INSTALL_DIR="./build/install/Hal"
|
|
|
|
|
|
2023-05-16 01:43:16 +02:00
|
|
|
./gradlew ${GRADLE_COLOR} installDist
|
2023-02-27 23:33:56 +01:00
|
|
|
EXIT_CODE=$?
|
|
|
|
|
|
|
|
|
|
if [[ ${EXIT_CODE} -ne 0 ]]; then
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
createSymLink "hal.conf"
|
|
|
|
|
createSymLink "hal.db"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Execute
|
|
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
echo "INFO: Starting Hal in the ${MODE}."
|
2018-12-03 19:35:56 +01:00
|
|
|
|
2021-09-15 16:29:59 +02:00
|
|
|
if [[ ${MODE} == "FOREGROUND" ]]; then
|
2023-02-27 23:33:56 +01:00
|
|
|
EXIT_CODE=200
|
|
|
|
|
|
|
|
|
|
while [[ ${EXIT_CODE} -eq 200 ]]; do
|
|
|
|
|
# Restart as long as we have a exit code of 200, this allows the application to restart itself
|
2023-03-04 00:24:20 +01:00
|
|
|
#startHal
|
2023-09-28 22:14:13 +02:00
|
|
|
./gradlew ${GRADLE_COLOR} run
|
2023-02-27 23:33:56 +01:00
|
|
|
EXIT_CODE=$?
|
|
|
|
|
done
|
|
|
|
|
elif [[ ${MODE} == "BACKGROUND" ]]; then
|
2021-07-29 10:30:55 +01:00
|
|
|
# Kill current session
|
|
|
|
|
screen -S hal -X kill
|
|
|
|
|
# Start new session
|
2024-07-16 23:44:46 +02:00
|
|
|
screen -S hal -L -d -m $(dirname "$0")/run.sh --foreground --no-color
|
2021-07-29 10:30:55 +01:00
|
|
|
|
|
|
|
|
echo "-------------------------"
|
|
|
|
|
screen -list
|
2023-02-27 23:33:56 +01:00
|
|
|
else
|
|
|
|
|
echo "ERROR: Unknown mode: ${MODE}"
|
|
|
|
|
exit 1
|
2021-07-29 10:30:55 +01:00
|
|
|
fi
|