]> git.pld-linux.org Git - packages/apache1-mod_bandwidth.git/blob - apache1-mod_bandwidth-cleanlink.pl
- use apache1(EAPI) for runtime dep
[packages/apache1-mod_bandwidth.git] / apache1-mod_bandwidth-cleanlink.pl
1 #!/usr/bin/perl
2
3 #
4 # A little daemon that I use to clean links created by the bandwidth
5 # module for Apache when they weren't removed properly by the server.
6 # (Ie: when a httpd process didn't terminated in the usual way.)
7 #
8 # Change the value of TIME to how often (in seconds) you want to
9 # do the cleaning.
10 #
11
12 $TIME=120;
13
14 $PS="ps auxw";
15 $LINKDIR="/var/run/apache-mod_bandwidth/link";
16
17
18 sub do_clean {
19    local(%ppid);
20
21    open(INP, "$PS |");
22    while(<INP>) {
23       if (($process) =/^\S+\s+(\d+)\s+.+httpd\s/) {
24          $ppid{$process}=1;
25       }
26    }
27    close(INP);
28
29    opendir(DIR, $LINKDIR);
30    local(@filename)=readdir(DIR);
31    closedir(DIR);
32
33    for($i=0; $i <= $#filename; $i++)  {
34       if ($filename[$i] =~ /^\d+$/) {
35          if (! $ppid{$filename[$i]}) {
36             unlink("$LINKDIR/$filename[$i]");
37          }
38       }
39    }
40 }
41
42 do_clean();
43
This page took 0.103021 seconds and 3 git commands to generate.