1

I'm preparing a script for Docker, which allows only one top-level process, which should receive the signals so we can stop it.

Therefore, I'm having a script like this: one application writes to syslog (bash script in this sample), and the other one just prints it.

#! /usr/bin/env bash
set -eu

tail -f /var/log/syslog &

exec bash -c 'while true ; do logger aaaaaaaaaaaaaaaaaaa ; sleep 1 ; done'

Almost solved: when the top-level process bash gets SIGTERM -- it exists, but tail -f continues to run.

How do I instruct tail -f to exit when the parent process exits? E.g. it should also get the signal.

Note: Can't use bash traps since exec on the last line replaces the process completely.

10
  • Isn't this what things like supervisord are supposed to handle? May 28, 2014 at 19:08
  • @MichaelHampton, you're right, but in this case I really need to print something out. Supervisor is not good at printing :)
    – kolypto
    May 28, 2014 at 19:10
  • I read your other question too. You really should describe what's actually going on, and name the applications you're working with. May 28, 2014 at 19:10
  • Could you try tail -f --pid="$$" filename?
    – kupson
    May 28, 2014 at 19:17
  • @MichaelHampton, okay, let's say that's Apache. It can only log to files or syslog, and not to stdout. I need to have logging to stdout :)
    – kolypto
    May 28, 2014 at 19:17

1 Answer 1

1

If you are lucky^Wusing tail command from GNU coreutils you can use --pid=<number> option. The capital -F option would make you safe against log rotation.

tail --pid="$$" -F /var/log/syslog &

More info: http://www.gnu.org/software/coreutils/manual/html_node/tail-invocation.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.