Home
The Toolkit for Online Communities
17133 Community Members, 0 members online, 1849 visitors today
Log In Register
OpenACS Home : Forums : OpenACS Q&A : Rolling logs

Forum OpenACS Q&A: Rolling logs

Icon of envelope Request notifications

Collapse
Posted by Andrei Popov on

This is probably a very lame question, but: how do I get AOLServer to roll all its logs? I have the following setup in nsd.tcl:

[snip]

ns_section ns/parameters
        ns_param serverlog      /var/log/aolserver/${server}.log
        ns_param home           ${homedir}
        ns_param maxkeepalive   0
        ns_param maxbackup      5
        ns_param debug          ${debug}
        ns_param rolllog        true
        ns_param logroll        true
        ns_param rollfmt        %Y%m%d
        ns_param rollday        *
        ns_param rollhour       3
        ns_param rollonsignal   true
        
[snip]

ns_section ns/server/${server}/module/nslog
        ns_param file           ${homedir}/log/${server}.log
        ns_param enablehostnamelookup   false
        ns_param logcombined    true
        ns_param logrefer       false
        ns_param loguseragent   false
        ns_param maxbackup      5
        ns_param rollday        *
        ns_param rollfmt        %Y-%m-%d-%H:%M
        ns_param rollhour       0
        ns_param rollonsignal   true
        ns_param rolllog        true
[snip]

Now, the "server" section works and rolls the logs every day at 2400hrs. The global section does not work and log grows and grows and grows...

Also, is there a way to tell AOLServer to compress logs?

Finally, can it be made to work with syslog/newsyslog? Last time I tried something like this:

#logfilename [owner:group] mode count size when [ZJB] [/pid_file]
[sig_num]
/var/log/aolserver/openacs-dev-error.log  nsadmin:www  640  5  100  *  Z
in my /etc/newsyslog.conf, log rolled every day, like a clock, but had no data in it except for "Log rolled" entry. I understand that I need to signal AOLServer that log was rolled, but how? Same story is with PostgreSQL, btw.

Collapse
2: Response to Rolling logs (response to 1)
Posted by Don Baccus on
You have to do kick AOLserver with a kill -HUP to get it to roll its log, and it will ignore formating and similar information in the start up file. That only works for the access log, not the server error log. It's easy enough to issue the HUP from a daily cronjob ...

Here's a perl script you can try:

#!/usr/bin/perl

## Sends AOLserver an HUP signal, so it will roll it's logs. Takes as its
## only argument the name of the server to roll.

## modified from the version in ACS 4

$ENV{'PATH'} = '/sbin:/bin';

if (scalar(@ARGV) == 0) {
    die "Don't run this without any arguments!
";
}

my $server = shift;
# untaint this variable to make suidperl happy
$server =~ /^([w-]*)$/;
my $servername = $1;

## get the PIDs of all matching servers
open(PID, "/bin/ps -efwww |") || die $!;
my @pids;
while () {
  next unless /^s*S+s+(d+).*nsd.*/$servername.tcl/;
  my $pid = $1;
  push(@pids, $pid);
}
close PID;

print "Rolling ", join(" ", @pids), "
";
kill 'HUP', @pids;
Collapse
3: Response to Rolling logs (response to 1)
Posted by Jonathan Ellis on
This can be about as comlicated as you want to make it :) You can do a perl script. You can do a simpler proc:
proc util_logroll {} {
    exec kill -HUP [ns_info pid]
}

ns_schedule_daily 0 0 util_logroll
but the easiest way is to use the builtin ns_logroll. :) incidently, according to the docs the only parameters affecting the "global" log are
LogMaxBackup 

10 

The maximum number of server log backup files. 

LogRoll 

on 

Boolean value. If set to on, the server log file will be rolled on a SIGHUP.
pretty simplistic I'm afraid.
Collapse
4: Response to Rolling logs (response to 1)
Posted by Andrei Popov on

Don, Jonathan, thanks.

I think I finally figured how to do it. FWIW, here's what I do (caveat: this is on FreeBSD, applicability to other systems may vary):

  1. In nsd.tcl relevent section looks as follows:

    ns_section ns/parameters
            ns_param serverlog      /var/log/aolserver/${server}.log
            ns_param pidfile        ${homedir}/log/nspid.${server}
            ns_param home           ${homedir}
            ns_param maxkeepalive   0
            ns_param maxbackup      5
            ns_param debug          ${debug}
            ns_param logroll        true
    

  2. I then add the following line to /etc/newsyslog.conf:
    #logfilename [owner:group] mode count size when [ZJB] [/pid_file] [sig_num]
    /var/log/aolserver/openacs-dev.log nsadmin:www 640 5 100 * B 
    /usr/local/aolserver/log/nspid.openacs-dev 1
    

Now, AOLServer stores PID in nspid.$server file that is accessible by syslog, that is used to send signal 1 (SIGHUP) to the process with that ID.

Collapse
5: Response to Rolling logs (response to 1)
Posted by Andrew Piskorski on
This question has definitely been addressed before. :) That thread has both the Bourne shell script that I (still) use, and ns_logroll, which is probably the best way.
Collapse
6: Response to Rolling logs (response to 1)
Posted by Andrew Piskorski on
Oh, and Andrei, regarding your question about making AOLserver logs work with syslog, you should take a look at Rob Mayoff's dqd_log module. It, "allows AOLserver to send access log entries directly to an external program." Perhaps it will (or can be made to) work with the server (error) log as well.
Collapse
7: Response to Rolling logs (response to 1)
Posted by Andrei Popov on
Actually, what is I've outlined above works perfectly (at least on FreeBSD).  No need for anything additional -- bash or Tcl scripts -- just the standard tools.  Logs are nicely rolled and zipped whenever they reach specified size.