Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Docker log tailing #1066

Merged
merged 7 commits into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions docker/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#!/bin/bash

tail_file() {
echo "tailing file $1"
ALIGN=27
LENGTH=`echo $1 | wc -c`
PADDING=`expr ${ALIGN} - ${LENGTH}`
PREFIX=$1`perl -e "print ' ' x $PADDING;"`
file="/var/log/$1"
# each tail runs in the background but prints to stdout
# sed outputs each line from tail prepended with the filename+padding
tail -qF $file | sed --unbuffered "s|^|${PREFIX}:|g" &
}

echo_status() {
local args="${@}"
tput setaf 4
Expand Down Expand Up @@ -101,12 +113,26 @@ if [[ $test = false ]]; then
echo_status "Starting supervisor"

# Start Supervisor
/usr/bin/supervisord $([[ $no_daemon = true ]] && printf %s "-n")
/usr/bin/supervisord

echo_status "Done!"

# Watch Logs
echo_status "Watching logs"
tail -qF /var/log/supervisor/* /var/log/nginx/* /var/log/tethys/*
echo_status "Watching logs. You can ignore errors from either apache (httpd) or nginx depending on which one you are using."

log_files=("httpd/access_log"
"httpd/error_log"
"nginx/access.log"
"nginx/error.log"
"supervisor/supervisord.log"
"tethys/tethys.log")

# When this exits, exit all background tail processes
trap 'kill $(jobs -p)' EXIT
for log_file in "${log_files[@]}"; do
tail_file "${log_file}"
done

# Read output from tail; wait for kill or stop command (docker waits here)
wait
fi