Line # Revision Author
1 265 ahitrov #!/usr/bin/perl
2
3 use strict;
4 use warnings "all";
5 use locale;
6
7 use FindBin;
8 BEGIN {
9 require "$FindBin::RealBin/../lib/Modules.pm";
10 }
11
12 use Contenido::Globals;
13 use Contenido::Init;
14 use ErrorTee;
15 use PidFile;
16
17
18 # begin
19 Contenido::Init->init();
20
21 my $keeper_module = $state->project.'::Keeper';
22 $keeper = $keeper_module->new($state);
23
24 #PidFile->new($keeper, compat=>1); # db-based locking (run only on one host)
25 #PidFile->new($keeper, compat=>1, per_host=>1); # db-based locking (run on whole cluster)
26
27 my $session_lifetime;
28 for my $plugin ( split(/\s+/, $state->plugins) ) {
29 my $class = $plugin.'::Apache';
30 eval { $class->child_init(); };
31 if ( $@ ) {
32 $log->error("Не могу выполнить метод child_init плагина $plugin ($class) по причине '$@'");
33 } elsif ( $plugin eq 'session' ) {
34 $session_lifetime = $state->{session}->lifetime;
35 }
36 }
37
38 ############################################
39 # please use:
40 # $state->{log_dir} for logging
41 # $state->{tmp_dir} for temporary files
42 ###########################################
43
44 print "Lifetime: $session_lifetime\n" if $DEBUG;
45 if ( $session_lifetime ) {
46 my $DBH = $keeper->SQL;
47 my $now = Contenido::DateTime->new;
48 my $then = $now->clone->subtract( seconds => $session_lifetime );
49 my $request = "DELETE FROM sessions WHERE dtime < ?";
50 my $sth = $DBH->prepare($request);
51 print $then->ymd('-').' '.$then->hms."\n" if $DEBUG;
52 $sth->execute( $then->ymd('-').' '.$then->hms );
53 $sth->finish;
54 }