Home > Software engineering >  Ending tail on SIGTERM inside background subshell
Ending tail on SIGTERM inside background subshell

Time:06-05

In my script I am starting multiple background processes and one of them is

(
  tail -qF -n 0 logs/nginx/*.log
) &
processes[logs]=$!

for process in "${!processes[@]}"; do
  wait "${processes[$process]}"
done

When sending SIGTERM signal all processes ends only tail is left running. After some testing I came up to the solution to send tail to background and its working.

(
  tail -qF -n 0 logs/nginx/*.log &
) &
processes[logs]=$!

for process in "${!processes[@]}"; do
  wait "${processes[$process]}"
done

Can someone explain to me what is happening when I send tail to background in subshell so it ends when SIGTERM arrives?

CodePudding user response:

My tail was not killed in example I provided, it was only sent to background and that allowed script to exit.

I have attached tail to my server, so after my server dies tail also dies. Now it behaves how I want.

tail -qF -n 0 --pid=${process_list[server]} logs/nginx/*.log
  • Related