Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 353 lines (286 sloc) 8.736 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 #
e58b738 @pajamian New Free Software Foundation Address in headers of various files
pajamian authored
6 # $Id: expire.PL,v 2.8.2.1 2007-03-30 12:15:51 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
e58b738 @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;
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
b31a690 @jonjensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
149 sub logGlobal { }
150 sub logError { }
151 sub logDebug { }
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
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
a71f111 @perusionmike Updated to find either interchange.cfg or minivend.cfg
perusionmike authored
161 -c catalog specify a catalog from interchange.cfg
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
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
b31a690 @jonjensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
181 getopts('c:e:f:ruvx') or die "$@\n$USAGE\n";
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
182
183 $catalog = $opt_c || undef;
184 $expiretime = $opt_e || undef;
185 $reorg = $opt_r;
186
b31a690 @jonjensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
187 if($opt_f) {
188 $Global::ConfigFile = $opt_f;
189 }
190 else {
191 $Global::ConfigFile = "$Global::VendRoot/$Global::ConfigFile";
192 }
193
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
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.
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
204 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
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);
dde2445 Set $Vend::ControllingInterchange = 1 before calling global_config()
Kevin Walsh authored
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";
b31a690 @jonjensen Move DEV_4_7_0 development branch to repository trunk.
jonjensen authored
234 global_config();
dde2445 Set $Vend::ControllingInterchange = 1 before calling global_config()
Kevin Walsh authored
235
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
236 $g = $Global::Catalog{$catalog};
237 chdir $g->{dir} or die "chdir to $g->{dir}: $!\n";
4fe1796 @racke stop expiring if catalog configuration fails and add catalog name
racke authored
238 eval {$Vend::Cfg = Vend::Config::config(
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
239 $g->{name},
240 $g->{dir},
241 "$g->{dir}/etc",
242 $g->{base} || undef,
4fe1796 @racke stop expiring if catalog configuration fails and add catalog name
racke authored
243 )};
244 if ($@) {
245 die "$0: Configuration for catalog $catalog failed: $@\n";
246 }
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
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
2082329 @jonjensen Check in Kevin Walsh's patch for expiring NFS-based session files.
jonjensen authored
264 if ($Vend::Cfg->{SessionType} eq 'File'
265 or $Vend::Cfg->{SessionType} eq 'NFS') {
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
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
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
304 expire -- expire Interchange session files and databases
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
305
306 =head1 VERSION
307
4fe1796 @racke stop expiring if catalog configuration fails and add catalog name
racke authored
308 1.1
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
309
310 =head1 SYNOPSIS
311
312 expire [-ra] [-e expr] [-c catalog] [-d dir] [sessiondb]
313
314 =head1 DESCRIPTION
315
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
316 Interchange's C<expire> expires the various session database and temporary
317 files used by the Interchange daemon.
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
318
319 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
320 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
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
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
339 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
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
3397adc @jonjensen The great copyright, email address, URL, and version update.
jonjensen authored
347 expireall(1), http://www.icdevgroup.org/
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
348
349 =head1 AUTHOR
350
3397adc @jonjensen The great copyright, email address, URL, and version update.
jonjensen authored
351 Mike Heins
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
352
Something went wrong with that request. Please try again.