[Bio] / FigCommon / lwc_postprocess.pl Repository:
ViewVC logotype

View of /FigCommon/lwc_postprocess.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (download) (as text) (annotate)
Mon Nov 25 19:51:32 2013 UTC (6 years, 7 months ago) by olson
Branch: MAIN
CVS Tags: rast_rel_2014_0912, rast_rel_2014_0729, lwc, HEAD
Changes since 1.7: +0 -5 lines
remove sleep again now we've fixed the real problem

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

#
# This script is invoked after a lightweight code update has completed.
#
# It is used to kick the services scripts if they are running so that
# they pick up any new code.
#
# In addition, I anticipate this being the place to hook any per-module functionality
# that might need a post-lwc step. The scheme would probably be a module writes
# a file into FIG/var/lwc_post.d when it makes, and this script executes all of those scripts.
#

use FIG_Config;
use strict;
use Errno qw(EEXIST EINVAL ESRCH EPERM);

#
# If we have a monit config set, use that to restart services.
#

if (defined(my $cfg = $FIG_Config::monit_config))
{
    my $host = $cfg->{hostname};
    my $file = $cfg->{config_file};

    my $this_host = `hostname -f`;
    chomp $this_host;
    if ($this_host eq $host)
    {
	print STDERR "Kicking monit\n";
	my $rc = system("monit", "-c", $file, "restart", "all");
	print STDERR "Restart had rc=$rc\n";
    }
}
else
{
    kick_services();
}

exit;

sub kick_services
{
    #
    # This is more grossness because we don't have a generalized mechanism
    # for registering services to be stopped and started. Must be coordinated
    # with the startup/shutdown code in FigKernelScripts/start_services.pl and
    # stop_services.pl.
    #

    #
    # Check to see if one of the services is running. If it is, invoke
    # stop_services and start_services. Otherwise, don't bother as we
    # don't want to start up services if they are currently stopped.
    #
    # We need to also check that the service is running as the same
    # user that we are running as. 
    #

    my $pid_file  = "$FIG_Config::fig_disk/config/seed_registration.pid";
    if (not open(FH, "<$pid_file"))
    {
	#
	# Not there. just return.
	#

	return;
    }

    my $pid = <FH>;
    chop $pid;

    #
    # Try a kill with signal 0 to see if the process exists and if we might
    # be able to kill it.
    #

    if (kill(0, $pid) == 1)
    {
	#
	# We can do it. Do a stop/start services.
	#
	my $rc = system("$FIG_Config::bin/stop_services");
	if ($rc != 0)
	{
	    warn "lwc_postprocess: stop_services failed with rc=$rc\n";
	}
	else
	{
	    #
	    # If we're running from a CGI, close  STDIN and STDOUT to
	    # keep things from hanging.
	    #

	    if (exists($ENV{SERVER_NAME}))
	    {
		close(STDIN);
		close(STDOUT);
		close(STDERR);
	    }
	       
	    my $rc = system("$FIG_Config::bin/start_services");
	    if ($rc != 0)
	    {
		warn "lwc_postprocess: start_services failed with rc=$rc\n";
	    }
	}
    }
    else
    {
	if ($! == ESRCH)
	{
	    warn "lwc_postprocess: service process not found, not restarting services.\n";
	}
	elsif ($! == EPERM)
	{
	    warn "lwc_postprocess: services running as a different user, not restarting services.\n";
	}
	else
	{
	    warn "lwc_postprocess: Unknown error probing for existing service: $!\n";
	}
    }

}


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3