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

View of /FigWebServices/seed_ctl.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (download) (annotate)
Mon Oct 29 15:57:26 2007 UTC (12 years, 2 months ago) by olson
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, rast_rel_2008_06_18, myrast_rel40, rast_rel_2008_06_16, mgrast_dev_05262011, rast_rel_2008_12_18, mgrast_dev_04082011, rast_rel_2008_07_21, rast_rel_2010_0928, rast_2008_0924, mgrast_version_3_2, mgrast_dev_12152011, rast_rel_2008_04_23, mgrast_dev_06072011, rast_rel_2008_09_30, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_rel_2008_0625, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, rast_rel_2008_10_09, mgrast_dev_04012011, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, rast_rel_2009_07_09, rast_rel_2010_0827, mgrast_rel_2008_1110, myrast_33, rast_rel_2011_0928, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, mgrast_dev_04052011, mgrast_dev_02222011, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
Changes since 1.12: +7 -0 lines
add ability to disable just the control panel.

#
# Copyright (c) 2003-2006 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
#
# This file is part of the SEED Toolkit.
# 
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License. 
#
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info@ci.uchicago.edu or the Fellowship for Interpretation of
# Genomes at veronika@thefig.info or download a copy from
# http://www.theseed.org/LICENSE.TXT.
#

#
# SEED control panel.
#
# Functionality:
#
# Show info about this seed
# Enable / disable SEED
# Remake indexes
# Switch code versions
#

use FIG;
#$FIG_Config::dbport =3000;
use JobScheduler;

use strict;

use Text::Wrap;
use POSIX;

use CGI;
my $cgi = new CGI;

use HTML;
my @html = ();
unshift @html, "<TITLE>The SEED Control Panel</TITLE>\n";

my $fig;
eval {
    $fig = new FIG;
};

my $ok = !defined($?);

#
# Common dirs.
#

my $job_dir = "$FIG_Config::data/Global/background_jobs";
my $down_file = "$FIG_Config::data/Global/why_down";

if (-f "$FIG_Config::fig_disk/config/DISABLE_P2P")
{
    push(@html, "<p>Control panel is disabled on this system.");
    &HTML::show_page($cgi,\@html);
    exit(0);
}
    
if (-f "$FIG_Config::fig_disk/config/DISABLE_CTL")
{
    push(@html, "<p>Control panel is disabled on this system.");
    &HTML::show_page($cgi,\@html);
    exit(0);
}
    


#
# Handle actions first.
#

if ($cgi->param('enable_server'))
{
    push(@html, $cgi->p("Enabling server."));


    unlink($down_file);
}
elsif ($cgi->param('disable_server'))
{
    push(@html, $cgi->p("Disabling server."));


    open my $fh, ">$down_file";
    print $fh $cgi->param("disable_reason");
    close($fh);
}
elsif ($cgi->param("rebuild_indexes"))
{
    #
    # Fork a process to run the rebuild scripts.
    #

    my $add = "$FIG_Config::bin/add_assertions_of_function";
    my $mkindex = "$FIG_Config::bin/make_indexes";

    $fig->run_in_background(sub {
	
	print "Running $add\n";
	
	open(my $fh, ">$down_file");
	print $fh "SEED server is rebuilding indexes.\n";
	print $fh "Running $add\n";
	close($fh);
	
	system($add);
	
	print "Running $mkindex\n";
	
	open my $fh, ">>$down_file";
	print $fh "Running $mkindex\n";
	close($fh);
	
	system($mkindex);
	
	print "Complete\n";
	
	unlink($down_file);
    });
}
elsif ($cgi->param("rebuild_subsys_conflicts"))
{
    # 
    # Fork a process to rebuild the subsystem conflicts page
    #
    
    # this should work but doesn't background, so we will do it differently
    my $conflict = "$FIG_Config::bin/fig update_subsys_conflicts";
    
    $fig->run_in_background(sub {
	print "Started updating the subsystem conflicts by running $conflict at ", scalar(localtime(time)), "\n";
	system($conflict);
	print "Finished updating the subsystem conflicts at ", scalar(localtime(time)), "\n";
    });

}


#
# Check params list for other actions (that encode names within the param name).
#

for my $action ($cgi->param)
{
    if ($action =~ /^delete_job_(\d+)/)
    {
	system("rm -r $job_dir/$1");
	push(@html, $cgi->p("Removed job $1"));
    }
    elsif ($action =~ /^kill_job_(\d+)/)
    {
	my $ret = kill(1, -$1);
	push(@html, $cgi->p("Killed job $1; return code is $ret"));
    }
}

#
# Check database
#

push(@html, $cgi->h1("SEED current status"));
push(@html, $cgi->start_form(-action => "seed_ctl.cgi", -name=>"seed_ctl"));
push(@html, $cgi->h2("Database status"));

if (!$ok)
{
    push(@html, "Database system is unavailable.\n");
}
else
{
    eval {
	my $dbh = $fig->db_handle;

	my $resp = $dbh->SQL("SELECT count(*) from genome");
	if (!$resp or @$resp == 0)
	{
	    push(@html, "Could not get count from genome table\n");
	}
	else
	{
	    my $c = $resp->[0]->[0];
	    push(@html, "Database live: found $c genomes\n");
	}
    };
    if ($@)
    {
	push(@html, "Database system is unavailable.\n");
	$ok = 0;
    }
}

#
# Check enabled state.
#

