Added hal.service file for systemd and updated the run script to support forground execution

This commit is contained in:
Ziver Koc 2021-07-29 10:30:55 +01:00
parent 5e3b103815
commit e57d62471b
2 changed files with 69 additions and 7 deletions

16
hal.service Normal file
View file

@ -0,0 +1,16 @@
# This is a SystemD configuration for the Hal Server.
#
# To activate the service run:
# - sudo cp hal.service /lib/systemd/system/
# - sudo systemctl enable hal.service
#
[Unit]
Description=Hal Server
[Service]
Type=idle
ExecStart=/home/pi/repo/hal/run.sh --forground
[Install]
WantedBy=multi-user.target

60
run.sh
View file

@ -1,12 +1,58 @@
#!/bin/bash
#ant clean
# -----------------------------------------------
# User input
# -----------------------------------------------
function printHelp() {
echo "Run code analysis through SonarQube.
Usage:
$(basename $0)
[-f|--foreground]
[-h|--help]
Where:
--foreground Run Hal Server in the foreground instead of detatching a new screen.
--help Print this help message.
"
}
MODE="SCREEN"
until [[ $# -eq 0 ]]; do
case "$1" in
-f|--forground)
MODE="FORGROUND"
shift
;;
*)
echo "ERROR: Unknown input parameter: $1=$2"
exit 1
;;
esac
shift
done
# -----------------------------------------------
# Execute
# -----------------------------------------------
# Build Hal source
./gradlew build
# Kill current session
screen -S hal -X kill
# Start new session
screen -S hal -L -d -m ./gradlew run
if [[ ${MODE} == "FORGROUND" ]]; then
./gradlew run
else
# Kill current session
screen -S hal -X kill
# Start new session
screen -S hal -L -d -m ./gradlew run
echo "-------------------------"
screen -list
fi
echo "-----------------"
screen -list