Fixed up capture
[clearscm.git] / bin / cleantmp.pl
index 79c567a..12898a9 100755 (executable)
@@ -46,6 +46,8 @@ $Date: $
    -c|onf <file>:    Config file holding patterns to match (Default: 
                      .../etc/cleantmp.conf)
    -l|ogpath <path>: Path to logfile (Default: /var/log)
+   -a|ppend:         Append to logfile (Default: Noappend)
+   -da|emon          Run in daemon mode (Default: -daemon)
    -s|leep <secs>:   How many seconds to sleep between polls (Default: 60)
 
 =head1 DESCRIPTION
@@ -75,14 +77,17 @@ use Utils;
 my ($script) = ($FindBin::Script =~ /^(.*)\.pl/);
 my $log;
 
+local $0 = $script;
+
 my %opts = (
   usage   => sub { pod2usage },
   help    => sub { pod2usage(-verbose => 2)},
   verbose => sub { set_verbose },
   debug   => sub { set_debug },
+  daemon  => 1,
   tmp     => File::Spec->tmpdir(),
   conf    => "$FindBin::Bin/../etc/$script.conf",
-  logpath => '/var/log',
+  logpath => '/var/local/log',
   sleep   => 60,
 );
 
@@ -144,7 +149,6 @@ sub FileCreated {
           } # if
         } # if
 
-
         last;
       } # if
     } # for
@@ -153,6 +157,8 @@ sub FileCreated {
   return;
 } # FileCreated
 
+$SIG{USR1} = \&FileCreated;
+
 ## Main
 GetOptions (
   \%opts,
@@ -160,13 +166,19 @@ GetOptions (
   'help',
   'verbose',
   'debug',
+  'daemon!',
   'tmp=s',
   'logpath=s',
   'conf=s',
-  'sleep=i'
+  'sleep=i',
+  'append',
 ) or pod2usage;
 
-$log = Logger->new(path => $opts{logpath}, timestamped => 1);
+$log = Logger->new(
+  path        => $opts{logpath},
+  timestamped => 1,
+  append      => $opts{append},
+);
 
 $log->msg("Starting $FindBin::Script");
 
@@ -185,7 +197,12 @@ $monitor->watch({
 
 set_debug if $DB::OUT;
 
-EnterDaemonMode unless $DB::OUT or get_debug;
+if ($opts{daemon}) {
+  # Perl complains if we reference $DB::OUT only once
+  no warnings;
+  EnterDaemonMode unless defined $DB::OUT or get_debug;
+  use warnings;
+} # if
 
 while () {
   $monitor->scan;