mirror of
https://github.com/overleaf/toolkit.git
synced 2025-04-19 15:28:06 +02:00
84 lines
2.3 KiB
Bash
Executable file
84 lines
2.3 KiB
Bash
Executable file
#! /usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
#### Detect Toolkit Project Root ####
|
|
# if realpath is not available, create a semi-equivalent function
|
|
command -v realpath >/dev/null 2>&1 || realpath() {
|
|
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
|
|
}
|
|
SCRIPT_PATH="$(realpath "${BASH_SOURCE[0]}")"
|
|
SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"
|
|
TOOLKIT_ROOT="$(realpath "$SCRIPT_DIR/..")"
|
|
if [[ ! -d "$TOOLKIT_ROOT/bin" ]] || [[ ! -d "$TOOLKIT_ROOT/config" ]]; then
|
|
echo "ERROR: could not find root of overleaf-toolkit project (inferred project root as '$TOOLKIT_ROOT')"
|
|
exit 1
|
|
fi
|
|
|
|
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__() {
|
|
local LINES="$DEFAULT_LINES"
|
|
local 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
|
|
|
|
local log_base_path="/var/log/sharelatex"
|
|
|
|
declare -a services
|
|
IFS=" " read -r -a services <<< "$*"
|
|
|
|
local path_spec="$log_base_path/*.log"
|
|
|
|
if [[ ! "0" == "${#services[@]}" ]]; then
|
|
local log_paths=()
|
|
for service in "${services[@]}"; do
|
|
log_paths+=("$log_base_path/${service}.log")
|
|
done
|
|
path_spec="${log_paths[*]}"
|
|
fi
|
|
|
|
local bash_exec_command_string="tail $FOLLOW_FLAG -n $LINES $path_spec"
|
|
|
|
exec "$TOOLKIT_ROOT/bin/docker-compose" exec sharelatex bash -c "$bash_exec_command_string"
|
|
}
|
|
|
|
__main__ "$@"
|