head	1.1;
access;
symbols
	TIGRIS_1_1_0RC2:1.1.2.1
	TIGRIS_1_1:1.1.0.2;
locks; strict;
comment	@# @;


1.1
date	2001.08.14.23.21.21;	author ms;	state Exp;
branches
	1.1.2.1;
next	;

1.1.2.1
date	2001.08.15.00.04.38;	author ms;	state Exp;
branches;
next	;


desc
@@


1.1
log
@script from cron, moved to helm/scripts under new name rotate_eb_mbox.pl
@
text
@#!/usr/bin/perl -w

use Fcntl;

my $sandbox = shift;
die "Error starting rotation script, required parameter $sandbox not given\n" unless (defined $sandbox);
my $eyebrowseWrapper = "$sandbox/site/scripts/eyebrowse";

my $props = "--props=$sandbox/conf/eyebrowse/eyebrowse.properties";
my @@lists=`$eyebrowseWrapper --command=getlists $props`; 
foreach $list(@@lists){
  chomp $list;
  my  $listFile = `$eyebrowseWrapper --command=getlistfile --listname=$list $props`;
  chomp $listFile;
  print "$list $listFile\n";
  if ( -s $listFile >  1_000_000 ){   
    my $newListFile = $listFile;    
    $newListFile=~s/(\d+)(mbox)$/$1 +1 . $2/e; 
    print "new mbox $newListFile\n";
    touch ($newListFile);
    if(!get_lock($listFile)){
      print "Unable to get lock file for $listFile\n";
      exit 1; 
    }
    print "Updating listfile $listFile for the last time" .           
        `$eyebrowseWrapper --command=updatelist --listname=$list`;
    print "Adding new mbox for $list, $newListFile" . 
        `$eyebrowseWrapper --command=addlistfile --listname=$list --listfile=$newListFile`;
    print "Updating list: $list\n\tMessage:" .
         `$eyebrowseWrapper --command=updatelist --listname=$list $props`;
    release_lock($listFile);
  }
}

sub touch  {
  my $file = shift;
  open TOUCHED, ">$file" or die "Can't write new file, error [$!]\n";
  close TOUCHED;
}

sub get_lock {
  my ($file) = @@_;
  my $lock_file = "$file.lck";
  my $counter = 0;
  while ($counter++ < 10) {
    if (sysopen LOCK, "$lock_file", O_CREAT | O_EXCL ) {
      close LOCK;
      # lock created -- we're ok
      return 1;
    } # lock failed -- something's wrong.  wait a little while
    sleep 1;
  }
  # uhoh ... something's wrong.  the lock file is still present ...
  return 0;
}

sub release_lock {
  my ($file) = @@_;
  my $lock_file = "$file.lck";
  unlink($lock_file);
}
@


1.1.2.1
log
@removing script from cron, moving to helm/scripts under a new name rotate_eb_mbox.pl
@
text
@@

