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

Annotation of /FigWebServices/seed_ctl.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (view) (download)

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3