Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 360 lines (288 sloc) 8.752 kb
b31a690 Jon Jensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
1 my $base = $ARGV[0] || '/work/interchange';
2 $self = {
3 INSTALLARCHLIB => $base,
4 INSTALLBIN => "$base/bin",
5 INSTALLDIRS => 'perl',
6 INSTALLMAN1DIR => "$base/doc",
7 INSTALLMAN3DIR => "$base/doc",
8 INSTALLPRIVLIB => "$base/lib",
9 INSTALLSCRIPT => "$base/bin",
10 };
11
12 my %Special;
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
13
14 use Config;
b31a690 Jon Jensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
15
16 eval {
17 require 'scripts/initp.pl';
18 };
19
20 if(! $MV::Self ) {
21 $MV::Self = $self;
22 $Special{perlpath} = $Config{perlpath};
23 $Special{perlpath} .= <<EOF;
24
25
26 eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
27 if 0; # not running under some shell
28 EOF
29 $Special{perlpath} =~ s/\s+$//;
30 }
31
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
32
33 sub doit {
34 my ($key) = @_;
35 my $val;
36 if ($MV::Self->{RPMBUILDDIR} and $val = $MV::Self->{$key}) {
37 $val =~ s!^$MV::Self->{RPMBUILDDIR}/!/!;
38 return $val;
39 }
40 return $MV::Self->{$key} unless $key =~ /[a-z]/;
b31a690 Jon Jensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
41 return $Special{$key} if defined $Special{$key};
42 $Config{$key};
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
43 }
44
45 DOIT: {
46 local ($/);
47 local($_) = <<'_EoP_';
48 #!/usr/bin/perl
49 ##!~_~perlpath~_~
50 #
d6dc450 perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
51 # Interchange session expiration
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
52 #
4fe1796 Stefan Hornburg (Racke) stop expiring if catalog configuration fails and add catalog name
racke authored
53 # $Id: expire.PL,v 2.3 2002-03-30 12:18:31 racke Exp $
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
54 #
4fe1796 Stefan Hornburg (Racke) stop expiring if catalog configuration fails and add catalog name
racke authored
55 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
56 #
b31a690 Jon Jensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
57 # This program was originally based on Vend 0.2 and 0.3
58 # Copyright 1995-96 by Andrew M. Wilcox <awilcox@world.std.com>
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
59 #
60 # This program is free software; you can redistribute it and/or modify
61 # it under the terms of the GNU General Public License as published by
62 # the Free Software Foundation; either version 2 of the License, or
63 # (at your option) any later version.
64 #
65 # This program is distributed in the hope that it will be useful,
66 # but WITHOUT ANY WARRANTY; without even the implied warranty of
67 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68 # GNU General Public License for more details.
69 #
70 # You should have received a copy of the GNU General Public
71 # License along with this program; if not, write to the Free
72 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
73 # MA 02111-1307 USA.
74
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored
75 use lib '/usr/local/interchange/lib';
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
76 #use lib '~_~INSTALLPRIVLIB~_~';
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored
77 use lib '/usr/local/interchange';
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
78 #use lib '~_~INSTALLARCHLIB~_~';
79
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
80 use strict;
81 use Fcntl;
82 use Vend::Session;
b31a690 Jon Jensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
83 use Vend::Config qw(get_catalog_default global_config parse_time);
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
84 use Vend::Util qw/errmsg/;
85 use Getopt::Std;
b31a690 Jon Jensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
86 use vars qw/$opt_c $opt_r $opt_e $opt_f $opt_u $opt_v $opt_x/;
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
87
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
88 BEGIN {
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
89 ($Global::VendRoot = $ENV{MINIVEND_ROOT})
90 if defined $ENV{MINIVEND_ROOT};
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
91 $Global::VendRoot = $Global::VendRoot || '/usr/local/interchange';
92 # $Global::VendRoot = $Global::VendRoot || '~_~INSTALLARCHLIB~_~';
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
93 $ENV{MINIVEND_STORABLE} = 1
94 if -f "$Global::VendRoot/_session_storable";
95 $ENV{MINIVEND_STORABLE_DB} = 1
96 if -f "$Global::VendRoot/_db_storable";
a71f111 perusionmike Updated to find either interchange.cfg or minivend.cfg
perusionmike authored
97
98 if(-f "$Global::VendRoot/interchange.cfg") {
99 $Global::ExeName = 'interchange';
100 $Global::ConfigFile = 'interchange.cfg';
101 }
102 elsif(-f "$Global::VendRoot/minivend.cfg") {
103 $Global::ExeName = 'minivend';
104 $Global::ConfigFile = 'minivend.cfg';
105 }
106 elsif(-f "$Global::VendRoot/interchange.cfg.dist") {
107 $Global::ExeName = 'interchange';
108 $Global::ConfigFile = 'interchange.cfg';
109 }
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
110 }
111
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
112 ### END CONFIGURATION VARIABLES
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
113
114 $Global::HammerLock = 20;
115 $Global::ErrorFile = 'error.log';
116
117 $Vend::ExternalProgram = 1;
5ce6fe8 perusionmike Set to remove error messages when running.
perusionmike authored
118 $Vend::Quiet = 1;
119 $Vend::SessionName = 'utility';
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
120
121 #select a DBM
122
123 BEGIN {
124 $Global::GDBM = $Global::DB_File = 0;
125 AUTO: {
126 last AUTO if
127 (defined $ENV{MINIVEND_DBFILE} and $Global::DB_File = 1);
128 last AUTO if
129 (defined $ENV{MINIVEND_NODBM});
130 eval {require GDBM_File and $Global::GDBM = 1} ||
131 eval {require DB_File and $Global::DB_File = 1};
132 }
133 if($Global::GDBM) {
134 require Vend::Table::GDBM;
135 import GDBM_File;
136 $Global::GDBM = 1;
137 }
138 elsif($Global::DB_File) {
139 require Vend::Table::DB_File;
140 import DB_File;
141 $Global::DB_File = 1;
142 }
143 else {
144 die "Can't use expire without DBM sessions.\n";
145 }
146 }
147
b31a690 Jon Jensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
148 sub logGlobal { }
149 sub logError { }
150 sub logDebug { }
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
151
152 sub is_retired {}
153
154 my $USAGE = <<EOF;
155 usage: expire [-r|-u] -c catalog [-e 'SessionExpire']
156 or
157 expire [-r|-u] [-e 'SessionExpire'] sessionfile [sessionfile.lock]
158
159 OPTIONS
a71f111 perusionmike Updated to find either interchange.cfg or minivend.cfg
perusionmike authored
160 -c catalog specify a catalog from interchange.cfg
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
161
162 -e time vary expire time from default in catalog.cfg.
163 time is a string like '4 hours' or '2 days'
164
165 -r reorganize database and recover lost disk space
166
167 -u unlink files if file-based sessions (otherwise
168 produces "rm -f \$file" suitable for shell
169 scripts)
170
171 -x produce list of expired files, one per line
172 EOF
173
174 my $catalog;
175 my $expiretime;
176 my $reorg;
177
178 $Vend::Cfg = { FileCreationMask => 0600 };
179
b31a690 Jon Jensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
180 getopts('c:e:f:ruvx') or die "$@\n$USAGE\n";
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
181
182 $catalog = $opt_c || undef;
183 $expiretime = $opt_e || undef;
184 $reorg = $opt_r;
185
b31a690 Jon Jensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
186 if($opt_f) {
187 $Global::ConfigFile = $opt_f;
188 }
189 else {
190 $Global::ConfigFile = "$Global::VendRoot/$Global::ConfigFile";
191 }
192
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
193 GETOPT: {
194
195 last GETOPT if $catalog;
196 $Vend::Cfg->{SessionDatabase} = shift
197 || die $USAGE;
198 $Vend::Cfg->{SessionDatabase} =~ s/\.(gdbm|db)$//;
199 $Vend::Cfg->{SessionLockFile} = shift;
200 if (defined $Vend::Cfg->{SessionLockFile}) {
201 die <<EOF unless -f $Vend::Cfg->{SessionLockFile};
202 Session lock file '$Vend::Cfg->{SessionLockFile}' doesn't exist.
d6dc450 perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
203 Create one if you are sure the Interchange server is down, then try
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
204 again.
205 EOF
206 }
207 elsif (-f "$Vend::Cfg->{SessionDatabase}.lock") {
208 $Vend::Cfg->{SessionLockFile} =
209 "$Vend::Cfg->{SessionDatabase}.lock";
210 }
211 else {
212 my $dir = $Vend::Cfg->{SessionDatabase};
213 $dir = s:/?([^/]+)$::;
214 my $file = $1 || die $USAGE;
215 die "Aborting, no lock files found!\n"
216 unless -f "$dir/$file.lock";
217 }
218
219 } # END GETOPT
220
221 die "too many args, aborting.\n" if @ARGV;
222
223 my $g;
224
225 if(defined $catalog) {
226 my($name,$dir,$param);
dde2445 Set $Vend::ControllingInterchange = 1 before calling global_config()
Kevin Walsh authored
227
228 # Parse the interchange.cfg file to look for script/catalog info
229 # but don't read in the core tags
230 $Vend::ControllingInterchange = 1;
231 chdir $Global::VendRoot
232 or die "Couldn't change to $Global::VendRoot: $!\n";
b31a690 Jon Jensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
233 global_config();
dde2445 Set $Vend::ControllingInterchange = 1 before calling global_config()
Kevin Walsh authored
234
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
235 $g = $Global::Catalog{$catalog};
236 chdir $g->{dir} or die "chdir to $g->{dir}: $!\n";
4fe1796 Stefan Hornburg (Racke) stop expiring if catalog configuration fails and add catalog name
racke authored
237 eval {$Vend::Cfg = Vend::Config::config(
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
238 $g->{name},
239 $g->{dir},
240 "$g->{dir}/etc",
241 $g->{base} || undef,
4fe1796 Stefan Hornburg (Racke) stop expiring if catalog configuration fails and add catalog name
racke authored
242 )};
243 if ($@) {
244 die "$0: Configuration for catalog $catalog failed: $@\n";
245 }
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
246 }
247 else {
248 $Vend::Cfg->{ScratchDir} = '/tmp';
249 $Vend::Cfg->{ErrorFile} = $Global::ErrorFile;
250 $expiretime = '1 day' unless defined $expiretime;
251 }
252
253 if($expiretime) {
254 $Vend::Cfg->{SessionExpire} = parse_time('SessionExpire', $expiretime);
255 }
256
257 print "$Vend::Cfg->{CatalogName} expire="
258 . $Vend::Cfg->{SessionExpire} / 3600
259 . " hour" . ($Vend::Cfg->{SessionExpire} > 3600 ? 's' : '') . "\n"
260 if $opt_v;
261
262
2082329 Jon Jensen Check in Kevin Walsh's patch for expiring NFS-based session files.
jonjensen authored
263 if ($Vend::Cfg->{SessionType} eq 'File'
264 or $Vend::Cfg->{SessionType} eq 'NFS') {
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
265 require File::Find;
266 my $expire = $Vend::Cfg->{SessionExpire} + 60;
267 $expire /= 86400;
268 my $wanted;
269 my @nuke;
270 $wanted = sub {
271 return unless -f $_ && -M _ > $expire;
272 push @nuke, $File::Find::name;
273 };
274 require File::Find;
275 File::Find::find($wanted, $Vend::Cfg->{SessionDatabase});
276 exit unless @nuke;
277 if($opt_u) {
278 unlink @nuke;
279 }
280 else {
281 my $joiner = $opt_x ? "\n" : "\nrm -f ";
282 print "rm -f " unless $opt_x;
283 print join $joiner, @nuke;
284 print "\n";
285 }
286 exit;
287 }
288
289 die $USAGE unless defined $Vend::Cfg->{SessionLockFile};
290
291 my $db_reorg = $Global::DB_File ? $reorg : undef;
292
293 undef $reorg unless $Global::GDBM;
294
295 get_session() unless $reorg;
296 expire_sessions($reorg);
297 release_session() unless $reorg;
298
299 #system "compact ." if $db_reorg;
300
301 =head1 NAME
302
d6dc450 perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
303 expire -- expire Interchange session files and databases
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
304
305 =head1 VERSION
306
4fe1796 Stefan Hornburg (Racke) stop expiring if catalog configuration fails and add catalog name
racke authored
307 1.1
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
308
309 =head1 SYNOPSIS
310
311 expire [-ra] [-e expr] [-c catalog] [-d dir] [sessiondb]
312
313 =head1 DESCRIPTION
314
d6dc450 perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
315 Interchange's C<expire> expires the various session database and temporary
316 files used by the Interchange daemon.
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
317
318 If the program C<tmpwatch> is available, it is called with the appropriate
d6dc450 perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
319 arguments. Otherwise, Interchange will remove all files itself with a recursive
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
320 routine.
321
322 =head1 OPTIONS
323
324 =over 4
325
326 =item -c name
327
328 Expires the catalog C<name> according to its settings. Removes all temporary
329 files that are in a subdirectory one level below the directory itself.
330
331 =item -d dir
332
333 Sets the directory that will be checked for session files and/or temporary
334 files.
335
336 =item -e spec
337
d6dc450 perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
338 Accepts a Interchange expire time setting like "6 hours", "3 days", etc.
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
339 The expire time is applied directly to sessions, and may be padded for
340 temporary files.
341
342 =back
343
344 =head1 SEE ALSO
345
b31a690 Jon Jensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
346 expireall(1), http://interchange.redhat.com/
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
347
348 =head1 AUTHOR
349
b31a690 Jon Jensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
350 Mike Heins, <mheins@redhat.com>
5550c3a perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
351
352 _EoP_
353 s{.*\n(#(.*)~_~(\w+)~_~(.*))}{$2 . doit($3) . "$4\n$1"}eg;
354 my $file = $0;
355 $file =~ s/\.PL$//;
356 open(OUT, ">$file")
357 or die "Create $file: $!\n";
358 print OUT $_;
359 }
Something went wrong with that request. Please try again.