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

Annotation of /FigCommon/lwc_postprocess.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (view) (download) (as text)

1 : olson 1.1 #
2 : olson 1.5 # Copyright (c) 2003-2006 University of Chicago and Fellowship
3 :     # for Interpretations of Genomes. All Rights Reserved.
4 :     #
5 :     # This file is part of the SEED Toolkit.
6 :     #
7 :     # The SEED Toolkit is free software. You can redistribute
8 :     # it and/or modify it under the terms of the SEED Toolkit
9 :     # Public License.
10 :     #
11 :     # You should have received a copy of the SEED Toolkit Public License
12 :     # along with this program; if not write to the University of Chicago
13 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
14 :     # Genomes at veronika@thefig.info or download a copy from
15 :     # http://www.theseed.org/LICENSE.TXT.
16 :     #
17 :    
18 :     #
19 : olson 1.1 # This script is invoked after a lightweight code update has completed.
20 :     #
21 :     # It is used to kick the services scripts if they are running so that
22 :     # they pick up any new code.
23 :     #
24 :     # In addition, I anticipate this being the place to hook any per-module functionality
25 :     # that might need a post-lwc step. The scheme would probably be a module writes
26 :     # a file into FIG/var/lwc_post.d when it makes, and this script executes all of those scripts.
27 :     #
28 :    
29 :     use FIG_Config;
30 :     use strict;
31 :     use Errno qw(EEXIST EINVAL ESRCH EPERM);
32 :    
33 : olson 1.6 #
34 :     # If we have a monit config set, use that to restart services.
35 :     #
36 :    
37 :     if (defined(my $cfg = $FIG_Config::monit_config))
38 :     {
39 :     my $host = $cfg->{hostname};
40 :     my $file = $cfg->{config_file};
41 :    
42 :     my $this_host = `hostname -f`;
43 :     chomp $this_host;
44 :     if ($this_host eq $host)
45 :     {
46 :     print STDERR "Kicking monit\n";
47 :     my $rc = system("monit", "-c", $file, "restart", "all");
48 :     print STDERR "Restart had rc=$rc\n";
49 :     }
50 :     }
51 :     else
52 :     {
53 :     kick_services();
54 :     }
55 : olson 1.1
56 :     exit;
57 :    
58 :     sub kick_services
59 :     {
60 :     #
61 :     # This is more grossness because we don't have a generalized mechanism
62 :     # for registering services to be stopped and started. Must be coordinated
63 :     # with the startup/shutdown code in FigKernelScripts/start_services.pl and
64 :     # stop_services.pl.
65 :     #
66 :    
67 :     #
68 :     # Check to see if one of the services is running. If it is, invoke
69 :     # stop_services and start_services. Otherwise, don't bother as we
70 :     # don't want to start up services if they are currently stopped.
71 :     #
72 :     # We need to also check that the service is running as the same
73 :     # user that we are running as.
74 :     #
75 :    
76 :     my $pid_file = "$FIG_Config::fig_disk/config/seed_registration.pid";
77 :     if (not open(FH, "<$pid_file"))
78 :     {
79 :     #
80 :     # Not there. just return.
81 :     #
82 :    
83 :     return;
84 :     }
85 :    
86 :     my $pid = <FH>;
87 :     chop $pid;
88 :    
89 :     #
90 :     # Try a kill with signal 0 to see if the process exists and if we might
91 :     # be able to kill it.
92 :     #
93 :    
94 :     if (kill(0, $pid) == 1)
95 :     {
96 :     #
97 :     # We can do it. Do a stop/start services.
98 :     #
99 :     my $rc = system("$FIG_Config::bin/stop_services");
100 :     if ($rc != 0)
101 :     {
102 :     warn "lwc_postprocess: stop_services failed with rc=$rc\n";
103 :     }
104 :     else
105 :     {
106 : olson 1.2 #
107 :     # If we're running from a CGI, close STDIN and STDOUT to
108 :     # keep things from hanging.
109 :     #
110 :    
111 : olson 1.4 if (exists($ENV{SERVER_NAME}))
112 : olson 1.2 {
113 :     close(STDIN);
114 :     close(STDOUT);
115 : olson 1.3 close(STDERR);
116 : olson 1.2 }
117 :    
118 : olson 1.1 my $rc = system("$FIG_Config::bin/start_services");
119 :     if ($rc != 0)
120 :     {
121 :     warn "lwc_postprocess: start_services failed with rc=$rc\n";
122 :     }
123 :     }
124 :     }
125 :     else
126 :     {
127 :     if ($! == ESRCH)
128 :     {
129 :     warn "lwc_postprocess: service process not found, not restarting services.\n";
130 :     }
131 :     elsif ($! == EPERM)
132 :     {
133 :     warn "lwc_postprocess: services running as a different user, not restarting services.\n";
134 :     }
135 :     else
136 :     {
137 :     warn "lwc_postprocess: Unknown error probing for existing service: $!\n";
138 :     }
139 :     }
140 :    
141 :     }
142 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3