Re: [leaf-user] daemon vs. savelog ???

2002-07-10 Thread Michael D. Schleif


Jeff Newmiller wrote:
> 
> On Tue, 9 Jul 2002, Charles Steinkuehler wrote:

[ snip ]

> > > After savelog rotates the logfile, $DAEMON is writing to logfile.0,
> > > instead of logfile.  Obviously, this is not acceptable ;<
> > >
> > > I assume that this has something to do with the original redirected
> > > output keeping logfile open, even during the rename to logfile.0
> >
> > Correct...the file-handle used to log the daemon's output doesn't "go
> > bad" just because another process renamed the file.
> >
> > > is there a workaround?
> >
> > Yes...you have to get your process to close the log-file and re-open it
> > (so it starts writing to logfile, rather than logfile.0).  Since it
> > sounds like you're doing the logging at the shell level, you'll probably
> > just want to effectively do a "restart"...this can be handled using the
> > savelog scripts by providing a command to execute after rotating the
> > logs (ie: svi mydaemon restart).
> 
> or just split the output and write it line-by-line... if you don't mind
> the timestamping offered by syslogd, you can use something like
> 
>  # $DAEMON 2>&1 | streamlog
> 
> ---streamlog---
> #!/bin/sh
> # streamlog - splits a stream and logs each line of stdin with logger
> 
> IFS=''
> while read lin; do
>  logger -p local1.user "$lin"
> done
> ---

Yes, this is my preferred solution -- thank you.

Although, logger is not a good choice for this app, the message stream
is pretty lean and re-starting the app at log rotation was far more
distasteful

For those wondering, this is a cleanup and enhancement to my ntpclnt.lrp
that Charles wants to include in the next version of dcd.

-- 

Best Regards,

mds
mds resource
888.250.3987

Dare to fix things before they break . . .

Our capacity for understanding is inversely proportional to how much we
think we know.  The more I know, the more I know I don't know . . .


---
This sf.net email is sponsored by:ThinkGeek
Two, two, TWO treats in one.
http://thinkgeek.com/sf

leaf-user mailing list: [EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-user
SR FAQ: http://leaf-project.org/pub/doc/docmanager/docid_1891.html



Re: [leaf-user] daemon vs. savelog ???

2002-07-09 Thread Jeff Newmiller

On Tue, 9 Jul 2002, Charles Steinkuehler wrote:

> > This app spews data on STDOUT while running.  I want to run this app
> as
> > a daemon (continuously running in background) and I want to save the
> > stdout data to a logfile.  In fact, I am doing this now and everything
> > is OK:
> >
> > $DAEMON >>$LOG 2>&1 &
> >
> > Except, when _savelog_ rotates the logfile, the application writes to
> > the first archive, rather than the file with original logfile label:
> >
> > -rw-r- 1 root adm 0 Jul 9 05:07 logfile
> > -rw-r- 1 root adm 17943 Jul 9 14:17 logfile.0
> >
> > After savelog rotates the logfile, $DAEMON is writing to logfile.0,
> > instead of logfile.  Obviously, this is not acceptable ;<
> >
> > I assume that this has something to do with the original redirected
> > output keeping logfile open, even during the rename to logfile.0
> 
> Correct...the file-handle used to log the daemon's output doesn't "go
> bad" just because another process renamed the file.
> 
> > is there a workaround?
> 
> Yes...you have to get your process to close the log-file and re-open it
> (so it starts writing to logfile, rather than logfile.0).  Since it
> sounds like you're doing the logging at the shell level, you'll probably
> just want to effectively do a "restart"...this can be handled using the
> savelog scripts by providing a command to execute after rotating the
> logs (ie: svi mydaemon restart).

or just split the output and write it line-by-line... if you don't mind
the timestamping offered by syslogd, you can use something like

 # $DAEMON 2>&1 | streamlog

---streamlog---
#!/bin/sh
# streamlog - splits a stream and logs each line of stdin with logger

IFS=''
while read lin; do
 logger -p local1.user "$lin"
done
---

This is untested, so YMMV. :)

If you don't like logger, you can echo the line to the logfile yourself
with ">>".  The effect will be the same... the file will be opened and
closed for each line added.

---
Jeff NewmillerThe .   .  Go Live...
DCN:<[EMAIL PROTECTED]>Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...2k
---



---
This sf.net email is sponsored by:ThinkGeek
Stuff, things, and much much more.
http://thinkgeek.com/sf

leaf-user mailing list: [EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-user
SR FAQ: http://leaf-project.org/pub/doc/docmanager/docid_1891.html



Re: [leaf-user] daemon vs. savelog ???

2002-07-09 Thread Charles Steinkuehler

> This app spews data on STDOUT while running.  I want to run this app
as
> a daemon (continuously running in background) and I want to save the
> stdout data to a logfile.  In fact, I am doing this now and everything
> is OK:
>
> $DAEMON >>$LOG 2>&1 &
>
> Except, when _savelog_ rotates the logfile, the application writes to
> the first archive, rather than the file with original logfile label:
>
> -rw-r- 1 root adm 0 Jul 9 05:07 logfile
> -rw-r- 1 root adm 17943 Jul 9 14:17 logfile.0
>
> After savelog rotates the logfile, $DAEMON is writing to logfile.0,
> instead of logfile.  Obviously, this is not acceptable ;<
>
> I assume that this has something to do with the original redirected
> output keeping logfile open, even during the rename to logfile.0

Correct...the file-handle used to log the daemon's output doesn't "go
bad" just because another process renamed the file.

> is there a workaround?

Yes...you have to get your process to close the log-file and re-open it
(so it starts writing to logfile, rather than logfile.0).  Since it
sounds like you're doing the logging at the shell level, you'll probably
just want to effectively do a "restart"...this can be handled using the
savelog scripts by providing a command to execute after rotating the
logs (ie: svi mydaemon restart).

Charles Steinkuehler
http://lrp.steinkuehler.net
http://c0wz.steinkuehler.net (lrp.c0wz.com mirror)



---
This sf.net email is sponsored by:ThinkGeek
Stuff, things, and much much more.
http://thinkgeek.com/sf

leaf-user mailing list: [EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-user
SR FAQ: http://leaf-project.org/pub/doc/docmanager/docid_1891.html