Best practice to tail a log and start it as service using rc.d scripts

Eugene Grosbein eugen at grosbein.net
Mon Jul 3 18:22:26 UTC 2017


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.



More information about the freebsd-ports mailing list