boot, rc script and logs

Ian Smith smithi at nimnet.asn.au
Wed Dec 15 03:57:34 UTC 2010


In freebsd-questions Digest, Vol 341, Issue 3, Message: 17
On Tue, 14 Dec 2010 19:02:54 +0100 Samuel Mart?n Moro <faust64 at gmail.com> wrote:
 > Hi,
 > 
 > I'm adding some scripts to FreeBSD boot.
 > One of this script runs a binary that checks our postgres database, its
 > output being redirected to a dialog --gauge.
 > But I noticed that the dialog output, while correctly displayed on the
 > terminal, is also dumped into /var/log/console.log and /var/log/messages.
 > 
 > I'm not even sure about how this is happening... I can't find about messages
 > nor console.log in /etc/rc*

As you indicate below, 'tty is /dev/console' while running the boot rc 
scripts, so it's normal to see these scripts logged to console.log when 
that's ebabled .. presumably /etc/syslog.conf includes something like:
# uncomment this to log all writes to /dev/console to /var/log/console.log 
console.info			/var/log/console.log

 > Is there a way to disable log output in a given rc.script?
 > 
 > here's my script:
 >         #!/bin/sh
 > [...]
 >         test "$1" = 'start' -o "$1" = 'faststart' || exit 0
 >         Prg=`basename $_file`
 >         exec 2>/var/log/$Prg.log

You're redirecting stderr to your logfile, but not stdout, so standard 
output from the below goes to /dev/console, so also to /console.log

 >         test "$TERM" || export TERM=cons25
 >         DIALOG="/usr/local/bin/dialog --no-collapse --cr-wrap --colors"
 >         echo "tty is `tty`" >&2 #debug, prints: tty is /dev/console
 >         echo "===== Checking DB 1/2 =====" >&2

The above line is also written to stdout, so to console.log below, so 
I'm not sure whether your exec usage | syntax | redirection is correct.

 >         dbcheck -s | $DIALOG --gauge "\n  Checking DB 1/2" 7 70 2>/dev/null
 >         echo "===== Checking DB 2/2 =====" >&2
 >         dbcheck -r -s | $DIALOG --gauge "\n  Checking DB 2/2" 7 70 2>/dev/null
 > [...]
 > 
 > here is what it gives in /var/log/messages:
 > Dec 14 13:26:46 camtrace13 dhclient: New Subnet Mask (wlan0): 255.255.255.0
 > Dec 14 13:26:46 camtrace13 dhclient: New Broadcast Address (wlan0):
 > 192.168.0.255
 > Dec 14 13:26:46 camtrace13 dhclient: New Routers (wlan0): 192.33.160.111
 > Dec 14 13:26:47 camtrace13 kernel: m  ^[[36m^[[44m^[[K^[[16;6H^[[1K
 > ^[[30m^[[40m^[[70X^[[77`^[[36m^[[44m^[[K^[[13;9H^[[39;49m^[[m
 > Dec 14 13:26:48 camtrace13 kernel: m  ^[[36m^[[44m^[[K^[[16;6H^[[1K
 > ^[[30m^[[40m^[[70X^[[77`^[[36m^[[44m^[[K^[[13;9H^[[39;49m^[[m

I don't know why those two dialog lines are sent to /var/log/messages; 
perhaps they indicate some error, only those being logged with *.notice?

[..]

 > and here is what I can read in /var/log/console.log:
 > Dec 14 13:26:43 camtrace13 kernel: Starting apache.
 > Dec 14 13:26:46 camtrace13 kernel: Starting pgsql.

If you view these scripts you'll see that they don't themselves write to 
stdout .. it's the rc system logging these.

 > Dec 14 13:26:47 camtrace13 kernel: ^[[m
 > Dec 14 13:26:47 camtrace13 kernel: ^[[39;49m^[[=1S
 > Dec 14 13:26:47 camtrace13 kernel:
 > ^[[39;49m^[[m^[[H^[[J^[[17d^[[36m^[[44m^[[1m^[[J^[[H^[[K^[[B^[[K^[[B^[[K^[[B^[[K^[[B^[[K^[[B^[[K^[[B^[[K^[[B^[[K^[[B
 > ^[[37m^[[47mÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ^[[m^[[30m^[[47m¿^[[m^[[36m^[[44m^[[1m^[[K^[[B
 > ^[[37m^[[47m³^[[m^[[30m^[[47m^[[68X^[[74`³^[[m^[[30m^[[40m^[[1m
 > ^[[36m^[[44m^[[K^[[B    ^[[37m^[[47m³^[[m^[[30m^[[47m   Checking DB
 > 1/2^[[20X^[[74`³^[[m^[[30m^[[40m^[[1m  ^[[36m^[[44m^[[K^[[B
[..]
 > Dec 14 13:26:48 camtrace13 kernel: Starting slim.
 > Dec 14 13:26:48 camtrace13 kernel: Starting

You'll need to rework this somehow so dialog's stdout isn't written to 
/dev/console, though that may seem necessary if you want it coming up on 
the VTY0 boot screen.  It may involve decoupling this task from running 
'inline' as a boot script somehow, or else making sure that output is 
redirected to a log or temporary file instead of directly into dialog.

 > dhclient and oss seem to dump their output in /var/log/messages, while
 > apache, postgresql and slim dump their one in /var/log/console.log
 > So... How can my rc.script write in both console and messages logs?
 > And how can I get rid of that?

dhclient's (running) output is normally logged to messages, whereas the 
'Starting' messages are output of the rc process as it launches things.

And it's only those couple of lines to messages, the rest of them to 
console.log is unsurprising and expected if they're written to stdout.

HTH a bit, Ian


More information about the freebsd-questions mailing list