Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Jul 2017 01:21:59 +0700
From:      Eugene Grosbein <eugen@grosbein.net>
To:        Matthias Fechner <idefix@fechner.net>, FreeBSD Mailing List <freebsd-ports@freebsd.org>
Subject:   Re: Best practice to tail a log and start it as service using rc.d scripts
Message-ID:  <595A8B47.2060705@grosbein.net>
In-Reply-To: <62c231e8-74b0-8515-eb22-4e4edf6ff5e2@fechner.net>
References:  <62c231e8-74b0-8515-eb22-4e4edf6ff5e2@fechner.net>

next in thread | previous in thread | raw e-mail | index | archive | help
03.07.2017 23:20, Matthias Fechner пишет:
> Dear all,
> 
> I just in the process to test mailtrain (https://mailtrain.org/) and if
> it is working I would like to create a port for FreeBSD.
> 
> That mailtrain can handle bounce message with postfix together it is
> necessary to tail the postfix log and pass it to mailtrain, using a
> command like this:
> tail -F -n +0 /var/log/maillog | nc localhost 5699 -
> 
> Is there a best practice approach on how to do this on FreeBSD?
> I would require now a startup script in /usr/local/etc/rc.d to start
> this kind of tail or is there a better mechanism in FreeBSD available?
> If not, does anyone have some kind of template/example on how to start a
> program like tail as daemon so FreeBSD can stop/restart it with the
> service command?

For logs written using standard syslog service, there is much effective way.

1. The syslogd daemon can run a subprocess and duplicate log stream to its
standard input. For example, write to its config:

mail.*	"|exec nc localhost 5699 -"

See man syslog.conf for details. You can even pipe not full log
but some part of it, f.e. `mail.notice' instead of `mail.*'
for important event only (no debug lines, no informational mesages).

2. And you need not modify system /etc/syslog.conf but create file
named like /usr/local/etc/syslog.d/mailtrain.conf with that single line.
Then use `service syslogd reload' to apply additional configuration
and syslogd will run your "addon" when corresponding logs is updated.

For deinstallation/deactivation procedure just remone mailtrain.conf
and use `service syslogd reload' again.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?595A8B47.2060705>