Skip to content
Newer
Older
100644 352 lines (285 sloc) 8.49 KB
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
1 #!/usr/bin/perl
2 ##!~_~perlpath~_~
3 #
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored Jul 12, 2000
4 # Interchange session expiration
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
5 #
43d511c @pajamian * Updated copyright headers to 2007 (closes bug #102)
pajamian authored Aug 9, 2007
6 # Copyright (C) 2002-2007 Interchange Development Group
3397adc @jonjensen The great copyright, email address, URL, and version update.
jonjensen authored Jun 18, 2003
7 # Copyright (C) 1996-2002 Red Hat, Inc.
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
8 #
b31a690 @jonjensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored Jul 18, 2001
9 # 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 Jun 27, 2002
10 # Copyright 1995-96 by Andrew M. Wilcox <amw@wilcoxsolutions.com>
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
11 #
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public
23 # License along with this program; if not, write to the Free
07f71a7 @pajamian New Free Software Foundation Address in headers of various files
pajamian authored Mar 30, 2007
24 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
25 # MA 02110-1301 USA.
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
26
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored Sep 20, 2000
27 use lib '/usr/local/interchange/lib';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
28 #use lib '~_~INSTALLPRIVLIB~_~';
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored Sep 20, 2000
29 use lib '/usr/local/interchange';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
30 #use lib '~_~INSTALLARCHLIB~_~';
31
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored Sep 25, 2000
32 use strict;
33 use Fcntl;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
34
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored Sep 25, 2000
35 BEGIN {
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
36 ($Global::VendRoot = $ENV{MINIVEND_ROOT})
37 if defined $ENV{MINIVEND_ROOT};
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored Sep 25, 2000
38 $Global::VendRoot = $Global::VendRoot || '/usr/local/interchange';
39 # $Global::VendRoot = $Global::VendRoot || '~_~INSTALLARCHLIB~_~';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
40 $ENV{MINIVEND_STORABLE} = 1
41 if -f "$Global::VendRoot/_session_storable";
42 $ENV{MINIVEND_STORABLE_DB} = 1
43 if -f "$Global::VendRoot/_db_storable";
a71f111 @perusionmike Updated to find either interchange.cfg or minivend.cfg
perusionmike authored Sep 23, 2000
44
45 if(-f "$Global::VendRoot/interchange.cfg") {
46 $Global::ExeName = 'interchange';
47 $Global::ConfigFile = 'interchange.cfg';
48 }
49 elsif(-f "$Global::VendRoot/minivend.cfg") {
50 $Global::ExeName = 'minivend';
51 $Global::ConfigFile = 'minivend.cfg';
52 }
53 elsif(-f "$Global::VendRoot/interchange.cfg.dist") {
54 $Global::ExeName = 'interchange';
55 $Global::ConfigFile = 'interchange.cfg';
56 }
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
57 }
58
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored Sep 25, 2000
59 ### END CONFIGURATION VARIABLES
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
60
61 $Global::HammerLock = 20;
62 $Global::ErrorFile = 'error.log';
63
64 $Vend::ExternalProgram = 1;
5ce6fe8 @perusionmike Set to remove error messages when running.
perusionmike authored Oct 4, 2000
65 $Vend::Quiet = 1;
66 $Vend::SessionName = 'utility';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
67
68 #select a DBM
69
70 BEGIN {
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored May 27, 2002
71 $Global::GDBM = $Global::DB_File = $Global::SDBM =
72 # LDAP
73 $Global::LDAP =
74 # END LDAP
75 # SQL
76 $Global::DBI =
77 # END SQL
78 0;
79
80 # SQL
81 # This is for standard DBI
82 eval {
83 die if $ENV{MINIVEND_NODBI};
84 require DBI and $Global::DBI = 1
85 };
86 # END SQL
87 # LDAP
88 eval {
89 die if $ENV{MINIVEND_NOLDAP};
90 require Net::LDAP and $Global::LDAP = 1
91 };
92 # END LDAP
93
94 # Now can use any type of database
95 AUTO: {
96 last AUTO if
97 (defined $ENV{MINIVEND_DBFILE} and $Global::DB_File = 1);
98 last AUTO if
99 (defined $ENV{MINIVEND_SDBM} and $Global::SDBM = 1);
100 last AUTO if
101 (defined $ENV{MINIVEND_NODBM});
102 eval {require GDBM_File and $Global::GDBM = 1};
103 last AUTO if
104 (defined $ENV{MINIVEND_GDBM} and $Global::GDBM = 1);
105 last AUTO if
106 ! $ENV{MINIVEND_ALLDBM}
107 and $Global::GDBM;
108 eval {require DB_File and $Global::DB_File = 1};
109 last AUTO if
110 ! $ENV{MINIVEND_ALLDBM}
111 and $Global::GDBM || $Global::DB_File;
112 eval {require SDBM_File and $Global::SDBM = 1};
113 }
114
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
115 if($Global::GDBM) {
116 require Vend::Table::GDBM;
117 import GDBM_File;
118 $Global::GDBM = 1;
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored May 27, 2002
119 $Global::Default_database = 'GDBM'
120 unless defined $Global::Default_database;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
121 }
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored May 27, 2002
122 if($Global::DB_File) {
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
123 require Vend::Table::DB_File;
124 import DB_File;
125 $Global::DB_File = 1;
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored May 27, 2002
126 $Global::Default_database = 'DB_FILE'
127 unless defined $Global::Default_database;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
128 }
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored May 27, 2002
129 if($Global::SDBM) {
130 require Vend::Table::SDBM;
131 import SDBM_File;
132 $Global::SDBM = 1;
133 $Global::Default_database = 'SDBM'
134 unless defined $Global::Default_database;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
135 }
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored May 27, 2002
136 $Global::Default_database = 'MEMORY'
137 unless defined $Global::Default_database;
138 require Vend::Table::InMemory;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
139 }
140
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored May 27, 2002
141 use Vend::Session;
25372d3 * Added the missing "use Vend::Dispatch" directive to prevent the
Kevin Walsh authored Mar 21, 2006
142 use Vend::Dispatch;
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored May 27, 2002
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 Jul 18, 2001
148 sub logGlobal { }
149 sub logError { }
150 sub logDebug { }
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
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 Sep 23, 2000
160 -c catalog specify a catalog from interchange.cfg
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
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 Jul 18, 2001
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 May 26, 2000
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 Jul 18, 2001
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 May 26, 2000
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 Jul 12, 2000
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 May 26, 2000
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 Feb 4, 2002
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 Jul 18, 2001
233 global_config();
dde2445 Set $Vend::ControllingInterchange = 1 before calling global_config()
Kevin Walsh authored Feb 4, 2002
234
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
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 Mar 30, 2002
237 eval {$Vend::Cfg = Vend::Config::config(
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
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 Mar 30, 2002
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 May 26, 2000
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 Jan 16, 2002
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 May 26, 2000
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 Jul 12, 2000
303 expire -- expire Interchange session files and databases
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
304
305 =head1 VERSION
306
4fe1796 @racke stop expiring if catalog configuration fails and add catalog name
racke authored Mar 30, 2002
307 1.1
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
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 Jul 12, 2000
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 May 26, 2000
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 Jul 12, 2000
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 May 26, 2000
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 Jul 12, 2000
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 May 26, 2000
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
3397adc @jonjensen The great copyright, email address, URL, and version update.
jonjensen authored Jun 18, 2003
346 expireall(1), http://www.icdevgroup.org/
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
347
348 =head1 AUTHOR
349
3397adc @jonjensen The great copyright, email address, URL, and version update.
jonjensen authored Jun 18, 2003
350 Mike Heins
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored May 26, 2000
351
Something went wrong with that request. Please try again.