dbboot.in 2.19 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl -wT
use English;

#
# Boottime cleanup of the DB. A series of specialize commands that are
# likely yo get out of synch with reality!
# 

#
# Configure variables
#
my $TB		= "@prefix@";
my $TBOPS       = "@TBOPSEMAIL@";

# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/site/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

#
# Turn off line buffering on output
#
$| = 1; 

# Load the Testbed support stuff.
use lib "@prefix@/lib";
use libdb;
use libtestbed;

#
# Only real root can call this.
# 
if ($UID != 0) {
    print STDERR "You must be root to run this script!\n";
    exit(-1);
}

#
# Form a temp name.
#
40
my $logname = TBMakeLogname("dbboot");
41
42
43
44
45
46
47
48
49
50
51
52
53
54

#
# Reopen both stdout and stderr so that we can record all the output for
# later mailing.
# 
open(STDERR, ">> $logname") or die("opening $logname for STDERR: $!");
open(STDOUT, ">> $logname") or die("opening $logname for STDOUT: $!");

#
# Clear the load_address field of the images table since any frisbee's
# that were running are obviously not running anymore! 
#
DBQueryFatal("update images set load_address=''");

55
56
57
58
59
60
#
# Clear the event scheduler pids. Its okay to set them to zero since
# thats not a valid process id. 
# 
DBQueryFatal("update experiments set event_sched_pid=0");

61
62
63
64
65
#
# Clear old logins. 
#
DBQueryFatal("delete from login");

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#
# Check for experiments stuck in transition.
#
$query_result =
    DBQueryFatal("select pid,eid,expt_locked from experiments ".
		 "where expt_locked is not NULL");
if ($query_result->numrows) {
    print "The following experiments are stuck in transition.\n\n";

    print "Pid          Eid                  When\n";
    print "------------ -------------------- ------------------------\n";
    while (($pid,$eid,$locked) = $query_result->fetchrow_array) {
	printf("%-12s %-20s %s\n", $pid, $eid, $locked);
    }
    print "\n";
}

#
# Send email if anything was reported.
#
if (-s $logname) {
    SENDMAIL($TBOPS, "DB Boot Finished", "DB Boot results:",
	     $TBOPS, undef, ($logname));
}

91
92
93
94
95
96
97
unlink("$logname");
exit 0;

sub fatal($) {
    my ($msg) = @_;

    print STDERR "$msg\n";
98
    SENDMAIL($TBOPS, "DB Boot Failed", $msg, undef, undef, ($logname));
99
100
101
    unlink("$logname");
    exit(1);
}