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