Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 352 lines (285 sloc) 8.72 kB
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
1 #!/usr/bin/perl
2 ##!~_~perlpath~_~
3 #
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
4 # Interchange session expiration
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
5 #
bde37b0 @jonjensen Update Andrew Wilcox's email address at his request.
jonjensen authored
6 # $Id: expire.PL,v 2.6 2002-06-27 22:24:11 jon Exp $
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
7 #
4fe1796 @racke stop expiring if catalog configuration fails and add catalog name
racke authored
8 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
9 #
b31a690 @jonjensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
10 # This program was originally based on Vend 0.2 and 0.3
bde37b0 @jonjensen Update Andrew Wilcox's email address at his request.
jonjensen authored
11 # Copyright 1995-96 by Andrew M. Wilcox <amw@wilcoxsolutions.com>
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
12 #
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public
24 # License along with this program; if not, write to the Free
25 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 # MA 02111-1307 USA.
27
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored
28 use lib '/usr/local/interchange/lib';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
29 #use lib '~_~INSTALLPRIVLIB~_~';
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored
30 use lib '/usr/local/interchange';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
31 #use lib '~_~INSTALLARCHLIB~_~';
32
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
33 use strict;
34 use Fcntl;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
35
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
36 BEGIN {
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
37 ($Global::VendRoot = $ENV{MINIVEND_ROOT})
38 if defined $ENV{MINIVEND_ROOT};
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
39 $Global::VendRoot = $Global::VendRoot || '/usr/local/interchange';
40 # $Global::VendRoot = $Global::VendRoot || '~_~INSTALLARCHLIB~_~';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
41 $ENV{MINIVEND_STORABLE} = 1
42 if -f "$Global::VendRoot/_session_storable";
43 $ENV{MINIVEND_STORABLE_DB} = 1
44 if -f "$Global::VendRoot/_db_storable";
a71f111 @perusionmike Updated to find either interchange.cfg or minivend.cfg
perusionmike authored
45
46 if(-f "$Global::VendRoot/interchange.cfg") {
47 $Global::ExeName = 'interchange';
48 $Global::ConfigFile = 'interchange.cfg';
49 }
50 elsif(-f "$Global::VendRoot/minivend.cfg") {
51 $Global::ExeName = 'minivend';
52 $Global::ConfigFile = 'minivend.cfg';
53 }
54 elsif(-f "$Global::VendRoot/interchange.cfg.dist") {
55 $Global::ExeName = 'interchange';
56 $Global::ConfigFile = 'interchange.cfg';
57 }
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
58 }
59
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
60 ### END CONFIGURATION VARIABLES
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
61
62 $Global::HammerLock = 20;
63 $Global::ErrorFile = 'error.log';
64
65 $Vend::ExternalProgram = 1;
5ce6fe8 @perusionmike Set to remove error messages when running.
perusionmike authored
66 $Vend::Quiet = 1;
67 $Vend::SessionName = 'utility';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
68
69 #select a DBM
70
71 BEGIN {
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored
72 $Global::GDBM = $Global::DB_File = $Global::SDBM =
73 # LDAP
74 $Global::LDAP =
75 # END LDAP
76 # SQL
77 $Global::DBI =
78 # END SQL
79 0;
80
81 # SQL
82 # This is for standard DBI
83 eval {
84 die if $ENV{MINIVEND_NODBI};
85 require DBI and $Global::DBI = 1
86 };
87 # END SQL
88 # LDAP
89 eval {
90 die if $ENV{MINIVEND_NOLDAP};
91 require Net::LDAP and $Global::LDAP = 1
92 };
93 # END LDAP
94
95 # Now can use any type of database
96 AUTO: {
97 last AUTO if
98 (defined $ENV{MINIVEND_DBFILE} and $Global::DB_File = 1);
99 last AUTO if
100 (defined $ENV{MINIVEND_SDBM} and $Global::SDBM = 1);
101 last AUTO if
102 (defined $ENV{MINIVEND_NODBM});
103 eval {require GDBM_File and $Global::GDBM = 1};
104 last AUTO if
105 (defined $ENV{MINIVEND_GDBM} and $Global::GDBM = 1);
106 last AUTO if
107 ! $ENV{MINIVEND_ALLDBM}
108 and $Global::GDBM;
109 eval {require DB_File and $Global::DB_File = 1};
110 last AUTO if
111 ! $ENV{MINIVEND_ALLDBM}
112 and $Global::GDBM || $Global::DB_File;
113 eval {require SDBM_File and $Global::SDBM = 1};
114 }
115
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
116 if($Global::GDBM) {
117 require Vend::Table::GDBM;
118 import GDBM_File;
119 $Global::GDBM = 1;
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored
120 $Global::Default_database = 'GDBM'
121 unless defined $Global::Default_database;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
122 }
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored
123 if($Global::DB_File) {
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
124 require Vend::Table::DB_File;
125 import DB_File;
126 $Global::DB_File = 1;
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored
127 $Global::Default_database = 'DB_FILE'
128 unless defined $Global::Default_database;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
129 }
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored
130 if($Global::SDBM) {
131 require Vend::Table::SDBM;
132 import SDBM_File;
133 $Global::SDBM = 1;
134 $Global::Default_database = 'SDBM'
135 unless defined $Global::Default_database;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
136 }
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored
137 $Global::Default_database = 'MEMORY'
138 unless defined $Global::Default_database;
139 require Vend::Table::InMemory;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
140 }
141
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored
142 use Vend::Session;
143 use Vend::Config qw(get_catalog_default global_config parse_time);
144 use Vend::Util qw/errmsg/;
145 use Getopt::Std;
146 use vars qw/$opt_c $opt_r $opt_e $opt_f $opt_u $opt_v $opt_x/;
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";
4fe1796 @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 @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 @jonjensen 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 @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 @jonjensen 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 @jonjensen 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
Something went wrong with that request. Please try again.