Parent Directory
|
Revision Log
Revision 1.2 - (view) (download) (as text)
1 : | parrello | 1.1 | #!/usr/bin/perl -w |
2 : | |||
3 : | # | ||
4 : | # Copyright (c) 2003-2006 University of Chicago and Fellowship | ||
5 : | # for Interpretations of Genomes. All Rights Reserved. | ||
6 : | # | ||
7 : | # This file is part of the SEED Toolkit. | ||
8 : | # | ||
9 : | # The SEED Toolkit is free software. You can redistribute | ||
10 : | # it and/or modify it under the terms of the SEED Toolkit | ||
11 : | # Public License. | ||
12 : | # | ||
13 : | # You should have received a copy of the SEED Toolkit Public License | ||
14 : | # along with this program; if not write to the University of Chicago | ||
15 : | # at info@ci.uchicago.edu or the Fellowship for Interpretation of | ||
16 : | # Genomes at veronika@thefig.info or download a copy from | ||
17 : | # http://www.theseed.org/LICENSE.TXT. | ||
18 : | # | ||
19 : | |||
20 : | =head1 NMPDR Emergency Switch | ||
21 : | |||
22 : | This method will rename files in the HTML root of the NMPDR website in order | ||
23 : | to bring the NMPDR up or down. While it is down, the main page will redirect | ||
24 : | users to the backup copy of NMPDR (the "mirror site"). The single | ||
25 : | command-line parameter should be C<off> to turn the NMPDR off (redirecting | ||
26 : | users to the backup web site) or C<on> to turn it back on. | ||
27 : | |||
28 : | The currently-supported command-line options are as follows. | ||
29 : | |||
30 : | =over 4 | ||
31 : | |||
32 : | =item user | ||
33 : | |||
34 : | Name suffix to be used for log files. If omitted, the PID is used. | ||
35 : | |||
36 : | =item trace | ||
37 : | |||
38 : | Numeric trace level. A higher trace level causes more messages to appear. The | ||
39 : | default trace level is 2. Tracing will be directly to the standard output | ||
40 : | as well as to a C<trace>I<User>C<.log> file in the FIG temporary directory, | ||
41 : | where I<User> is the value of the B<user> option above. | ||
42 : | |||
43 : | =item sql | ||
44 : | |||
45 : | If specified, turns on tracing of SQL activity. | ||
46 : | |||
47 : | =item background | ||
48 : | |||
49 : | Save the standard and error output to files. The files will be created | ||
50 : | in the FIG temporary directory and will be named C<err>I<User>C<.log> and | ||
51 : | C<out>I<User>C<.log>, respectively, where I<User> is the value of the | ||
52 : | B<user> option above. | ||
53 : | |||
54 : | =item h | ||
55 : | |||
56 : | Display this command's parameters and options. | ||
57 : | |||
58 : | =item phone | ||
59 : | |||
60 : | Phone number to message when the script is complete. | ||
61 : | |||
62 : | =back | ||
63 : | |||
64 : | =cut | ||
65 : | |||
66 : | use strict; | ||
67 : | use Tracer; | ||
68 : | use Cwd; | ||
69 : | use File::Copy; | ||
70 : | use File::Path; | ||
71 : | |||
72 : | # Get the command-line options and parameters. | ||
73 : | my ($options, @parameters) = StandardSetup([qw() ], | ||
74 : | { | ||
75 : | phone => ["", "phone number (international format) to call when load finishes"], | ||
76 : | }, | ||
77 : | "<on or off>", | ||
78 : | @ARGV); | ||
79 : | # Set a variable to contain return type information. | ||
80 : | my $rtype; | ||
81 : | # Insure we catch errors. | ||
82 : | eval { | ||
83 : | # Compute the names of the relevant files: index, indexDown, and indexUp. | ||
84 : | my ($indexFileName, $downFileName, $upFileName) = map { "$FIG_Config::nmpdr_pages/index$_.php"} ("", "Down", "Up"); | ||
85 : | # Check the command-line parameter. | ||
86 : | my $onOff = $parameters[0]; | ||
87 : | if (lc($onOff) eq 'off') { | ||
88 : | # Here the user wants to turn the NMPDR off. We do this by renaming index to indexUp, then | ||
89 : | # indexDown to index. If indexDown does not exist, the system is already down. | ||
90 : | if (! -e $downFileName) { | ||
91 : | Confess("$downFileName not found: the NMPDR is probably already down."); | ||
92 : | } else { | ||
93 : | Trace("Renaming index file.") if T(2); | ||
94 : | rename $indexFileName, $upFileName; | ||
95 : | Trace("Creating new index file.") if T(2); | ||
96 : | rename $downFileName, $indexFileName; | ||
97 : | Trace("The NMPDR is now offline.") if T(2); | ||
98 : | } | ||
99 : | } elsif (lc($onOff) eq 'on') { | ||
100 : | # Here the user wants to turn the NMPDR back on. We do this by renaming index to indexDown, | ||
101 : | # then indexUp to index. If indexUp does not exist, the system is already up. | ||
102 : | if (! -e $upFileName) { | ||
103 : | Confess("$upFileName not found: the NMPDR is probably already up."); | ||
104 : | } else { | ||
105 : | Trace("Renaming index file.") if T(2); | ||
106 : | rename $indexFileName, $downFileName; | ||
107 : | Trace("Creating new index file.") if T(2); | ||
108 : | rename $upFileName, $indexFileName; | ||
109 : | Trace("The NMPDR is now online.") if T(2); | ||
110 : | } | ||
111 : | } else { | ||
112 : | Confess("Unrecognized option \"$onOff\"."); | ||
113 : | } | ||
114 : | |||
115 : | }; | ||
116 : | if ($@) { | ||
117 : | Trace("Script failed with error: $@") if T(0); | ||
118 : | $rtype = "error"; | ||
119 : | } else { | ||
120 : | Trace("Script complete.") if T(2); | ||
121 : | $rtype = "no error"; | ||
122 : | } | ||
123 : | if ($options->{phone}) { | ||
124 : | my $msgID = Tracer::SendSMS($options->{phone}, "NMPDR Emergency Switch terminated with $rtype."); | ||
125 : | if ($msgID) { | ||
126 : | Trace("Phone message sent with ID $msgID.") if T(2); | ||
127 : | } else { | ||
128 : | Trace("Phone message not sent.") if T(2); | ||
129 : | } | ||
130 : | } | ||
131 : | |||
132 : | 1; |
MCS Webmaster | ViewVC Help |
Powered by ViewVC 1.0.3 |