All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

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

#
# EMULAB-COPYRIGHT
5
# Copyright (c) 2000-2010 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
6 7
# All rights reserved.
#
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 40 41 42 43 44 45
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.
#
46
my $logname = TBMakeLogname("dbboot");
47 48 49 50 51 52 53 54 55

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

#
56
# Clear the frisbee_blobs table since any frisbee's
57 58
# that were running are obviously not running anymore! 
#
59
DBQueryFatel("delete from frisbee_blobs");
60

61 62 63 64 65 66
#
# 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");

67 68 69 70 71
#
# Clear old logins. 
#
DBQueryFatal("delete from login");

72 73 74 75 76
#
# Clear the pool daemon lock.
#
DBQueryFatal("replace into emulab_locks set name='pool_daemon',value='0'");

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
#
# 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));
}

102 103 104 105 106 107 108
unlink("$logname");
exit 0;

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

    print STDERR "$msg\n";
109
    SENDMAIL($TBOPS, "DB Boot Failed", $msg, undef, undef, ($logname));
110 111 112
    unlink("$logname");
    exit(1);
}