subboss_sync.in 2.26 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
use Fcntl ':flock';


my $RSYNC = 'rsync';

14
my $RSYNC_OPTS = "-W -u -av --delete --force";
15
16
17
18
19
20
21
22
23
24
25
26

my @excludes=qw#cisco-config/ cisco-config. hp-config/ OLD/ tmp/ /proj/#;
my @includes=qw#INCLUDE_ME#;

#
# 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";
27
    print "-c	Use checksums rather than time stamps in rsync\n";
28
    print "-h	Show this message\n";
29
    print "-n	All talk, no action\n";
30
31
    exit(1);
}
32
my $optlist = "chn";
33
34
35
my $install = 0;
my $vnames  = 0;
my $restart = 0;
36
37
my $impotent = 0;
my $cksum = 0;
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

# 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();
}
58
59
60
if (defined($options{"c"})) {
    $cksum = 1;
}
61
62
63
if (defined($options{"h"})) {
    usage();
}
64
65
66
if (defined($options{"n"})) {
    $impotent = 1;
}
67
68
69

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

70
71
72
73
74
75
if ($cksum) {
	$cmdline .= " -c";
}
if ($impotent) {
	$cmdline .= " -n -i";
}
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

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

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

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

# Slurp in all of the subboss data to know A) if we should serve the DHCP
# lease to a given node, or if the next-server field should be something
# other than the IP for boss.
$query_result =
    DBQueryWarn("select distinct subboss_id from subbosses where service = 'tftp'");
if (! $query_result) {
    fatal("Could not dhcpd data from DB!");
}
while (my %row = $query_result->fetchhash()) {
    my $subboss_id = $row{"subboss_id"};
97
    print $cmdline . " $subboss_id:/tftpboot/\n";
98
99
100
101
    system($cmdline . " $subboss_id:/tftpboot/");
}
exit(0);