dbboot.in 3.24 KB
Newer Older
1
#!/usr/bin/perl -wT
Leigh Stoller's avatar
Leigh Stoller committed
2 3

#
4
# Copyright (c) 2000-2015 University of Utah and the Flux Group.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
24
#
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
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.
#
63
my $logname = TBMakeLogname("dbboot");
64 65 66 67 68 69 70 71 72

#
# 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: $!");

#
73
# Clear the frisbee_blobs table since any frisbee's
74 75
# that were running are obviously not running anymore! 
#
76
DBQueryFatal("delete from frisbee_blobs");
77

78 79 80 81 82 83
#
# 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");

84 85 86 87 88
#
# Clear image locks.
#
DBQueryFatal("update images set locked=NULL,locker_pid=0");

89 90 91 92 93
#
# Clear old logins. 
#
DBQueryFatal("delete from login");

94 95 96 97
#
# Clear the pool daemon lock.
#
DBQueryFatal("replace into emulab_locks set name='pool_daemon',value='0'");
98 99
# And other locks.
DBQueryFatal("update emulab_locks set value='0'");
100

101 102 103 104
#
# Check for experiments stuck in transition.
#
$query_result =
105
    DBQueryFatal("select pid,eid,expt_locked,state from experiments ".
106 107 108 109 110 111
		 "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";
112 113
    while (($pid,$eid,$locked,$state) = $query_result->fetchrow_array) {
	printf("%-12s %-20s %s %s\n", $pid, $eid, $locked, $state);
114 115 116 117 118 119 120 121 122 123 124 125
    }
    print "\n";
}

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

126 127 128 129 130 131 132
unlink("$logname");
exit 0;

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

    print STDERR "$msg\n";
133
    SENDMAIL($TBOPS, "DB Boot Failed", $msg, undef, undef, ($logname));
134 135 136
    unlink("$logname");
    exit(1);
}