]>
Commit | Line | Data |
---|---|---|
5128d3ce AM |
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 | ||
3ea0f987 | 14 | $PS="ps auxw"; |
5128d3ce AM |
15 | $LINKDIR="/var/run/apache-mod_bandwidth/link"; |
16 | ||
5128d3ce AM |
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 | } | |
9d94e18c MP |
41 | |
42 | do_clean(); | |
43 |