I am using nomad-autoscaler image to run a pod that emits the logs on standard out, I want to send these logs into a file (within the pod) to enable a liveness check based on logfile content.
Used below dockerfile -
FROM hashicorp/nomad-autoscaler:0.3.5
USER 0
RUN touch /var/log/nomad-autoscaler.log \
&& ln -sf /proc/$$/fd/1 /var/log/nomad-autoscaler.log
but there is nothing in the log file when tailing the file.
I've followed the solutions -
- Added an entrypoint.sh file which redirects the output with
tee
# entrypoint.sh
set -e
"$@" | tee -a "/log/nomad-autoscaler-logs.log"
This creates the file but not adding the logs to that, it is always 0 size, I can see the below processes in the container
/ $ ps
PID USER TIME COMMAND
1 nomad-au 0:00 sh /log/script/entrypoint.sh nomad-autoscaler agent -config /etc/nomad-autoscaler/conf/shared -config /etc/nomad-autoscaler/conf/secret
7 nomad-au 2:37 nomad-autoscaler agent -config /etc/nomad-autoscaler/conf/shared -config /etc/nomad-autoscaler/conf/secret
8 nomad-au 0:00 tee -a /log/nomad-autoscaler-logs.log
- But when I redirect the output, I can see the logs in file but not it is not populated on standard output.
# entrypoint.sh
set -e
"$@" &> "/log/nomad-autoscaler-logs.log"
Additional info about log redirection configured within the container -
/ $ ls -l /dev/stdout /dev/stderr /proc/self/fd/2 /proc/self/fd/1
lrwxrwxrwx 1 root root 15 Jan 3 18:44 /dev/stderr -> /proc/self/fd/2
lrwxrwxrwx 1 root root 15 Jan 3 18:44 /dev/stdout -> /proc/self/fd/1
lrwx------ 1 nomad-au nomad-au 64 Jan 4 19:37 /proc/self/fd/1 -> /dev/pts/2
lrwx------ 1 nomad-au nomad-au 64 Jan 4 19:37 /proc/self/fd/2 -> /dev/pts/2
Any suggestions will be a great help.