• Re: daemon program?

    From Chris Elvidge@chris@internal.net to uk.comp.os.linux,alt.os.linux.ubuntu on Thu Sep 11 13:46:35 2025
    From Newsgroup: uk.comp.os.linux

    On 10/09/2025 at 20:32, Lawrence DrCOOliveiro wrote:
    On Wed, 10 Sep 2025 12:04:48 +0100, Chris Elvidge wrote:

    On 10/09/2025 at 09:27, Lawrence DrCOOliveiro wrote:

    On Wed, 10 Sep 2025 09:01:15 +0100, Mike Scott wrote:

    But the linux version seems to just keep writing to the same file
    whatever I try.

    ArenrCOt you supposed to do logging through syslog?

    ITYF systemd doesn't use syslog - see journalctl.

    systemd myth number 20: systemd makes it impossible to run syslog <https://0pointer.de/blog/projects/the-biggest-myths.html>.


    I didn't say it couldn't, just that it didn't.
    --
    Chris Elvidge, England
    ALL WORK AND NO PLAY MAKES BART A DULL BOY
    Bart Simpson on chalkboard in episode 1F07

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Chris Elvidge@chris@internal.net to uk.comp.os.linux,alt.os.linux.ubuntu on Thu Sep 11 13:53:09 2025
    From Newsgroup: uk.comp.os.linux

    On 11/09/2025 at 11:02, Mike Scott wrote:
    On 11/09/2025 08:49, Richard Kettlewell wrote:
    Mike Scott <usenet.16@scottsonline.org.uk.invalid> writes:
    On 10/09/2025 09:42, Dan Purgert wrote:
    On 2025-09-10, Mike Scott wrote:
    On 04/09/2025 08:26, Richard Kettlewell wrote:
    Mike Scott<usenet.16@sc
    ottsonline.org.uk.invalid> writes:
    I've been using a program 'daemon' on freebsd
    (eg
    man.freebsd.org/cgi/man.cgi?query=daemon&sektion=8&manpath=FreeBSD+14.3-RELEASE+and+Ports)


    which will run arbitrary programs as daemons, handling all the
    necessary "house-keeping" for them.

    I can't find a ready-to-roll linux version - is there one please? >>>>>> If you want an (almost) identical interface then in Debian (and
    presumably therefore also Ubuntu), thererCOs a command of the same name >>>>>> and similar behavior:

    https://manpages.debian.org/trixie/daemon/daemon.1.en.html

    Sorry, back again.

    I've been playing with this and there seems to be an important feature >>>>> missing on linux that's in the BSD version: how to do logfile
    rotation?
    [...]
    Have I missed something?
    logrotate(8) ?

    Thanks for the reply, but no. That assumes the existence of the
    mechanism missing AFAICS from this daemon.

    And to answer ldo, this is for a web daemon that writes its own
    private log file that needs archival copies kept; syslog is not
    appropriate. I've been doing that using mv and sending the BSD daemon
    a sighup; migration is being something of a chore.

    Looks like I'll have to see about patching the daemon source code.

    IrCOm not quite clear on the requirement here. I think what you mean is:

    * The daemon executable logs to stdout and/or stderr
    * You want these logs saved to a file
    * You want this file rotated (in the normal way for a logfile)
    * You want to keep the data essentially indefinitely, or at least, for
    longer than other syslog outputs.

    I can see several options.

    1) Change the daemon to log to the target file instead of stdout/stderr,
    and either arrange for it to close and re-open the logfile when it
    recieves SIGHUP, or just do the log rotate itself (which avoids
    dealing with signal handlers).

    2) Add a second program that reads from stdin and writes to the target
    logfile, doing the log rotation itself. The daemon command line would
    be a pipeline, e.g. daemon sh -c "executable 2>&1 | loghandler".

    3) Log to syslog, either directly or via the daemon wrapper. syslog
    daemons (e.g. rsyslogd) can select a specific programrCOs logs to an
    individual file, and you can control the log rotation policy for that
    file individually. The syslog daemon takes care of the close/re-open
    dance.


    The problem is fixed to my satisfaction, but to answer your query.

    The target program runs unattended for extended periods. It writes a lot
    of data to stdout and stderr. It is not of itself a daemon in the linux sense, just a large chunk of perl code that normally runs at a terminal.
    To make it a self-contained linux daemon would be a pain, and pointless duplication of code. At user-determined intervals, I need output to be directed to a fresh file.

    On freebsd, I've been using a program called 'daemon'. This runs the
    target program as a child process, intercepting its stdout and stderr
    and writing their data to a suitable file; it also does the necessary detaching and other housekeeping operations on its behalf. Importantly, 'daemon' responds to a suitable signal by closing and reopening its
    output. This provides a way of chopping up the target program's output streams into files for archiving and further processing without stopping
    it.

    The linux program of the same name does much the same - but lacks the ability to close and reopen its output files. 'logrotate' can sort-of
    work around this with a (small) risk of data loss for programs like
    mine, that cannot handle rotation hygienically.

    I've now modified the linux 'daemon' program to respond as the freebsd
    one, and it can now close and reopen its output file(s) without risk of
    data loss. So archiving now becomes a simple matter of "mv log.txt
    log.old; kill -usr2 <daemon-pid>" which results in log.old with the data
    to date, and a fresh log.txt being opened.

    I've emailed the author to see if he's interested in rolling the modification into the next release.

    And yes, I suppose your suggestion #2 would have worked. But involving a
    3rd program is messy, and I'd still be having cut code to tell it to do
    the log rotation on request. Better to put that where it really belongs,
    I think. But thanks for the idea.




    Have you seen 'daemonize' - seems to do what you want.
    --
    Chris Elvidge, England
    ALL WORK AND NO PLAY MAKES BART A DULL BOY
    Bart Simpson on chalkboard in episode 1F07

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Richard Kettlewell@invalid@invalid.invalid to uk.comp.os.linux,alt.os.linux.ubuntu on Thu Sep 11 18:48:51 2025
    From Newsgroup: uk.comp.os.linux

    Chris Elvidge <chris@internal.net> writes:
    Lawrence DrCOOliveiro wrote:
    On Wed, 10 Sep 2025 12:04:48 +0100, Chris Elvidge wrote:
    On 10/09/2025 at 09:27, Lawrence DrCOOliveiro wrote:
    On Wed, 10 Sep 2025 09:01:15 +0100, Mike Scott wrote:

    But the linux version seems to just keep writing to the same file
    whatever I try.

    ArenrCOt you supposed to do logging through syslog?

    ITYF systemd doesn't use syslog - see journalctl.
    systemd myth number 20: systemd makes it impossible to run syslog
    <https://0pointer.de/blog/projects/the-biggest-myths.html>.

    I didn't say it couldn't, just that it didn't.

    In the context of a question about rCLlogging through syslogrCY, it _does_
    use syslog. journald listens on /dev/log and the syslog(3) API works.
    --
    https://www.greenend.org.uk/rjk/
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to uk.comp.os.linux,alt.os.linux.ubuntu on Thu Sep 11 22:17:21 2025
    From Newsgroup: uk.comp.os.linux

    On Thu, 11 Sep 2025 11:02:30 +0100, Mike Scott wrote:

    The target program runs unattended for extended periods. It writes a
    lot of data to stdout and stderr. It is not of itself a daemon in
    the linux sense, just a large chunk of perl code that normally runs
    at a terminal. To make it a self-contained linux daemon would be a
    pain, and pointless duplication of code.

    It shouldnrCOt take much work to make it runnable as a daemon. Remember,
    the distinction in *nix isnrCOt that great, anyway: look at common
    existing service daemons, and you will see that lots of them will run
    fine in non-daemon mode, specifically to ease debugging.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Mike Scott@usenet.16@scottsonline.org.uk.invalid to uk.comp.os.linux,alt.os.linux.ubuntu on Fri Sep 12 16:19:59 2025
    From Newsgroup: uk.comp.os.linux

    On 11/09/2025 13:53, Chris Elvidge wrote:
    Have you seen 'daemonize' - seems to do what you want.

    I can't see anything in the man page for that, or its website, that
    suggests it can close and reopen log files. It seems very similar to
    'daemon'. But thanks for commenting.
    --
    Mike Scott
    Harlow, England
    --- Synchronet 3.21a-Linux NewsLink 1.2