[Bio] / FigKernelScripts / boot_cluster_seed.pl Repository:
ViewVC logotype

View of /FigKernelScripts/boot_cluster_seed.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (download) (as text) (annotate)
Mon Dec 5 18:56:37 2005 UTC (14 years, 6 months ago) by olson
Branch: MAIN
Changes since 1.3: +17 -0 lines
Add license words.

#
# 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.
#

#
# Boot up a cluster-node SEED server. We assume we are using
# mysql with a snapshotted database directory.
#
# 1. See if $FIG_Config::db_datadir exists.  If it does,
#    go to step 3.
#
# 2. Extract $FIG_Config::db_snapshot_file into $FIG_Config::db_datadir.
#
# 3. Start the database server using start_dbserver.
#
# 4. Source the SEED environment setup file.
#
# 5. Start an SGE execution daemon.
#
# 6. Spin sleeping until the file FIGdisk/config/cluster_shutdown is created.
#
# 7. Shut down the SGE exec daemon.
#
# 8. Shut down the database server.
#
# 9. Exit.
#

use strict;

use FIG;
use FIG_Config;

use File::Basename;

use LWP::UserAgent;

use Getopt::Long;

my $sge_only = 0;

$SIG{TERM} = \&shutdown_sig;
$SIG{INT} = \&shutdown_sig;
$SIG{HUP} = \&shutdown_sig;

our $sge_running = 0;
our $db_running = 0;

if (!GetOptions("sge-only" => \$sge_only))
{
    die "Usage: $0 [--sge-only]\n";
}

my $celldir = $FIG_Config::sge_cell_dir;
if (!defined($celldir))
{
    die "SGE cell directory not specified in FIG_Config::sge_cell_dir\n";
}
elsif (! -d $celldir)
{
    die "SGE cell directory $celldir not found\n";
}

#
# Step 1.
#


if (not $sge_only)
{
    if (-d $FIG_Config::db_datadir)
    {
	#
	# See if the size is right
	#
	
	my $sum = `cd $FIG_Config::db_datadir; ls -lR  | grep -v err | awk '{print \$5, \$8}'|md5sum | awk '{print \$1}'`;
	chomp($sum);

	print "Computed size as '$sum' want $FIG_Config::db_datadir_size\n";
	
	if ($sum != $FIG_Config::db_datadir_size)
	{
	    print "Removing invalid datadir \n";
	    system("rm -rf $FIG_Config::db_datadir");
	}
    }
    
    if (! -d $FIG_Config::db_datadir)
    {
	#
	# Step 2.
	#
	
	my $dir = dirname($FIG_Config::db_datadir);
	&FIG::verify_dir($dir);
	
	print "Extract db snapshot from $FIG_Config::db_snapshot_file to $dir\n";
	&FIG::run("cd $dir; tar xzfp $FIG_Config::db_snapshot_file");
    }
    
    if (! -d $FIG_Config::db_datadir)
    {
	die "After extract, data directory $FIG_Config::db_datadir does not exist\n";
    }
    
    #
    # Step 3.
    #
    
    &FIG::run("$FIG_Config::bin/start_dbserver");
    
    $db_running = 1;
    
    #
    # Wait a bit for the db to come up.
    #
    
    my $give_up = time + 10 * 60;
    my $ok;
    while (time < $give_up)
    {
	sleep 5;
	
	my $fig;
	eval {
	    $fig = new FIG;
	};

	if ($@)
	{
	    warn "Could not connect to database: $@\n";
	}
	else
	{
	    $ok = 1;
	    last;
	}
    }

    if (not $ok)
    {
	warn "Could not connect to database for ten minutes, giving up\n";
	shutdown_seed();
    }
}

#
# Step 4/5.
#

my $sge_cmd = "source $FIG_Config::fig_disk/config/fig-user-env.sh; $celldir/common/sgeexecd start";
warn "Starting sge: $sge_cmd\n";
my $rc = system($sge_cmd);
if ($rc != 0)
{
    warn "Return code $rc from attempt to start sge daemon\n";
    my $out = `ps auxw|grep sge_execd|grep -v grep`;
    if ($out !~ /sge_execd/)
    {
	warn "sge_execd process not found, quitting\n";
	shutdown_seed();
    }
}
$sge_running = 1;

#
# Step 6.
#
# Due to GPFS weirdness, we can't actually do this. Substitute a URL get.
#

if(0)
{
    while (! -f "$FIG_Config::fig_disk/config/cluster_shutdown")
    {
	sleep(1);
    }
}

my $ua = new LWP::UserAgent;
my $url = "http://tp-login1.uchicago.edu/~olson/cluster_shutdown";

while (1)
{
    my $resp = $ua->get($url);
    if ($resp->is_success())
    {
	last;
    }
    sleep 10;
}

print "Shutting down cluster node\n";

shutdown_seed();
exit(0);

sub shutdown_sig
{
    my($sig) = @_;
    print "Shutting down due to signal $sig\n";
    shutdown_seed();
}

sub shutdown_seed
{
    my($sig) = @_;
    #
    # Step 7.
    #

    if ($sge_running)
    {
	system("source $FIG_Config::fig_disk/config/fig-user-env.sh; $celldir/common/sgeexecd stop");
    }

    #
    # Step 8.
    #

    if ($db_running)
    {
	system("$FIG_Config::ext_bin/mysqladmin -u root shutdown");
    }

    exit(0);
}


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3