subboss_sync.in 2.95 KB
Newer Older
1 2
#!/usr/bin/perl -wT
#
3
# Copyright (c) 2000-2013 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{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/>.
# 
# }}}
23 24 25 26 27 28 29 30
#
use English;
use Getopt::Std;
use Fcntl ':flock';


my $RSYNC = 'rsync';

31
my $RSYNC_OPTS = "-W -u -av --delete --force";
32

33 34
my @excludes=qw#cisco-config/ cisco-config. hp-config/ OLD/ tmp/ /proj/ switch-backup#;
my @includes=qw##;
35 36 37 38 39 40 41 42 43

#
# dhcpd_makeconf - helper script to create dhcpd.conf files from the database.
# The template file should look like an ordinary dhcpd.conf file, but have
# the string %%nodetype=<type> where you want entries for a set of nodes
# filled out. See the template file in the dhcp directory for an example.
#
sub usage {
    print "Usage: $0 [-h]\n";
44
    print "-c	Use checksums rather than time stamps in rsync\n";
45
    print "-h	Show this message\n";
46
    print "-n	All talk, no action\n";
47 48
    exit(1);
}
49
my $optlist = "chn";
50 51 52
my $install = 0;
my $vnames  = 0;
my $restart = 0;
53 54
my $impotent = 0;
my $cksum = 0;
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

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

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

use lib "@prefix@/lib";
use libdb;
use libtestbed;

#
# Parse command arguments. Once we return from getopts, all that should
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
    usage();
}
75 76 77
if (defined($options{"c"})) {
    $cksum = 1;
}
78 79 80
if (defined($options{"h"})) {
    usage();
}
81 82 83
if (defined($options{"n"})) {
    $impotent = 1;
}
84 85 86

my $cmdline = $RSYNC . ' ' . $RSYNC_OPTS;

87 88 89 90 91 92
if ($cksum) {
	$cmdline .= " -c";
}
if ($impotent) {
	$cmdline .= " -n -i";
}
93 94 95 96 97 98 99 100 101 102 103

for (@excludes) {
	$cmdline .= " --exclude=$_";
}

for (@includes) {
	$cmdline .= " --include=$_";
}

$cmdline .= " -e ssh /tftpboot/";

104
# Slurp in all of the subboss data to know if we should serve the DHCP
105 106 107
# lease to a given node, or if the next-server field should be something
# other than the IP for boss.
$query_result =
108 109 110 111
    DBQueryWarn("select distinct subboss_id from subbosses ".
		"where service='tftp'");
if (!$query_result) {
    fatal("Could not subboss data from DB!");
112 113 114
}
while (my %row = $query_result->fetchhash()) {
    my $subboss_id = $row{"subboss_id"};
115
    print $cmdline . " $subboss_id:/tftpboot/\n";
116 117 118 119
    system($cmdline . " $subboss_id:/tftpboot/");
}
exit(0);