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

Annotation of /FigWebServices/seed_ctl.cgi

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3