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

View of /FigWebServices/seed_ctl.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (annotate)
Thu Apr 1 20:59:35 2004 UTC (16 years, 2 months ago) by olson
Branch: MAIN
Control panel.

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

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

use strict;

use POSIX;

use CGI;
my $cgi = new CGI;

use HTML;
my @html = ();

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

#
# Common dirs.
#

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

#
# 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 $child = fork;

    if (!$child)
    {
	#
	# In the child
	#

	POSIX::setsid();

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

	my $job_file = "$job_dir/$$";


	open(my $fh, ">$job_file");
	print $fh "Running $add\n";
	close($fh);

	open(my $fh, ">$down_file");
	print $fh "SEED server is rebuilding indexes.\n";
	print $fh "Running $add\n";
	close($fh);

	system($add);

	open my $fh, ">>$job_file";
	print $fh "Running $mkindex\n";
	close($fh);

	open my $fh, ">>$down_file";
	print $fh "Running $mkindex\n";
	close($fh);

	system($mkindex);

	unlink($job_file);
	unlink($down_file);
    }
}

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

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

#
# Check database
#

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

if (!$ok)
{
    push(@html, "Database system is unavailable.\n");
}
else
{
    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");
    }
}

#
# Check enabled state.
#

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


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 for background jobs.
#

&FIG::verify_dir($job_dir);

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

if (@jobs > 0)
{
    push(@html, $cgi->start_table({-border => 1}));

    push(@html, $cgi->TR($cgi->th(["Process", "Status", "Description","Action"])));

    for my $job (@jobs)
    {
	my($status, $but);
	
	if (kill(0, $job) > 0)
	{
	    $status = "Running";
	    $but = $cgi->submit(-value => "Kill process", -name => "kill_job_$job");
	}
	else
	{
	    $status = "Dead";
	    $but = $cgi->submit(-value => "Remove entry", -name => "delete_job_$job");
	}

	push(@html, $cgi->start_TR());
	push(@html, $cgi->td($job));
	push(@html, $cgi->td($status));

	open my $fh, "<$job_dir/$job";
	local $/;
	my $job_status = <$fh>;
	push(@html, $cgi->td($cgi->pre($job_status)));
	
	push(@html, $cgi->td($but));
	push(@html, $cgi->end_TR());
	push(@html, "\n");
	    
    }
    push(@html, $cgi->end_table());
}
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"));

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

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


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3