[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.5 - (download) (as text) (annotate)
Tue Jan 10 18:39:34 2006 UTC (13 years, 10 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, caBIG-05Apr06-00, 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, caBIG-13Feb06-00, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
Changes since 1.4: +43 -22 lines
more checksum fixes. need to replace the "ls -lR" hack with somethign that traverses the treein perl.

#
# 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;
if (not $FIG_Config::use_system_sge)
{
    $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 '*-bin.*' | grep -v err | awk '{print \$5, \$NF}'|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);

	my $snap = $FIG_Config::db_snapshot_file;

	if (! -f $snap)
	{
	    die "No database snapshot found!\n";
	}
	
	print "Extract db snapshot from $snap to $dir\n";

	my $tar_args = "xfp";
	
	if ($snap =~ /gz$/)
	{
	    $tar_args .= "z";
	}
	&FIG::run("cd $dir; tar $tar_args $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.
#

if ($celldir)
{
    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