Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 354 lines (287 sloc) 8.753 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 #
07f71a7 @pajamian New Free Software Foundation Address in headers of various files
pajamian authored
6 # $Id: expire.PL,v 2.10 2007-03-30 11:39:56 pajamian Exp $
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
7 #
a9297cb @jonjensen Big copyright and version number update to prepare for 5.3.2 release.
jonjensen authored
8 # Copyright (C) 2002-2005 Interchange Development Group
3397adc @jonjensen The great copyright, email address, URL, and version update.
jonjensen authored
9 # Copyright (C) 1996-2002 Red Hat, Inc.
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
10 #
b31a690 @jonjensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
11 # 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
12 # Copyright 1995-96 by Andrew M. Wilcox <amw@wilcoxsolutions.com>
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
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
07f71a7 @pajamian New Free Software Foundation Address in headers of various files
pajamian authored
26 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
27 # MA 02110-1301 USA.
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
28
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored
29 use lib '/usr/local/interchange/lib';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
30 #use lib '~_~INSTALLPRIVLIB~_~';
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored
31 use lib '/usr/local/interchange';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
32 #use lib '~_~INSTALLARCHLIB~_~';
33
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
34 use strict;
35 use Fcntl;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
36
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
37 BEGIN {
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
38 ($Global::VendRoot = $ENV{MINIVEND_ROOT})
39 if defined $ENV{MINIVEND_ROOT};
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
40 $Global::VendRoot = $Global::VendRoot || '/usr/local/interchange';
41 # $Global::VendRoot = $Global::VendRoot || '~_~INSTALLARCHLIB~_~';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
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";
a71f111 @perusionmike Updated to find either interchange.cfg or minivend.cfg
perusionmike authored
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 }
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
59 }
60
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
61 ### END CONFIGURATION VARIABLES
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
62
63 $Global::HammerLock = 20;
64 $Global::ErrorFile = 'error.log';
65
66 $Vend::ExternalProgram = 1;
5ce6fe8 @perusionmike Set to remove error messages when running.
perusionmike authored
67 $Vend::Quiet = 1;
68 $Vend::SessionName = 'utility';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
69
70 #select a DBM
71
72 BEGIN {
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored
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
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
117 if($Global::GDBM) {
118 require Vend::Table::GDBM;
119 import GDBM_File;
120 $Global::GDBM = 1;
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored
121 $Global::Default_database = 'GDBM'
122 unless defined $Global::Default_database;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
123 }
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored
124 if($Global::DB_File) {
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
125 require Vend::Table::DB_File;
126 import DB_File;
127 $Global::DB_File = 1;
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored
128 $Global::Default_database = 'DB_FILE'
129 unless defined $Global::Default_database;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
130 }
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored
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;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
137 }
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored
138 $Global::Default_database = 'MEMORY'
139 unless defined $Global::Default_database;
140 require Vend::Table::InMemory;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
141 }
142
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored
143 use Vend::Session;
25372d3 * Added the missing "use Vend::Dispatch" directive to prevent the
Kevin Walsh authored
144 use Vend::Dispatch;
bbcef65 @racke merged changes 2.0.2.2 vs 2.0.2.3
racke authored
145 use Vend::Config qw(get_catalog_default global_config parse_time);
146 use Vend::Util qw/errmsg/;
147 use Getopt::Std;
148 use vars qw/$opt_c $opt_r $opt_e $opt_f $opt_u $opt_v $opt_x/;
149
b31a690 @jonjensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
150 sub logGlobal { }
151 sub logError { }
152 sub logDebug { }
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
153
154 sub is_retired {}
155
156 my $USAGE = <<EOF;
157 usage: expire [-r|-u] -c catalog [-e 'SessionExpire']
158 or
159 expire [-r|-u] [-e 'SessionExpire'] sessionfile [sessionfile.lock]
160
161 OPTIONS
a71f111 @perusionmike Updated to find either interchange.cfg or minivend.cfg
perusionmike authored
162 -c catalog specify a catalog from interchange.cfg
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
163
164 -e time vary expire time from default in catalog.cfg.
165 time is a string like '4 hours' or '2 days'
166
167 -r reorganize database and recover lost disk space
168
169 -u unlink files if file-based sessions (otherwise
170 produces "rm -f \$file" suitable for shell
171 scripts)
172
173 -x produce list of expired files, one per line
174 EOF
175
176 my $catalog;
177 my $expiretime;
178 my $reorg;
179
180 $Vend::Cfg = { FileCreationMask => 0600 };
181
b31a690 @jonjensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
182 getopts('c:e:f:ruvx') or die "$@\n$USAGE\n";
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
183
184 $catalog = $opt_c || undef;
185 $expiretime = $opt_e || undef;
186 $reorg = $opt_r;
187
b31a690 @jonjensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
188 if($opt_f) {
189 $Global::ConfigFile = $opt_f;
190 }
191 else {
192 $Global::ConfigFile = "$Global::VendRoot/$Global::ConfigFile";
193 }
194
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
195 GETOPT: {
196
197 last GETOPT if $catalog;
198 $Vend::Cfg->{SessionDatabase} = shift
199 || die $USAGE;
200 $Vend::Cfg->{SessionDatabase} =~ s/\.(gdbm|db)$//;
201 $Vend::Cfg->{SessionLockFile} = shift;
202 if (defined $Vend::Cfg->{SessionLockFile}) {
203 die <<EOF unless -f $Vend::Cfg->{SessionLockFile};
204 Session lock file '$Vend::Cfg->{SessionLockFile}' doesn't exist.
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
205 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
206 again.
207 EOF
208 }
209 elsif (-f "$Vend::Cfg->{SessionDatabase}.lock") {
210 $Vend::Cfg->{SessionLockFile} =
211 "$Vend::Cfg->{SessionDatabase}.lock";
212 }
213 else {
214 my $dir = $Vend::Cfg->{SessionDatabase};
215 $dir = s:/?([^/]+)$::;
216 my $file = $1 || die $USAGE;
217 die "Aborting, no lock files found!\n"
218 unless -f "$dir/$file.lock";
219 }
220
221 } # END GETOPT
222
223 die "too many args, aborting.\n" if @ARGV;
224
225 my $g;
226
227 if(defined $catalog) {
228 my($name,$dir,$param);
dde2445 Set $Vend::ControllingInterchange = 1 before calling global_config()
Kevin Walsh authored
229
230 # Parse the interchange.cfg file to look for script/catalog info
231 # but don't read in the core tags
232 $Vend::ControllingInterchange = 1;
233 chdir $Global::VendRoot
234 or die "Couldn't change to $Global::VendRoot: $!\n";
b31a690 @jonjensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
235 global_config();
dde2445 Set $Vend::ControllingInterchange = 1 before calling global_config()
Kevin Walsh authored
236
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
237 $g = $Global::Catalog{$catalog};
238 chdir $g->{dir} or die "chdir to $g->{dir}: $!\n";
4fe1796 @racke stop expiring if catalog configuration fails and add catalog name
racke authored
239 eval {$Vend::Cfg = Vend::Config::config(
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
240 $g->{name},
241 $g->{dir},
242 "$g->{dir}/etc",
243 $g->{base} || undef,
4fe1796 @racke stop expiring if catalog configuration fails and add catalog name
racke authored
244 )};
245 if ($@) {
246 die "$0: Configuration for catalog $catalog failed: $@\n";
247 }
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
248 }
249 else {
250 $Vend::Cfg->{ScratchDir} = '/tmp';
251 $Vend::Cfg->{ErrorFile} = $Global::ErrorFile;
252 $expiretime = '1 day' unless defined $expiretime;
253 }
254
255 if($expiretime) {
256 $Vend::Cfg->{SessionExpire} = parse_time('SessionExpire', $expiretime);
257 }
258
259 print "$Vend::Cfg->{CatalogName} expire="
260 . $Vend::Cfg->{SessionExpire} / 3600
261 . " hour" . ($Vend::Cfg->{SessionExpire} > 3600 ? 's' : '') . "\n"
262 if $opt_v;
263
264
2082329 @jonjensen Check in Kevin Walsh's patch for expiring NFS-based session files.
jonjensen authored
265 if ($Vend::Cfg->{SessionType} eq 'File'
266 or $Vend::Cfg->{SessionType} eq 'NFS') {
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
267 require File::Find;
268 my $expire = $Vend::Cfg->{SessionExpire} + 60;
269 $expire /= 86400;
270 my $wanted;
271 my @nuke;
272 $wanted = sub {
273 return unless -f $_ && -M _ > $expire;
274 push @nuke, $File::Find::name;
275 };
276 require File::Find;
277 File::Find::find($wanted, $Vend::Cfg->{SessionDatabase});
278 exit unless @nuke;
279 if($opt_u) {
280 unlink @nuke;
281 }
282 else {
283 my $joiner = $opt_x ? "\n" : "\nrm -f ";
284 print "rm -f " unless $opt_x;
285 print join $joiner, @nuke;
286 print "\n";
287 }
288 exit;
289 }
290
291 die $USAGE unless defined $Vend::Cfg->{SessionLockFile};
292
293 my $db_reorg = $Global::DB_File ? $reorg : undef;
294
295 undef $reorg unless $Global::GDBM;
296
297 get_session() unless $reorg;
298 expire_sessions($reorg);
299 release_session() unless $reorg;
300
301 #system "compact ." if $db_reorg;
302
303 =head1 NAME
304
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
305 expire -- expire Interchange session files and databases
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
306
307 =head1 VERSION
308
4fe1796 @racke stop expiring if catalog configuration fails and add catalog name
racke authored
309 1.1
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
310
311 =head1 SYNOPSIS
312
313 expire [-ra] [-e expr] [-c catalog] [-d dir] [sessiondb]
314
315 =head1 DESCRIPTION
316
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
317 Interchange's C<expire> expires the various session database and temporary
318 files used by the Interchange daemon.
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
319
320 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
321 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
322 routine.
323
324 =head1 OPTIONS
325
326 =over 4
327
328 =item -c name
329
330 Expires the catalog C<name> according to its settings. Removes all temporary
331 files that are in a subdirectory one level below the directory itself.
332
333 =item -d dir
334
335 Sets the directory that will be checked for session files and/or temporary
336 files.
337
338 =item -e spec
339
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
340 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
341 The expire time is applied directly to sessions, and may be padded for
342 temporary files.
343
344 =back
345
346 =head1 SEE ALSO
347
3397adc @jonjensen The great copyright, email address, URL, and version update.
jonjensen authored
348 expireall(1), http://www.icdevgroup.org/
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
349
350 =head1 AUTHOR
351
3397adc @jonjensen The great copyright, email address, URL, and version update.
jonjensen authored
352 Mike Heins
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
353
Something went wrong with that request. Please try again.