1
0
Fork 0
mirror of https://github.com/overleaf/toolkit.git synced 2025-04-19 15:28:06 +02:00
overleaf-toolkit/bin/logs
2020-06-12 10:53:38 +01:00

71 lines
1.7 KiB
Bash
Executable file

#! /usr/bin/env bash
set -euo pipefail
DEFAULT_LINES=20
function usage() {
echo "Usage: bin/logs [OPTIONS] [SERVICES...]"
echo ""
echo "Services: chat, clsi, contacts, docstore, document-updater,"
echo " filestore, notifications, real-time, spelling,"
echo " tags, track-changes, web"
echo ""
echo "Options:"
echo " -f follow log output"
echo " -n {number} number of lines to print (default $DEFAULT_LINES)"
echo ""
echo "Examples:"
echo ""
echo " bin/logs -n 50 web clsi"
echo ""
echo " bin/logs -f web"
echo ""
echo " bin/logs -f web chat docstore"
echo ""
echo " bin/logs -n 100 -f filestore "
echo ""
echo " bin/logs -f"
}
function __main__() {
LINES="$DEFAULT_LINES"
FOLLOW_FLAG=""
while getopts "fn:" opt
do
case $opt in
f ) FOLLOW_FLAG="-f" ;;
n ) LINES="${OPTARG}" ;;
\?) usage && exit ;;
esac
done
shift $(( OPTIND -1 ))
if [[ "${1:-null}" == "null" ]] \
|| [[ "${1:-null}" == "help" ]] \
|| [[ "${1:-null}" == "--help" ]] ; then
usage && exit
fi
log_base_path="/var/log/sharelatex"
declare -a services
IFS=" " read -r -a services <<< "$*"
path_spec="$log_base_path/*.log"
if [[ ! "0" == "${#services[@]}" ]]; then
log_paths=()
for service in "${services[@]}"; do
log_paths+=("$log_base_path/${service}.log")
done
path_spec="${log_paths[*]}"
fi
bash_exec_command_string="tail $FOLLOW_FLAG -n $LINES $path_spec"
exec ./bin/docker-compose exec sharelatex bash -c "$bash_exec_command_string"
}
__main__ "$@"