2

I would like to daemonize the answer in this topic https://serverfault.com/a/480871/94127. Since varnishlog has daemon mode, I tried to use -D option as below. But the timestamps are not appearing.

varnishlog  -I "Back healthy|Went sick" -w /var/log/varnish_health.log -D | awk '{ print strftime(), $0; fflush()}'
antimatter
  • 229
  • 1
  • 7
  • What is this supposed to do? I don't know varnishlog. Does -w make it read from that file or write to it? What does daemon mode mean? If the process detaches from the shell then it closes its /dev/stdout and thus the pipeline. awk never gets any input in that case. You need daemonize the whole pipeline by something like `nohup bash -c 'varnishlog ... | awk'` without daemonizing varnishlog itself, of course. – Hauke Laging Apr 14 '13 at 05:18
  • -w option writes to specified file and disables output to stdout, so your need to read from file with `tail -F`. – AlexD Apr 14 '13 at 05:46
  • daemon = run in background. I will try the command you suggested. @AlexD, awk is adding in the timestamp to the varnishlog. If I use tail -F, I will lose correct time? – antimatter Apr 14 '13 at 06:11
  • @antimatter, in your case awk isn't adding anything to varnishlog as it doesn't receive anything on stdin because -w redirects output to file instead of stdout. `tail -F` flushes its output after each line so it shouldn't affect timestamps much but `varnishlog` itself can buffer its output to file. – AlexD Apr 14 '13 at 06:58

1 Answers1

1

This may work for you:

{ varnishlog -I "Back healthy|Went sick" | awk '{ print strftime(), $0; fflush()}' >> /var/log/varnish_health.log; } & disown
Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
  • Thanks. That works. Here's my exact code for the record.Added unbuffer so that varnishlog will not buffer it. `{ unbuffer varnishlog -i Backend_health -I "Back healthy|Went sick" | awk '{ print strftime(), $0; fflush()}' >> /var/log/varnish_health.log; } & disown` – antimatter Apr 21 '13 at 02:38