Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 333 lines (269 sloc) 8.261 kb
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
1 #$self = {
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored
2 # INSTALLPRIVLIB => '/usr/local/interchange/lib',
3 # INSTALLARCHLIB => '/usr/local/interchange',
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
4 #};
5
6 use Config;
7 require 'scripts/initp.pl';
8
9 sub doit {
10 my ($key) = @_;
11 my $val;
12 if ($MV::Self->{RPMBUILDDIR} and $val = $MV::Self->{$key}) {
13 $val =~ s!^$MV::Self->{RPMBUILDDIR}/!/!;
14 return $val;
15 }
16 return $MV::Self->{$key} unless $key =~ /[a-z]/;
17 return $Config{$key};
18 }
19
20 DOIT: {
21 local ($/);
22 local($_) = <<'_EoP_';
23 #!/usr/bin/perl
24 ##!~_~perlpath~_~
25 #
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
26 # Interchange session expiration
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
27 #
5ce6fe8 @perusionmike Set to remove error messages when running.
perusionmike authored
28 # $Id: expire.PL,v 1.8 2000-10-04 23:36:57 heins Exp $
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
29 #
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
30 # Copyright (C) 1996-2000 Akopia, Inc. <info@akopia.com>
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
31 #
32 # This program was originally based on Vend 0.2
33 # Copyright 1995 by Andrew M. Wilcox <awilcox@world.std.com>
34 #
35 # Portions from Vend 0.3
36 # Copyright 1995 by Andrew M. Wilcox <awilcox@world.std.com>
37 #
38 # See the file 'Changes' for information.
39 #
40 # This program is free software; you can redistribute it and/or modify
41 # it under the terms of the GNU General Public License as published by
42 # the Free Software Foundation; either version 2 of the License, or
43 # (at your option) any later version.
44 #
45 # This program is distributed in the hope that it will be useful,
46 # but WITHOUT ANY WARRANTY; without even the implied warranty of
47 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 # GNU General Public License for more details.
49 #
50 # You should have received a copy of the GNU General Public
51 # License along with this program; if not, write to the Free
52 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
53 # MA 02111-1307 USA.
54
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored
55 use lib '/usr/local/interchange/lib';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
56 #use lib '~_~INSTALLPRIVLIB~_~';
a30978f s:/usr/local/minivend:/usr/local/interchange:g;
Eric Zarko authored
57 use lib '/usr/local/interchange';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
58 #use lib '~_~INSTALLARCHLIB~_~';
59
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
60 use strict;
61 use Fcntl;
62 use Vend::Session;
63 use Vend::Config qw(get_catalog_default parse_time);
64 use Vend::Util qw/errmsg/;
65 use Getopt::Std;
66 use vars qw/$opt_c $opt_r $opt_e $opt_u $opt_v $opt_x/;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
67
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
68 BEGIN {
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
69 ($Global::VendRoot = $ENV{MINIVEND_ROOT})
70 if defined $ENV{MINIVEND_ROOT};
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
71 $Global::VendRoot = $Global::VendRoot || '/usr/local/interchange';
72 # $Global::VendRoot = $Global::VendRoot || '~_~INSTALLARCHLIB~_~';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
73 $ENV{MINIVEND_STORABLE} = 1
74 if -f "$Global::VendRoot/_session_storable";
75 $ENV{MINIVEND_STORABLE_DB} = 1
76 if -f "$Global::VendRoot/_db_storable";
a71f111 @perusionmike Updated to find either interchange.cfg or minivend.cfg
perusionmike authored
77
78 if(-f "$Global::VendRoot/interchange.cfg") {
79 $Global::ExeName = 'interchange';
80 $Global::ConfigFile = 'interchange.cfg';
81 }
82 elsif(-f "$Global::VendRoot/minivend.cfg") {
83 $Global::ExeName = 'minivend';
84 $Global::ConfigFile = 'minivend.cfg';
85 }
86 elsif(-f "$Global::VendRoot/interchange.cfg.dist") {
87 $Global::ExeName = 'interchange';
88 $Global::ConfigFile = 'interchange.cfg';
89 }
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
90 }
91
47a2cb5 Minor formatting changes for consistency.
Eric Zarko authored
92 ### END CONFIGURATION VARIABLES
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
93
94 $Global::HammerLock = 20;
95 $Global::ErrorFile = 'error.log';
96
97 $Vend::ExternalProgram = 1;
5ce6fe8 @perusionmike Set to remove error messages when running.
perusionmike authored
98 $Vend::Quiet = 1;
99 $Vend::SessionName = 'utility';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
100
101 #select a DBM
102
103 BEGIN {
104 $Global::GDBM = $Global::DB_File = 0;
105 AUTO: {
106 last AUTO if
107 (defined $ENV{MINIVEND_DBFILE} and $Global::DB_File = 1);
108 last AUTO if
109 (defined $ENV{MINIVEND_NODBM});
110 eval {require GDBM_File and $Global::GDBM = 1} ||
111 eval {require DB_File and $Global::DB_File = 1};
112 }
113 if($Global::GDBM) {
114 require Vend::Table::GDBM;
115 import GDBM_File;
116 $Global::GDBM = 1;
117 }
118 elsif($Global::DB_File) {
119 require Vend::Table::DB_File;
120 import DB_File;
121 $Global::DB_File = 1;
122 }
123 else {
124 die "Can't use expire without DBM sessions.\n";
125 }
126 }
127
128 sub logGlobal {
129 ref $_[0] and shift(@_);
5ce6fe8 @perusionmike Set to remove error messages when running.
perusionmike authored
130 warn(errmsg(@_)) unless $Vend::Quiet;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
131 }
132
133 sub is_retired {}
134
135 my $USAGE = <<EOF;
136 usage: expire [-r|-u] -c catalog [-e 'SessionExpire']
137 or
138 expire [-r|-u] [-e 'SessionExpire'] sessionfile [sessionfile.lock]
139
140 OPTIONS
a71f111 @perusionmike Updated to find either interchange.cfg or minivend.cfg
perusionmike authored
141 -c catalog specify a catalog from interchange.cfg
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
142
143 -e time vary expire time from default in catalog.cfg.
144 time is a string like '4 hours' or '2 days'
145
146 -r reorganize database and recover lost disk space
147
148 -u unlink files if file-based sessions (otherwise
149 produces "rm -f \$file" suitable for shell
150 scripts)
151
152 -x produce list of expired files, one per line
153 EOF
154
155 my $catalog;
156 my $expiretime;
157 my $reorg;
158
159 $Vend::Cfg = { FileCreationMask => 0600 };
160
161 getopts('c:e:ruvx') or die "$@\n$USAGE\n";
162
163 $catalog = $opt_c || undef;
164 $expiretime = $opt_e || undef;
165 $reorg = $opt_r;
166
167 GETOPT: {
168
169 last GETOPT if $catalog;
170 $Vend::Cfg->{SessionDatabase} = shift
171 || die $USAGE;
172 $Vend::Cfg->{SessionDatabase} =~ s/\.(gdbm|db)$//;
173 $Vend::Cfg->{SessionLockFile} = shift;
174 if (defined $Vend::Cfg->{SessionLockFile}) {
175 die <<EOF unless -f $Vend::Cfg->{SessionLockFile};
176 Session lock file '$Vend::Cfg->{SessionLockFile}' doesn't exist.
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
177 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
178 again.
179 EOF
180 }
181 elsif (-f "$Vend::Cfg->{SessionDatabase}.lock") {
182 $Vend::Cfg->{SessionLockFile} =
183 "$Vend::Cfg->{SessionDatabase}.lock";
184 }
185 else {
186 my $dir = $Vend::Cfg->{SessionDatabase};
187 $dir = s:/?([^/]+)$::;
188 my $file = $1 || die $USAGE;
189 die "Aborting, no lock files found!\n"
190 unless -f "$dir/$file.lock";
191 }
192
193 } # END GETOPT
194
195 die "too many args, aborting.\n" if @ARGV;
196
197 my $g;
198
199 if(defined $catalog) {
200 my($name,$dir,$param);
201 chdir $Global::VendRoot;
56f620a @perusionmike Multiple security fixes, tightening up opens with explicit "< $filena…
perusionmike authored
202 open(GLOBAL, "< $Global::ConfigFile") or
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
203 die "No global configuration file? Aborting.\n";
204 while(<GLOBAL>) {
205 next unless /^\s*((?:sub)?catalog)\s+($catalog\s+.*)/i;
206 Vend::Config::parse_catalog($1, $2);
207 }
208 close GLOBAL;
209 die "Catalog $catalog not found in $Global::ConfigFile.\n"
210 unless $Global::Catalog{$catalog};
211 $g = $Global::Catalog{$catalog};
212 chdir $g->{dir} or die "chdir to $g->{dir}: $!\n";
213 $Vend::Cfg = Vend::Config::config(
214 $g->{name},
215 $g->{dir},
216 "$g->{dir}/etc",
217 $g->{base} || undef,
218 );
219 }
220 else {
221 $Vend::Cfg->{ScratchDir} = '/tmp';
222 $Vend::Cfg->{ErrorFile} = $Global::ErrorFile;
223 $expiretime = '1 day' unless defined $expiretime;
224 }
225
226 if($expiretime) {
227 $Vend::Cfg->{SessionExpire} = parse_time('SessionExpire', $expiretime);
228 }
229
230 print "$Vend::Cfg->{CatalogName} expire="
231 . $Vend::Cfg->{SessionExpire} / 3600
232 . " hour" . ($Vend::Cfg->{SessionExpire} > 3600 ? 's' : '') . "\n"
233 if $opt_v;
234
235
236 if ($Vend::Cfg->{SessionType} eq 'File' ) {
237 require File::Find;
238 my $expire = $Vend::Cfg->{SessionExpire} + 60;
239 $expire /= 86400;
240 my $wanted;
241 my @nuke;
242 $wanted = sub {
243 return unless -f $_ && -M _ > $expire;
244 push @nuke, $File::Find::name;
245 };
246 require File::Find;
247 File::Find::find($wanted, $Vend::Cfg->{SessionDatabase});
248 exit unless @nuke;
249 if($opt_u) {
250 unlink @nuke;
251 }
252 else {
253 my $joiner = $opt_x ? "\n" : "\nrm -f ";
254 print "rm -f " unless $opt_x;
255 print join $joiner, @nuke;
256 print "\n";
257 }
258 exit;
259 }
260
261 die $USAGE unless defined $Vend::Cfg->{SessionLockFile};
262
263 my $db_reorg = $Global::DB_File ? $reorg : undef;
264
265 undef $reorg unless $Global::GDBM;
266
267 get_session() unless $reorg;
268 expire_sessions($reorg);
269 release_session() unless $reorg;
270
271 #system "compact ." if $db_reorg;
272
273 =head1 NAME
274
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
275 expire -- expire Interchange session files and databases
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
276
277 =head1 VERSION
278
279 1.0
280
281 =head1 SYNOPSIS
282
283 expire [-ra] [-e expr] [-c catalog] [-d dir] [sessiondb]
284
285 =head1 DESCRIPTION
286
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
287 Interchange's C<expire> expires the various session database and temporary
288 files used by the Interchange daemon.
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
289
290 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
291 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
292 routine.
293
294 =head1 OPTIONS
295
296 =over 4
297
298 =item -c name
299
300 Expires the catalog C<name> according to its settings. Removes all temporary
301 files that are in a subdirectory one level below the directory itself.
302
303 =item -d dir
304
305 Sets the directory that will be checked for session files and/or temporary
306 files.
307
308 =item -e spec
309
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
310 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
311 The expire time is applied directly to sessions, and may be padded for
312 temporary files.
313
314 =back
315
316 =head1 SEE ALSO
317
c3c8e69 Changed documentation (mostly pod, a couple of comments as well) to r…
Eric Zarko authored
318 mvdocs(8), expireall(1), http://www.akopia.com/
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
319
320 =head1 AUTHOR
321
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
322 Mike Heins, <heins@akopia.com>
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
323
324
325 _EoP_
326 s{.*\n(#(.*)~_~(\w+)~_~(.*))}{$2 . doit($3) . "$4\n$1"}eg;
327 my $file = $0;
328 $file =~ s/\.PL$//;
329 open(OUT, ">$file")
330 or die "Create $file: $!\n";
331 print OUT $_;
332 }
Something went wrong with that request. Please try again.