1 | #!/usr/bin/perl
|
---|
2 |
|
---|
3 | use strict;
|
---|
4 | use warnings;
|
---|
5 |
|
---|
6 | BEGIN
|
---|
7 | {
|
---|
8 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
9 | }
|
---|
10 |
|
---|
11 | # Pragma to autoflush STDOUT
|
---|
12 | $| = 1;
|
---|
13 |
|
---|
14 | if (!defined $ARGV[0])
|
---|
15 | {
|
---|
16 | &printUsage();
|
---|
17 | }
|
---|
18 | my $collection = $ARGV[0];
|
---|
19 | my $threads = 1;
|
---|
20 | if (defined $ARGV[1])
|
---|
21 | {
|
---|
22 | if ($ARGV[1] =~ /^\d+$/)
|
---|
23 | {
|
---|
24 | $threads = $ARGV[1];
|
---|
25 | }
|
---|
26 | else
|
---|
27 | {
|
---|
28 | &printUsage();
|
---|
29 | }
|
---|
30 | }
|
---|
31 | my $epoc = 100;
|
---|
32 | if (defined $ARGV[2])
|
---|
33 | {
|
---|
34 | if ($ARGV[2] =~ /^\d+$/)
|
---|
35 | {
|
---|
36 | $epoc = $ARGV[2];
|
---|
37 | }
|
---|
38 | else
|
---|
39 | {
|
---|
40 | &printUsage();
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | # Remove the current archives directory
|
---|
45 | `rm_archives.pl $collection`;
|
---|
46 |
|
---|
47 | # Flush the memory disk cache
|
---|
48 | `sync`;
|
---|
49 | # - save our current default editor
|
---|
50 | my $current_editor = $ENV{'EDITOR'};
|
---|
51 | # - replace default editor with a script that simply clobbers the contents
|
---|
52 | # of any file it's handed with the number "3"
|
---|
53 | $ENV{'EDITOR'} = 'reset_memcache_editor.sh';
|
---|
54 | # - we now call sudoedit on the system file. How sudoedit works is that it
|
---|
55 | # starts by making a temp copy of the system file with appropriate
|
---|
56 | # permissions allowing the user to edit. It then passes the path to the
|
---|
57 | # temp file to the default editor - typically this would be an interactive
|
---|
58 | # editor like 'vi'. However, we've just replaced the editor with a custom
|
---|
59 | # script that just writes '3' as the content of the tmp file. Finally, when
|
---|
60 | # the editor exits, sudoedit copies the tmp file over the top of the system
|
---|
61 | # file, restoring appropriate root-level permissions
|
---|
62 | `sudoedit /proc/sys/vm/drop_caches`;
|
---|
63 | # - restore the default editor, just in case something in Greenstone
|
---|
64 | # depends on this being a reasonable value
|
---|
65 | $ENV{'EDITOR'} = $current_editor;
|
---|
66 |
|
---|
67 | print "===== GS Import with MPSTAT Poll ====\n";
|
---|
68 |
|
---|
69 | # Forking children... get off my front lawn!
|
---|
70 | my $child_pid = fork();
|
---|
71 |
|
---|
72 | # Ensure fork() worked
|
---|
73 | if (!defined($child_pid))
|
---|
74 | {
|
---|
75 | die("Fork didn't.");
|
---|
76 | }
|
---|
77 |
|
---|
78 | # Parent process polls memory until child is done
|
---|
79 | if ($child_pid > 0)
|
---|
80 | {
|
---|
81 | print " - parent monitoring child process $child_pid\n";
|
---|
82 |
|
---|
83 | # Start polling for a fixed amount of time (4 minutes seems long enough)
|
---|
84 | my $timeout = 300;
|
---|
85 | my $polling_cmd = 'mpstat -P 0,1,2,3,4,5,6,7 1 ' . $timeout . ' > processor-' . $child_pid . '.log 2>&1';
|
---|
86 | `$polling_cmd`;
|
---|
87 | print "===== Complete! =====\n\n";
|
---|
88 | exit(0);
|
---|
89 | }
|
---|
90 | # Child process runs import command
|
---|
91 | else
|
---|
92 | {
|
---|
93 | print " - child process running GS import\n";
|
---|
94 |
|
---|
95 | my $import_cmd = 'taskset -c 1 import.pl -keepold -manifest manifest.xml -verbosity 0 ' . $collection . ' 2>&1';
|
---|
96 | if ($threads > 1)
|
---|
97 | {
|
---|
98 | $import_cmd = 'parallel_import.pl -removeold -verbosity 0 -epoch ' . $epoc . ' -jobs ' . $threads . ' ' . $collection . ' 2>&1';
|
---|
99 | }
|
---|
100 | print STDOUT "Starting Import: " . `date` . "\n";
|
---|
101 | my $result = `$import_cmd`;
|
---|
102 | print STDOUT "Ending Import: " . `date` . "\n";
|
---|
103 | print " - child complete: " . $result . "\n";
|
---|
104 | exit(0);
|
---|
105 | }
|
---|
106 |
|
---|
107 | # Doubt we'll ever get here, but who knows.
|
---|
108 | exit(0);
|
---|
109 |
|
---|
110 | sub printUsage
|
---|
111 | {
|
---|
112 | die("Usage: poll-processor.pl <collection> [<threads> [<epoc>]]\n");
|
---|
113 | }
|
---|
114 |
|
---|
115 | 1;
|
---|