Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 357 lines (285 sloc) 8.659 kB
b31a690 @jonjensen 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 @jonjensen 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 @jonjensen 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 #
dde2445 Set $Vend::ControllingInterchange = 1 before calling global_config()
Kevin Walsh authored
53 # $Id: expire.PL,v 2.2 2002-02-04 07:41:39 kwalsh Exp $
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
54 #
b31a690 @jonjensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
55 # Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
56 #
b31a690 @jonjensen 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 @jonjensen 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 @jonjensen 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 @jonjensen 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 @jonjensen 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 @jonjensen 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 @jonjensen 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";
237 $Vend::Cfg = Vend::Config::config(
238 $g->{name},
239 $g->{dir},
240 "$g->{dir}/etc",
241 $g->{base} || undef,
242 );
243 }
244 else {
245 $Vend::Cfg->{ScratchDir} = '/tmp';
246 $Vend::Cfg->{ErrorFile} = $Global::ErrorFile;
247 $expiretime = '1 day' unless defined $expiretime;
248 }
249
250 if($expiretime) {
251 $Vend::Cfg->{SessionExpire} = parse_time('SessionExpire', $expiretime);
252 }
253
254 print "$Vend::Cfg->{CatalogName} expire="
255 . $Vend::Cfg->{SessionExpire} / 3600
256 . " hour" . ($Vend::Cfg->{SessionExpire} > 3600 ? 's' : '') . "\n"
257 if $opt_v;
258
259
2082329 @jonjensen Check in Kevin Walsh's patch for expiring NFS-based session files.
jonjensen authored
260 if ($Vend::Cfg->{SessionType} eq 'File'
261 or $Vend::Cfg->{SessionType} eq 'NFS') {
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
262 require File::Find;
263 my $expire = $Vend::Cfg->{SessionExpire} + 60;
264 $expire /= 86400;
265 my $wanted;
266 my @nuke;
267 $wanted = sub {
268 return unless -f $_ && -M _ > $expire;
269 push @nuke, $File::Find::name;
270 };
271 require File::Find;
272 File::Find::find($wanted, $Vend::Cfg->{SessionDatabase});
273 exit unless @nuke;
274 if($opt_u) {
275 unlink @nuke;
276 }
277 else {
278 my $joiner = $opt_x ? "\n" : "\nrm -f ";
279 print "rm -f " unless $opt_x;
280 print join $joiner, @nuke;
281 print "\n";
282 }
283 exit;
284 }
285
286 die $USAGE unless defined $Vend::Cfg->{SessionLockFile};
287
288 my $db_reorg = $Global::DB_File ? $reorg : undef;
289
290 undef $reorg unless $Global::GDBM;
291
292 get_session() unless $reorg;
293 expire_sessions($reorg);
294 release_session() unless $reorg;
295
296 #system "compact ." if $db_reorg;
297
298 =head1 NAME
299
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
300 expire -- expire Interchange session files and databases
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
301
302 =head1 VERSION
303
304 1.0
305
306 =head1 SYNOPSIS
307
308 expire [-ra] [-e expr] [-c catalog] [-d dir] [sessiondb]
309
310 =head1 DESCRIPTION
311
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
312 Interchange's C<expire> expires the various session database and temporary
313 files used by the Interchange daemon.
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
314
315 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
316 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
317 routine.
318
319 =head1 OPTIONS
320
321 =over 4
322
323 =item -c name
324
325 Expires the catalog C<name> according to its settings. Removes all temporary
326 files that are in a subdirectory one level below the directory itself.
327
328 =item -d dir
329
330 Sets the directory that will be checked for session files and/or temporary
331 files.
332
333 =item -e spec
334
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
335 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
336 The expire time is applied directly to sessions, and may be padded for
337 temporary files.
338
339 =back
340
341 =head1 SEE ALSO
342
b31a690 @jonjensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
343 expireall(1), http://interchange.redhat.com/
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
344
345 =head1 AUTHOR
346
b31a690 @jonjensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
347 Mike Heins, <mheins@redhat.com>
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
348
349 _EoP_
350 s{.*\n(#(.*)~_~(\w+)~_~(.*))}{$2 . doit($3) . "$4\n$1"}eg;
351 my $file = $0;
352 $file =~ s/\.PL$//;
353 open(OUT, ">$file")
354 or die "Create $file: $!\n";
355 print OUT $_;
356 }
Something went wrong with that request. Please try again.