From owner-freebsd-ports@freebsd.org Mon Jul 3 18:22:25 2017 Return-Path: Delivered-To: freebsd-ports@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E05709ECB13 for ; Mon, 3 Jul 2017 18:22:25 +0000 (UTC) (envelope-from eugen@grosbein.net) Received: from hz.grosbein.net (hz.grosbein.net [78.47.246.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "hz.grosbein.net", Issuer "hz.grosbein.net" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 7C1947AFA1 for ; Mon, 3 Jul 2017 18:22:24 +0000 (UTC) (envelope-from eugen@grosbein.net) Received: from eg.sd.rdtc.ru (root@eg.sd.rdtc.ru [62.231.161.221]) by hz.grosbein.net (8.15.2/8.15.2) with ESMTPS id v63IM7mU031863 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 3 Jul 2017 20:22:08 +0200 (CEST) (envelope-from eugen@grosbein.net) X-Envelope-From: eugen@grosbein.net X-Envelope-To: idefix@fechner.net Received: from [10.58.0.4] ([10.58.0.4]) by eg.sd.rdtc.ru (8.15.2/8.15.2) with ESMTPS id v63IM3x2043627 (version=TLSv1.2 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Tue, 4 Jul 2017 01:22:03 +0700 (+07) (envelope-from eugen@grosbein.net) Subject: Re: Best practice to tail a log and start it as service using rc.d scripts To: Matthias Fechner , FreeBSD Mailing List References: <62c231e8-74b0-8515-eb22-4e4edf6ff5e2@fechner.net> From: Eugene Grosbein Message-ID: <595A8B47.2060705@grosbein.net> Date: Tue, 4 Jul 2017 01:21:59 +0700 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <62c231e8-74b0-8515-eb22-4e4edf6ff5e2@fechner.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_00,LOCAL_FROM autolearn=no autolearn_force=no version=3.4.1 X-Spam-Report: * -2.3 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 2.6 LOCAL_FROM From my domains X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on hz.grosbein.net X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Jul 2017 18:22:26 -0000 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.