1 | #!/usr/bin/perl
|
---|
2 |
|
---|
3 | print "===== Flush DNS Cache =====\n";
|
---|
4 |
|
---|
5 | # The Premise: use sudoedit and other black magic to clear out the memory-
|
---|
6 | # based disk cache (which is done by writing the number 3 to a certain
|
---|
7 | # system file)
|
---|
8 | print " - Synching file system... ";
|
---|
9 | `sync`;
|
---|
10 | print "Done\n";
|
---|
11 | print " - Dropping memory disk cache... ";
|
---|
12 | # - save our current default editor
|
---|
13 | my $current_editor = $ENV{'EDITOR'};
|
---|
14 | # - replace default editor with a script that simply clobbers the contents
|
---|
15 | # of any file it's handed with the number "3"
|
---|
16 | $ENV{'EDITOR'} = 'reset_memcache_editor.sh';
|
---|
17 | # - we now call sudoedit on the system file. How sudoedit works is that it
|
---|
18 | # starts by making a temp copy of the system file with appropriate
|
---|
19 | # permissions allowing the user to edit. It then passes the path to the
|
---|
20 | # temp file to the default editor - typically this would be an interactive
|
---|
21 | # editor like 'vi'. However, we've just replaced the editor with a custom
|
---|
22 | # script that just writes '3' as the content of the tmp file. Finally, when
|
---|
23 | # the editor exits, sudoedit copies the tmp file over the top of the system
|
---|
24 | # file, restoring appropriate root-level permissions
|
---|
25 | `sudoedit /proc/sys/vm/drop_caches`;
|
---|
26 | # - restore the default editor, just in case something in Greenstone
|
---|
27 | # depends on this being a reasonably value
|
---|
28 | $ENV{'EDITOR'} = $current_editor;
|
---|
29 | print "Done\n";
|
---|
30 |
|
---|
31 | print "Complete!\n\n";
|
---|
32 |
|
---|
33 | exit;
|
---|