[Bio] / FigWebServices / seed_ctl.cgi Repository:
ViewVC logotype

Annotation of /FigWebServices/seed_ctl.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (view) (download)

1 : olson 1.1 #
2 :     # SEED control panel.
3 :     #
4 :     # Functionality:
5 :     #
6 :     # Show info about this seed
7 :     # Enable / disable SEED
8 :     # Remake indexes
9 :     # Switch code versions
10 :     #
11 :    
12 :     use FIG;
13 :     #$FIG_Config::dbport =3000;
14 : olson 1.4 use JobScheduler;
15 : olson 1.1
16 :     use strict;
17 :    
18 : olson 1.3 use Text::Wrap;
19 : olson 1.1 use POSIX;
20 :    
21 :     use CGI;
22 :     my $cgi = new CGI;
23 :    
24 :     use HTML;
25 :     my @html = ();
26 : redwards 1.8 unshift @html, "<TITLE>The SEED Control Panel</TITLE>\n";
27 : olson 1.1
28 :     my $fig;
29 :     my $ok = eval {
30 :     $fig = new FIG;
31 :     };
32 :    
33 :     #
34 :     # Common dirs.
35 :     #
36 :    
37 :     my $job_dir = "$FIG_Config::data/Global/background_jobs";
38 :     my $down_file = "$FIG_Config::data/Global/why_down";
39 :    
40 :     #
41 :     # Handle actions first.
42 :     #
43 :    
44 :     if ($cgi->param('enable_server'))
45 :     {
46 :     push(@html, $cgi->p("Enabling server."));
47 :    
48 :    
49 :     unlink($down_file);
50 :     }
51 :     elsif ($cgi->param('disable_server'))
52 :     {
53 :     push(@html, $cgi->p("Disabling server."));
54 :    
55 :    
56 :     open my $fh, ">$down_file";
57 :     print $fh $cgi->param("disable_reason");
58 :     close($fh);
59 :     }
60 :     elsif ($cgi->param("rebuild_indexes"))
61 :     {
62 :     #
63 :     # Fork a process to run the rebuild scripts.
64 :     #
65 :    
66 : olson 1.3 my $add = "$FIG_Config::bin/add_assertions_of_function";
67 :     my $mkindex = "$FIG_Config::bin/make_indexes";
68 : olson 1.1
69 : olson 1.3 $fig->run_in_background(sub {
70 :    
71 :     print "Running $add\n";
72 :    
73 : olson 1.1 open(my $fh, ">$down_file");
74 :     print $fh "SEED server is rebuilding indexes.\n";
75 :     print $fh "Running $add\n";
76 :     close($fh);
77 : olson 1.3
78 : olson 1.1 system($add);
79 : olson 1.3
80 :     print "Running $mkindex\n";
81 :    
82 : olson 1.1 open my $fh, ">>$down_file";
83 :     print $fh "Running $mkindex\n";
84 :     close($fh);
85 : olson 1.3
86 : olson 1.1 system($mkindex);
87 : olson 1.3
88 :     print "Complete\n";
89 :    
90 : olson 1.1 unlink($down_file);
91 : olson 1.3 });
92 : olson 1.1 }
93 : redwards 1.6 elsif ($cgi->param("rebuild_subsys_conflicts"))
94 :     {
95 :     #
96 :     # Fork a process to rebuild the subsystem conflicts page
97 :     #
98 :    
99 :     # this should work but doesn't background, so we will do it differently
100 :     my $conflict = "$FIG_Config::bin/fig update_subsys_conflicts";
101 :    
102 :     $fig->run_in_background(sub {
103 :     print "Started updating the subsystem conflicts by running $conflict at ", scalar(localtime(time)), "\n";
104 :     system($conflict);
105 :     print "Finished updating the subsystem conflicts at ", scalar(localtime(time)), "\n";
106 :     });
107 :    
108 :     }
109 :    
110 : olson 1.1
111 :     #
112 :     # Check params list for other actions (that encode names within the param name).
113 :     #
114 :    
115 :     for my $action ($cgi->param)
116 :     {
117 :     if ($action =~ /^delete_job_(\d+)/)
118 :     {
119 : olson 1.2 system("rm -r $job_dir/$1");
120 : olson 1.1 push(@html, $cgi->p("Removed job $1"));
121 :     }
122 :     elsif ($action =~ /^kill_job_(\d+)/)
123 :     {
124 : olson 1.2 my $ret = kill(1, -$1);
125 :     push(@html, $cgi->p("Killed job $1; return code is $ret"));
126 : olson 1.1 }
127 :     }
128 :    
129 :     #
130 :     # Check database
131 :     #
132 :    
133 :     push(@html, $cgi->h1("SEED current status"));
134 : redwards 1.7 push(@html, $cgi->start_form(-action => "seed_ctl.cgi", -name=>"seed_ctl"));
135 : olson 1.1 push(@html, $cgi->h2("Database status"));
136 :    
137 :     if (!$ok)
138 :     {
139 :     push(@html, "Database system is unavailable.\n");
140 :     }
141 :     else
142 :     {
143 :     my $dbh = $fig->db_handle;
144 :    
145 :     my $resp = $dbh->SQL("SELECT count(*) from genome");
146 :     if (!$resp or @$resp == 0)
147 :     {
148 :     push(@html, "Could not get count from genome table\n");
149 :     }
150 :     else
151 :     {
152 :     my $c = $resp->[0]->[0];
153 :     push(@html, "Database live: found $c genomes\n");
154 :     }
155 :     }
156 :    
157 :     #
158 :     # Check enabled state.
159 :     #
160 :    
161 :     push(@html, $cgi->h2("SEED status"));
162 :    
163 : olson 1.3 my $uptime = `uptime`;
164 :     if ($uptime =~ /load average(s?):\s+(.*)/)
165 :     {
166 :     push(@html, "Server load averages: $2<p>\n");
167 :     }
168 : olson 1.1
169 :     if (-f $down_file)
170 :     {
171 :     my $down_text = `cat $down_file`;
172 :    
173 :     push(@html, $cgi->p("SEED server is down:"));
174 :     push(@html, $cgi->pre($down_text));
175 :     push(@html, $cgi->submit(-value => "Enable SEED server.", -name => "enable_server"));
176 :    
177 :     }
178 :     else
179 :     {
180 :     push(@html, $cgi->p("SEED server is up.\n"));
181 :     push(@html, $cgi->p("To disable SEED server, enter a reason below and click button."));
182 :     push(@html, $cgi->textarea(-name => "disable_reason",
183 :     -rows => 3, -cols => 70));
184 :     push(@html, $cgi->p);
185 :     push(@html, $cgi->submit(-value => "Disable SEED server.", -name => "disable_server"));
186 :     }
187 :    
188 :     push(@html, $cgi->hr);
189 :    
190 :     #
191 : olson 1.4 # Check the asynchronous job queue.
192 :     #
193 :    
194 : redwards 1.7 push(@html, "\n\n", $cgi->h2("Job scheduler queue"), "\n");
195 : olson 1.4
196 :     my $js = new JobScheduler;
197 : redwards 1.7
198 :     my @todel=$cgi->param('deletejob');
199 :     if (@todel) {
200 :     foreach my $del (@todel) {
201 :     my $res=$js->job_delete($del);
202 :     if ($res) {push @html, $cgi->p("Deleted $del\n")}
203 :     else {push @html, $cgi->p("Some problem deleting $del\n")}
204 :     }
205 :     }
206 :    
207 : olson 1.4 my @job_status = $js->get_status();
208 :     if (@job_status == 0)
209 :     {
210 : redwards 1.7 push(@html, $cgi->p("No jobs in queue\n"));
211 : olson 1.4 }
212 :     else
213 :     {
214 :     my @t = ();
215 :    
216 :     for my $jent (@job_status)
217 :     {
218 :     my($id, $code, $status) = @$jent;
219 :    
220 : redwards 1.7 push(@t, [$cgi->a({name => "job_$id"}, $id), $status, $cgi->checkbox(-name=>"deletejob", -value=>$id, -label=>'')]);
221 : olson 1.4 }
222 :    
223 : redwards 1.7 push(@html, &HTML::make_table(["Job ID", "Job status", "Delete Job"], \@t));
224 :     push(@html, $cgi->br, &HTML::java_buttons("seed_ctl", "deletejob"), $cgi->br, "\n");
225 : redwards 1.9 push(@html, "\n", $cgi->p,$cgi->submit("Delete Job(s)"), $cgi->reset, $cgi->p, "\n");
226 :     # GJO: I used to have an end form right here but I think it disables the buttons below. This is probably causing you all kinds of pain.
227 : olson 1.4 }
228 :    
229 :    
230 :     #
231 : olson 1.1 # Check for background jobs.
232 :     #
233 :    
234 :     &FIG::verify_dir($job_dir);
235 :    
236 :     push(@html, $cgi->h2("Background jobs"));
237 :     push(@html, "\n");
238 : olson 1.3
239 :     if ($cgi->param("show_output"))
240 :     {
241 :     my $job = $cgi->param("show_output");
242 :    
243 :     push(@html, $cgi->hr);
244 :    
245 :     push(@html, $cgi->h2("Job $job output"));
246 :     open(my $fh, "<$job_dir/$job/OUTPUT");
247 :     push(@html, "<pre>");
248 :    
249 :     while (<$fh>)
250 :     {
251 :     push(@html, $_);
252 :     }
253 :     close($fh);
254 :    
255 :     push(@html, "</pre>");
256 :     push(@html, $cgi->hr);
257 :     }
258 : olson 1.1 opendir(D, $job_dir);
259 :     my @jobs = grep { $_ =~ /^\d+$/ } readdir(D);
260 :    
261 :     if (@jobs > 0)
262 :     {
263 : olson 1.2 my @hdrs;
264 :     my $tbl = [];
265 : olson 1.1
266 : olson 1.2 @hdrs = ("Process", "Running", "Status", "Description", "Output", "Action");
267 : olson 1.1
268 :     for my $job (@jobs)
269 :     {
270 : olson 1.3 my($running, $status, $but, @output, $info, $output);
271 : redwards 1.5
272 :     my $color="#FFFFFF";
273 : olson 1.1 if (kill(0, $job) > 0)
274 :     {
275 : olson 1.2 $running = "Running";
276 : olson 1.1 $but = $cgi->submit(-value => "Kill process", -name => "kill_job_$job");
277 : redwards 1.5 $color="#FF0000";
278 : olson 1.1 }
279 :     else
280 :     {
281 : olson 1.2 $running = "Dead";
282 : redwards 1.6 $but = $cgi->checkbox(-label => "Remove entry", -name => "delete_job_$job");
283 : redwards 1.5 $color="#D3D3D3";
284 : olson 1.1 }
285 :    
286 : olson 1.2 $status = &FIG::file_read("$job_dir/$job/STATUS");
287 :     $info = &FIG::file_read("$job_dir/$job/INFO");
288 : olson 1.3 @output = &FIG::file_read("$job_dir/$job/OUTPUT");
289 :     my $outlink;
290 :    
291 :     if (@output > 10)
292 :     {
293 :     splice(@output, 0, @output - 10);
294 :     my $link = "seed_ctl.cgi?show_output=$job";
295 :     $outlink = "<a href=\"$link\">Show full output</a>\n";
296 :     }
297 : olson 1.2
298 : olson 1.3 $Text::Wrap::columns = 60;
299 :     $output = wrap('', '', @output);
300 :     $output = "<pre>$output\n</pre><br>$outlink\n";
301 : redwards 1.5 push(@$tbl, [$job, [$running, "td style=\"background: $color\""], $status, $info, $output, $but]);
302 : olson 1.1 }
303 : olson 1.2 push(@html, &HTML::make_table(\@hdrs, $tbl));
304 : redwards 1.6 push(@html, $cgi->submit("Process marked deletions"));
305 : olson 1.1 }
306 :     else
307 :     {
308 :     push(@html, $cgi->p("No background jobs running"));
309 :     }
310 :    
311 :     push(@html, $cgi->hr());
312 :    
313 :     #
314 :     # Actions support.
315 :     #
316 :    
317 :     push(@html, $cgi->h1("SEED actions"));
318 :    
319 :     #
320 :     # making indexes.
321 :     #
322 :    
323 :     push(@html, $cgi->h2("Indexes"));
324 :     push(@html, $cgi->p("Recreating indexes can take a while; the SEED server will be unavailable to users while it is running."));
325 : redwards 1.6 push(@html, $cgi->submit(-value => "Rebuild indexes", -name => "rebuild_indexes"), $cgi->p);
326 :     push(@html, $cgi->h2("Subsystem Conflicts"), $cgi->p("Rebuilding the subsystem conflicts will take a few minutes, but the SEED server will keep running"));
327 :     push(@html, $cgi->submit(-value => "Rebuild subsystem conflicts", -name => "rebuild_subsys_conflicts"), $cgi->p); # this will run fig update_subsys_conflicts
328 : olson 1.1
329 :     push(@html, $cgi->end_form);
330 :    
331 :     &HTML::show_page($cgi,\@html);
332 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3