]>
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 | ||
14 | $PS="ps -auxw"; | |
15 | $LINKDIR="/var/run/apache-mod_bandwidth/link"; | |
16 | ||
17 | unless(fork) { | |
18 | unless (fork) { | |
19 | sleep 1 until getppid == 1; | |
20 | while (1) { | |
21 | &do_clean; | |
22 | sleep($TIME); | |
23 | } | |
24 | exit 0; | |
25 | } | |
26 | exit 0; | |
27 | } wait; | |
28 | ||
29 | sub do_clean { | |
30 | local(%ppid); | |
31 | ||
32 | open(INP, "$PS |"); | |
33 | while(<INP>) { | |
34 | if (($process) =/^\S+\s+(\d+)\s+.+httpd\s/) { | |
35 | $ppid{$process}=1; | |
36 | } | |
37 | } | |
38 | close(INP); | |
39 | ||
40 | opendir(DIR, $LINKDIR); | |
41 | local(@filename)=readdir(DIR); | |
42 | closedir(DIR); | |
43 | ||
44 | for($i=0; $i <= $#filename; $i++) { | |
45 | if ($filename[$i] =~ /^\d+$/) { | |
46 | if (! $ppid{$filename[$i]}) { | |
47 | unlink("$LINKDIR/$filename[$i]"); | |
48 | } | |
49 | } | |
50 | } | |
51 | } |