push(@html, $cgi->h2("SEED status"));

my $uptime = `uptime`;
if ($uptime =~ /load average(s?):\s+(.*)/)
{
    push(@html, "Server load averages: $2<p>\n");
}

if (-f $down_file)
{
    my $down_text = `cat $down_file`;

    push(@html, $cgi->p("SEED server is down:"));
    push(@html, $cgi->pre($down_text));
    push(@html, $cgi->submit(-value => "Enable SEED server.", -name => "enable_server"));
    
}
else
{
    push(@html, $cgi->p("SEED server is up.\n"));
    push(@html, $cgi->p("To disable SEED server, enter a reason below and click button."));
    push(@html, $cgi->textarea(-name => "disable_reason",
			       -rows => 3, -cols => 70));
    push(@html, $cgi->p);
    push(@html, $cgi->submit(-value => "Disable SEED server.", -name => "disable_server"));
}

push(@html, $cgi->hr);

#
# Check the asynchronous job queue.
#

push(@html, "\n\n", $cgi->h2("Job scheduler queue"), "\n");

my $js = new JobScheduler;

my @todel=$cgi->param('deletejob');
if (@todel) { 
 foreach my $del (@todel) {
  my $res=$js->job_delete($del);
  if ($res) {push @html, $cgi->p("Deleted $del\n")}
  else {push @html, $cgi->p("Some problem deleting $del\n")}
 }
}

my @job_status = $js->get_status();
if (@job_status == 0)
{
    push(@html, $cgi->p("No jobs in queue\n"));
}
else
{
    my @t = ();

    for my $jent (@job_status)
    {
	my($id, $code, $status) = @$jent;

	push(@t, [$cgi->a({name => "job_$id"}, $id), $status, $cgi->checkbox(-name=>"deletejob", -value=>$id, -label=>'')]);
    }

    push(@html, &HTML::make_table(["Job ID", "Job status", "Delete Job"], \@t));
    push(@html, $cgi->br, &HTML::java_buttons("seed_ctl", "deletejob"), $cgi->br, "\n");
    push(@html, "\n", $cgi->p,$cgi->submit("Delete Job(s)"), $cgi->reset, $cgi->p, "\n"); 
 	# 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.
}


#
# Check for background jobs.
#

&FIG::verify_dir($job_dir);

push(@html, $cgi->h2("Background jobs"));
push(@html, "\n");

if ($cgi->param("show_output"))
{
    my $job = $cgi->param("show_output");

    push(@html, $cgi->hr);

    push(@html, $cgi->h2("Job $job output"));
    open(my $fh, "<$job_dir/$job/OUTPUT");
    push(@html, "<pre>");
    
    while (<$fh>)
    {
	push(@html, $_);
    }
    close($fh);

    push(@html, "</pre>");
    push(@html, $cgi->hr);
}
opendir(D, $job_dir);
my @jobs = grep { $_ =~ /^\d+$/ } readdir(D);

if (@jobs > 0)
{
    my @hdrs;
    my $tbl = [];

    @hdrs = ("Process", "Running", "Status", "Description", "Output", "Action");

    for my $job (@jobs)
    {
	my($running, $status, $but, @output, $info, $output);
        
	my $color="#FFFFFF";
	if (kill(0, $job) > 0)
	{
	    $running = "Running";
	    $but = $cgi->submit(-value => "Kill process", -name => "kill_job_$job");
	    $color="#FF0000";
	}
	else
	{
	    $running = "Dead";
	    $but = $cgi->checkbox(-label => "Remove entry", -name => "delete_job_$job");
	    $color="#D3D3D3";
	}

	$status = &FIG::file_read("$job_dir/$job/STATUS");
	$info = &FIG::file_read("$job_dir/$job/INFO");
	@output = &FIG::file_read("$job_dir/$job/OUTPUT");
	my $outlink;

	if (@output > 10)
	{
	    splice(@output, 0, @output - 10);
	    my $link = "seed_ctl.cgi?show_output=$job";
	    $outlink = "<a href=\"$link\">Show full output</a>\n";
	}

	$Text::Wrap::columns = 60;
	$output = wrap('', '', @output);
	$output = "<pre>$output\n</pre><br>$outlink\n";
	push(@$tbl, [$job, [$running, "td style=\"background: $color\""], $status, $info, $output, $but]);
    }
    push(@html, &HTML::make_table(\@hdrs, $tbl));
    push(@html, $cgi->submit("Process marked deletions"));
}
else
{
    push(@html, $cgi->p("No background jobs running"));
}

push(@html, $cgi->hr());

#
# Actions support.
#

push(@html, $cgi->h1("SEED actions"));

#
# making indexes.
#

push(@html, $cgi->h2("Indexes"));
push(@html, $cgi->p("Recreating indexes can take a while; the SEED server will be unavailable to users while it is running."));
push(@html, $cgi->submit(-value => "Rebuild indexes", -name => "rebuild_indexes"), $cgi->p);
push(@html, $cgi->h2("Subsystem Conflicts"), $cgi->p("Rebuilding the subsystem conflicts will take a few minutes, but the SEED server will keep running"));
push(@html, $cgi->submit(-value => "Rebuild subsystem conflicts", -name => "rebuild_subsys_conflicts"), $cgi->p); # this will run fig update_subsys_conflicts

push(@html, $cgi->end_form);

&HTML::show_page($cgi,\@html);


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3