fix: add log, set handler for SIGINT
parent
c47158ee88
commit
c3cfd99f17
|
@ -5,7 +5,7 @@ set -e
|
|||
### ###
|
||||
# #
|
||||
# V Rising on-the-fly shell #
|
||||
# v0.1 #
|
||||
# v0.2 #
|
||||
### ###
|
||||
|
||||
stdout() {
|
||||
|
@ -16,14 +16,33 @@ stderr() {
|
|||
>&2 echo "${1}"
|
||||
}
|
||||
|
||||
log() {
|
||||
local action="${1}"
|
||||
local when=""
|
||||
when="$(date +%R:%S)"
|
||||
|
||||
echo "${when} - ${action}" >> "${THIS_LOG}" 2>&1 /dev/null
|
||||
}
|
||||
|
||||
editWithRestart() {
|
||||
local full_path_file_to_edit="${1}"
|
||||
nano "${full_path_file_to_edit}"
|
||||
log "File edit - ${full_path_file_to_edit}"
|
||||
stdout "The server will now be restarted and you will be attached to the logs."
|
||||
stdout "Use ctrl-c to detach from the logs (the service will continue to run in background)"
|
||||
log "Server restart"
|
||||
(cd "${VRISING_COMPOSE_HOME}" && docker-compose restart && docker-compose logs -f)
|
||||
}
|
||||
|
||||
ctrl_c_handler() {
|
||||
# shellcheck disable=SC2317
|
||||
log "Logout with ctrl-c"
|
||||
# shellcheck disable=SC2317
|
||||
exit 0
|
||||
}
|
||||
|
||||
trap 'ctrl_c_handler' INT
|
||||
|
||||
USERNAME="${1}"
|
||||
|
||||
shift
|
||||
|
@ -33,13 +52,12 @@ GAME_SETTINGS="ServerGameSettings.json"
|
|||
HOST_SETTINGS="ServerHostSettings.json"
|
||||
VRISING_COMPOSE_HOME="/home/davide/services/vrising/"
|
||||
LOGS_FOLDER="${HOME}/logs"
|
||||
THIS_LOG="${USERNAME}-$(date --iso-8601=ns).log"
|
||||
|
||||
mkdir -p "${LOGS_FOLDER}" || (stderr "Unable to create logs folder, exiting" && exit 1)
|
||||
|
||||
stdout "Welcome ${USERNAME}, please remember that your current activity in the server is logged!"
|
||||
|
||||
trap "" INT
|
||||
|
||||
while true
|
||||
do
|
||||
stdout """
|
||||
|
@ -57,6 +75,7 @@ Select one of the following actions:
|
|||
|
||||
case "${ACTION}" in
|
||||
0)
|
||||
log "Exit"
|
||||
exit 0
|
||||
;;
|
||||
1)
|
||||
|
@ -67,18 +86,22 @@ Select one of the following actions:
|
|||
;;
|
||||
3)
|
||||
stdout "Use ctrl-c to detach from the logs at any time"
|
||||
log "Show logs"
|
||||
(cd "${VRISING_COMPOSE_HOME}" && docker-compose logs -f)
|
||||
;;
|
||||
4)
|
||||
stdout "Use ctrl-c to detach from the logs at any time"
|
||||
log "Server restart"
|
||||
(cd "${VRISING_COMPOSE_HOME}" && docker-compose restart && docker-compose logs -f)
|
||||
;;
|
||||
5)
|
||||
stdout "Use ctrl-c to detach from the logs at any time"
|
||||
log "Recreate server"
|
||||
(cd "${VRISING_COMPOSE_HOME}" && docker-compose down -v && sleep 1 && docker-compose up -d && docker-compose logs -f)
|
||||
;;
|
||||
*)
|
||||
stderr "The provided input is not valid. Please chose from the listed actions"
|
||||
log "Invalid input: ${ACTION}"
|
||||
stderr "The provided input is not valid. Please chose a valid action"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue