Skip to content

Commit 3a743a1

Browse files
committed
server: Misc changes necessary to port to AWS from IU servers
* cherrypy: Disable global trial flag * Switch postgres serialization option from depricated value * reporter: PHP 7 replace split * CherryPy misc - Add a Get for the /submit interface for debugging - Some documentation in the main MTTServer.py * Rename config script to template so we don't accidentally commit it * Add date string to debug output * Add downtime pages, for quick reference * Add a helpful error message when gunzip fails * Move to using a config file for the cron perl scripts (Add tmpl) Signed-off-by: Joshua Hursey <[email protected]>
1 parent 74bcfff commit 3a743a1

21 files changed

+678
-170
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
*\\#
22
server/mtt_config.php
3+
server/php/config.inc
34
server/php/stats/mtt-contrib.pdf
45
server/php/stats/mtt-contrib-1year.pdf
56
server/php/tmp/*.csv
67
server/php/tmp/*.png
78
server/php/cron/mtt-update-stats-db-only-output.txt
89
server/php/cron/mtt-update-stats-output.txt
10+
server/php/cron/config.ini
911
server/php/favicon.ico
1012
server/php/robots.txt
1113
server/php/stats/php_errors.log
1214
server/php/submit/php_errors.log
15+
server/php/submit/cpy
1316
*.pyc
1417
*.bak
1518
.DS_Store

server/php/cherrypy/src/MTTServer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ def _restart_handler(signal, frame):
6363
'log.access_file': '../log/access.log',
6464
'log.error_file': '../log/cherrypy_error.log',
6565
'log.screen': False,
66+
# Autoreload is very useful when debugging or updating frequently
67+
# It will notice when any of the server files have been updated
68+
# and reboot the server. Disable it during production runs
69+
# as the continual overhead will accure CPU time.
6670
'engine.autoreload.on': False,
6771

6872
# Don't run CherryPy Checker on custom conf sections:

server/php/cherrypy/src/webapp/db_pgv3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@
260260
class DatabaseV3():
261261
_name = '[DB PG V3]'
262262

263-
_force_trial = True
263+
_force_trial = False
264264

265265
def __init__(self, logger, auth):
266266
self._auth = auth

server/php/cherrypy/src/webapp/dispatchers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def _validate_test_run(self, submit_id, metadata, data):
255255
return None
256256

257257
#
258-
# GET / : Server status
258+
# GET /submit/ : Server status
259259
#
260260
@cherrypy.tools.json_out()
261261
def GET(self, **kwargs):
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,9 @@ $mtt_http_password = rtrim(file_get_contents("/home/mpiteam/www-not-in-docroot/m
6060

6161
# Where to render graphs? Must be writable by the web server.
6262
$mtt_graph_tmp_dir = "tmp";
63+
64+
# Where to log detailed reports on server failures
65+
$mtt_err_log_file = "/mnt/data/mtt.open-mpi.org/log/mtt-php-errors.log";
66+
67+
# TMP dir to use when unpacking submission posts
68+
$mtt_submit_tmp_dir = "/tmp";

server/php/cron/alerts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#
4141
# Includes
4242
#
43-
$topdir = "/l/osl/www/mtt.open-mpi.org/mtt/server/php";
43+
$topdir = "/mnt/data/mtt.open-mpi.org/mtt/server/php";
4444
include_once("$topdir/curl_get.inc");
4545
include_once("$topdir/ini.inc");
4646
include_once("$topdir/reporter/reporter.inc");

server/php/cron/config.ini.tmpl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[database]
2+
user = USERNAME
3+
# Can use "run(cat /path/to/my/file/mtt-db-password.txt)"
4+
password = PASSWORD
5+
hostname = HOSTNAME
6+
port = 5432
7+
dbname = DATABASENAME
8+
9+
[reporting]
10+
to_email = EMAIL@ADDRRESS
11+
from_email = EMAIL@ADDRRESS
12+
13+
[stats]
14+
# MTT Working Dir to find scripts
15+
base_dir = "/path_to/cron/"
16+
# Directory containing scripts to execute
17+
working_dir = "/path_to/cron/stats"
18+
# Directory to place the contribution graph
19+
output_dir = "/path_to/stats/"
20+
# Temporary directory to store data files
21+
tmp_dir = "/tmp/"

server/php/cron/create-contrib-graph.pl

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@
22

33
use strict;
44
use Env qw(HOME PATH USER);
5+
use Config::IniFiles;
56

67
#
78
# Script requires the following software packages installed:
89
# - psql (with access to the mtt database)
910
# - gnuplot (with postscript terminal)
1011
# - ps2pdf
1112
#
12-
13-
# Directory containing scripts to execute
14-
my $working_dir = "/l/osl/www/mtt.open-mpi.org/mtt/server/php/cron/stats";
15-
# Directory to place the contribution graph
16-
my $output_dir = "/l/osl/www/mtt.open-mpi.org/mtt/server/php/stats/";
17-
# Temporary directory to store data files
18-
my $tmp_dir = "/tmp/";
13+
my $config_filename = "config.ini";
14+
my $ini_section;
1915

2016
my $cmd;
2117

@@ -40,6 +36,25 @@
4036
exit -1;
4137
}
4238

39+
my $ini = new Config::IniFiles(-file => $config_filename,
40+
-nocase => 1,
41+
-allowcontinue => 1);
42+
if( !$ini ) {
43+
print "Error: Failed to read: $config_filename\n";
44+
exit 1;
45+
}
46+
47+
# Check the contents of the config file
48+
check_ini_section($ini, "stats", ("working_dir", "output_dir", "tmp_dir") );
49+
50+
$ini_section = "stats";
51+
# Directory containing scripts to execute
52+
my $working_dir = resolve_value($ini, $ini_section, "working_dir");
53+
# Directory to place the contribution graph
54+
my $output_dir = resolve_value($ini, $ini_section, "output_dir");
55+
# Temporary directory to store data files
56+
my $tmp_dir = resolve_value($ini, $ini_section, "tmp_dir");
57+
4358
if(!chdir($working_dir) ) {
4459
print "Error: Cannot chdir to <$working_dir>\n";
4560
exit(-1);
@@ -61,6 +76,7 @@
6176
#
6277
# Gather the raw data
6378
#
79+
6480
$cmd = "./make-raw-data.pl -year ".$extra_cmd_line_arg." > ".$tmp_dir.$data_file_year;
6581
if(0 != system($cmd) ) {
6682
print "Error: Cannot exec the command <$cmd>\n";
@@ -139,6 +155,15 @@ ()
139155
elsif( $ARGV[$i] eq "-l" ) {
140156
$is_limited_to_one_year = "t";
141157
}
158+
elsif( $ARGV[$i] =~ /-config/ ) {
159+
$i++;
160+
if( $i < $argc ) {
161+
$config_filename = $ARGV[$i];
162+
} else {
163+
print_update("Error: -config requires a file argument\n");
164+
return -1;
165+
}
166+
}
142167
#
143168
# Invalid options produce a usage message
144169
#
@@ -158,3 +183,49 @@ ()
158183

159184
return 0;
160185
}
186+
187+
188+
sub resolve_value() {
189+
my $ini = shift(@_);
190+
my $section = shift(@_);
191+
my $key = shift(@_);
192+
my $value;
193+
194+
$value = $ini->val($section, $key);
195+
if( !defined($value) ) {
196+
print "Error: Failed to find \"$key\" in section \"$section\"\n";
197+
exit 1;
198+
}
199+
$value =~ s/^\"//;
200+
$value =~ s/\"$//;
201+
202+
if( $value =~ /^run/ ) {
203+
$value = $';
204+
$value =~ s/^\(//;
205+
$value =~ s/\)$//;
206+
$value = `$value`;
207+
chomp($value);
208+
}
209+
210+
return $value;
211+
}
212+
213+
sub check_ini_section() {
214+
my $ini = shift(@_);
215+
my $section = shift(@_);
216+
my @keys = @_;
217+
218+
if( !$ini->SectionExists($section) ) {
219+
print "Error: INI file does not contain a $section field\n";
220+
exit 1;
221+
}
222+
223+
foreach my $key (@keys) {
224+
if( !$ini->exists($section, $key) ) {
225+
print "Error: INI file missing $section key named $key\n";
226+
exit 1;
227+
}
228+
}
229+
230+
return 0;
231+
}

server/php/cron/crontab.dump

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Note UTC is +4 from US EST
2+
#### MTT ################
3+
# Update MTT Statistics [Database]
4+
# - everyday at 11:00 pm EST (3 am UTC)
5+
# - runs in about 1 min
6+
#########################
7+
0 3 * * * (cd /mnt/data/mtt.open-mpi.org/mtt/server/php/cron/ && ./mtt-update-stats-db-only.pl )
8+
9+
#### MTT ################
10+
# Update MTT Statistics [Contribution]
11+
# - everyday at 1 am EST (5 am UTC)
12+
# - runs in about 2 hours
13+
#########################
14+
0 5 * * * (cd /mnt/data/mtt.open-mpi.org/mtt/server/php/cron/ && ./mtt-update-stats.pl )
15+
16+
#### MTT ################
17+
# Update Contrib Graphs
18+
# - Everyday at 3 am EST (7 am UTC)
19+
# "-l" limits to just last year of data. (faster to run)
20+
#########################
21+
# Runs in < 1 min
22+
0 7 * * * (cd /mnt/data/mtt.open-mpi.org/mtt/server/php/cron/ && ./create-contrib-graph.pl -l )
23+
# Runs in about 45 minutes
24+
30 7 * * * (cd /mnt/data/mtt.open-mpi.org/mtt/server/php/cron/ && ./create-contrib-graph.pl )
25+
26+
#### MTT ################
27+
# Maintain internal PostgreSQL stats (Week)
28+
# - Sunday at 4 am EST (8 am UTC)
29+
# - runs in about 30 min
30+
#########################
31+
0 8 * * 0 (cd /mnt/data/mtt.open-mpi.org/mtt/server/php/cron/ && ./periodic-maintenance.pl -week 1> /dev/null 2> /dev/null )
32+
33+
#### MTT ################
34+
# Maintain internal PostgreSQL stats (Year)
35+
# - Dec. 1 at 4 am EST (8 am EST)
36+
# - runs in about 6 hours (?? Verify)
37+
#########################
38+
0 8 1 12 * (cd /mnt/data/mtt.open-mpi.org/mtt/server/php/cron/ && ./periodic-maintenance.pl -year 1> /dev/null 2> /dev/null )
39+
40+
#### MTT ################
41+
# Email Reports
42+
# - Tues - Thursday at 9 am (Past 12 hours) (1 pm UTC)
43+
# - Tues - Thursday at 9 pm (Past 24 hours) (1 am UTC)
44+
# - Monday at 9 am (Past 60 hours) (1 pm UTC)
45+
#########################
46+
0 13 * * 2-4 /mnt/data/mtt.open-mpi.org/mtt/server/php/cron/alerts.php -f /mnt/data/mtt.open-mpi.org/mtt/server/php/cron/morning.ini 1> /dev/null 2> /dev/null
47+
0 1 * * 2-4 /mnt/data/mtt.open-mpi.org/mtt/server/php/cron/alerts.php -f /mnt/data/mtt.open-mpi.org/mtt/server/php/cron/evening.ini 1> /dev/null 2> /dev/null
48+
0 13 * * 1 /mnt/data/mtt.open-mpi.org/mtt/server/php/cron/alerts.php -f /mnt/data/mtt.open-mpi.org/mtt/server/php/cron/monday.ini 1> /dev/null 2> /dev/null

server/php/cron/ic-check.pl

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use DBI;
1111
use Mail::Sendmail;
1212
use Class::Struct;
13+
use Config::IniFiles;
1314

1415
# Flush I/O frequently
1516
$| = 1;
@@ -18,10 +19,32 @@
1819
my $debug;
1920
my $debug_no_email;
2021

21-
#my $to_email_address = "FILL THIS IN";
22-
#my $from_email_address = "FILL THIS IN";
23-
my $to_email_address = "mtt-devel-core\@lists.open-mpi.org";
24-
my $from_email_address = "mtt-devel-core\@lists.open-mpi.org";
22+
my $config_filename = "config.ini";
23+
my $ini_section;
24+
my $ini = new Config::IniFiles(-file => $config_filename,
25+
-nocase => 1,
26+
-allowcontinue => 1);
27+
if( !$ini ) {
28+
print "Error: Failed to read: $config_filename\n";
29+
exit 1;
30+
}
31+
# Check the contents of the config file
32+
check_ini_section($ini, "database", ("user", "password", "hostname", "port", "dbname") );
33+
check_ini_section($ini, "reporting", ("to_email", "from_email") );
34+
35+
# Read in config entries
36+
$ini_section = "database";
37+
my $mtt_user = resolve_value($ini, $ini_section, "user");;
38+
my $mtt_pass = resolve_value($ini, $ini_section, "password");
39+
my $mtt_hostname = resolve_value($ini, $ini_section, "hostname");
40+
my $mtt_port = resolve_value($ini, $ini_section, "port");
41+
my $mtt_dbname = resolve_value($ini, $ini_section, "dbname");
42+
43+
$ini_section = "reporting";
44+
my $to_email_address = resolve_value($ini, $ini_section, "to_email");
45+
my $from_email_address = resolve_value($ini, $ini_section, "from_email");
46+
47+
# Static values
2548
my $current_mail_subject = "MTT Database Maintenance: IC Check";
2649
my $current_mail_header = "";
2750
my $current_mail_body = "";
@@ -210,10 +233,9 @@ ()
210233
}
211234

212235
sub connect_db() {
213-
my $mtt_user = "mtt";
214236
my $stmt;
215237

216-
$dbh_mtt = DBI->connect("dbi:Pg:dbname=mtt", $mtt_user);
238+
$dbh_mtt = DBI->connect("dbi:Pg:dbname=".$mtt_dbname.";host=".$mtt_hostname.";port=".$mtt_port, $mtt_user, $mtt_pass);
217239

218240
$stmt = $dbh_mtt->prepare("set sort_mem = '512MB'");
219241
$stmt->execute();
@@ -321,3 +343,48 @@ ()
321343

322344
return 0;
323345
}
346+
347+
sub resolve_value() {
348+
my $ini = shift(@_);
349+
my $section = shift(@_);
350+
my $key = shift(@_);
351+
my $value;
352+
353+
$value = $ini->val($section, $key);
354+
if( !defined($value) ) {
355+
print "Error: Failed to find \"$key\" in section \"$section\"\n";
356+
exit 1;
357+
}
358+
$value =~ s/^\"//;
359+
$value =~ s/\"$//;
360+
361+
if( $value =~ /^run/ ) {
362+
$value = $';
363+
$value =~ s/^\(//;
364+
$value =~ s/\)$//;
365+
$value = `$value`;
366+
chomp($value);
367+
}
368+
369+
return $value;
370+
}
371+
372+
sub check_ini_section() {
373+
my $ini = shift(@_);
374+
my $section = shift(@_);
375+
my @keys = @_;
376+
377+
if( !$ini->SectionExists($section) ) {
378+
print "Error: INI file does not contain a $section field\n";
379+
exit 1;
380+
}
381+
382+
foreach my $key (@keys) {
383+
if( !$ini->exists($section, $key) ) {
384+
print "Error: INI file missing $section key named $key\n";
385+
exit 1;
386+
}
387+
}
388+
389+
return 0;
390+
}

0 commit comments

Comments
 (0)