Changeset 5759 in /cluster/svnroot


Ignore:
Timestamp:
Aug 30, 2016 7:52:13 PM (4 years ago)
Author:
skylar
Message:

clean up etc re #915

Location:
bccd-ng/branches/skylar/bccd-3.4.0-build_ng/src
Files:
1 deleted
1 edited
14 moved

Legend:

Unmodified
Added
Removed
  • bccd-ng/branches/skylar/bccd-3.4.0-build_ng/src/bin/bccd-dhcp-conf

    r4714 r5759  
    1 #!/usr/bin/perl
     1#!/bin/sh
    22
    33# $Id$
     
    2323# along with this program.  If not, see <http://www.gnu.org/licenses/>.
    2424
    25 use strict;
    26 use warnings;
    27 use Net::IP qw/ip_bintoip/;
    28 use Bccd;
    29 use Getopt::Long;
    30 use POSIX;
     25### BEGIN INIT INFO
     26# Provides:          bccd-dhcp-conf
     27# Required-Start:
     28# Required-Stop:
     29# Default-Start:     S
     30# Default-Stop:
     31# Short-Description: Setup network-specific DHCP configuration
     32### END INIT INFO
    3133
    32 sub dec2bin {
    33     my $str = unpack("B32", pack("N", shift));
    34     $str =~ s/^0+(?=\d)//;   # otherwise you'll get leading zeros
    35     return $str;
    36 }
     34#if [ $(cat /etc/bccd-stage) = "LIBERATED" ]; then
     35#       /bin/bccd-dhcp-conf
     36#       exit $?
     37#fi
    3738
    38 my($Bccd,$netip,$uniip,$bcast,$dhcpaddrs,$pxeaddrs,$resaddrs,$mask,$next,
    39    $oneip,$i,$j,$dhcprange,$pxerange,$line,$cidr,$network,$file,$dhcp_conf,
    40    $dhcp_net,$template_dhcp_conf,$configured,$pxelinux,$template_pxelinux,
    41    $diskless_fstab,$template_diskless_fstab,$router,$sub,$rc,$out);
    42 my %opts;
     39grep -q '[[:space:]+]startdhcp' /proc/cmdline
     40if test $? -ne 0; then
     41    echo "No DHCP network information; not configuring authoritative DHCP."
     42    exit 2;
     43fi
    4344
    44 $Bccd = new Bccd();
     45/bin/bccd-dhcp-conf
    4546
    46 GetOptions(
    47                 'routernic=s'   => \$opts{'routernic'},
    48                 'net=s'         => \$opts{'net'},
    49                 );
    50 
    51 $sub = 'main';
    52 $dhcp_conf = '/etc/dhcp/bccd_net.conf';
    53 $template_dhcp_conf = $dhcp_conf."_template";
    54 $pxelinux = "/srv/tftp/pxelinux.cfg/default";
    55 $template_pxelinux = $pxelinux."_template";
    56 $configured = "/etc/dhcp/configured";
    57 $diskless_fstab = "/diskless/".$Bccd->get_project()."/etc/fstab";
    58 $template_diskless_fstab = $diskless_fstab."_template";
    59 $router = $Bccd->get_nic_ip(defined($opts{'routernic'}) ? $opts{'routernic'} : $Bccd->parse_cmdline('dhcp_routernic'));
    60 
    61 $dhcp_net = defined($opts{'net'}) ? $opts{'net'} : $Bccd->parse_cmdline('dhcp_net');
    62 
    63 if(defined($dhcp_net)) {
    64     ($cidr,$resaddrs,$dhcpaddrs,$pxeaddrs) = split(':',$dhcp_net);
    65     if(!defined($cidr) ||
    66        !defined($resaddrs) ||
    67        !defined($dhcpaddrs) ||
    68        !defined($pxeaddrs) ) {
    69         $Bccd->log_and_die("ERROR",$sub,"Parse error from dhcp_net in /proc/cmdline!");
    70     }
    71 } elsif( ! -f $configured || !defined($dhcp_net) ) {
    72     $cidr = '10.4.0.0/24';
    73     $resaddrs = 10;
    74     $dhcpaddrs = 100;
    75     $pxeaddrs = 100;
    76 }
    77 
    78 $netip=new Net::IP($cidr) ||
    79     $Bccd->log_and_die("ERROR",$sub,"Couldn't create network IP object for $cidr: $!");
    80 
    81 $oneip=new Net::IP('0.0.0.1') || # Addition doesn't work the way it should
    82     $Bccd->log_and_die("ERROR",$sub,"Couldn't create singleton IP object: $!");
    83 
    84 $Bccd->log_and_die("ERROR",$sub,"Network supports ".$netip->size().
    85                    " systems but we requested $dhcpaddrs addresses!")
    86     if($netip->size() < $dhcpaddrs);
    87 
    88 $Bccd->log_and_die("ERROR",$sub,"Network reservation of $resaddrs eats up too much space with only ".
    89                    $netip->size()." available.")
    90     if(($pxeaddrs+$dhcpaddrs+$resaddrs) > $netip->size());
    91 
    92 $network = $netip->ip();
    93 $bcast = $netip->last_ip();
    94 $mask = $netip->mask();
    95 
    96 $netip=$netip->binadd($oneip);
    97 $next = $netip->ip();
    98 
    99 open(HOSTS, "> /etc/hosts") or $Bccd->log_and_die("ERROR",$sub,"Can't open file /etc/hosts: $!");
    100 
    101 print HOSTS "127.0.0.1\tlocalhost\n";
    102 
    103 $j = 0;
    104 # Increment to first DHCP address
    105 for($i=1;$i<$resaddrs;$i++) {
    106         printf(HOSTS "%s\tnode%.3d.bccd.net\t# Reserved IP\n", $netip->ip(), $j);
    107     $netip=$netip->binadd($oneip);
    108     $j++;
    109 }
    110 
    111 $dhcprange = $netip->ip();
    112 
    113 for($i=0;$i<$dhcpaddrs;$i++) {
    114         printf(HOSTS "%s\tnode%.3d\t#DHCP IP\n", $netip->ip(), $j);
    115     $netip=$netip->binadd($oneip);
    116     $j++;
    117 }
    118 
    119 $dhcprange .= " ".$netip->ip();
    120 
    121 $netip=$netip->binadd($oneip);
    122 
    123 $pxerange = $netip->ip();
    124 
    125 $pxerange .= " ".$netip->ip();
    126 
    127 $file = $Bccd->snarf_file($template_dhcp_conf);
    128 
    129 $file =~ s/!NETWORK!/$network/g;
    130 $file =~ s/!NETMASK!/$mask/g;
    131 $file =~ s/!BROADCAST!/$bcast/g;
    132 $file =~ s/!DHCP-RANGE!/$dhcprange/g;
    133 $file =~ s/!NEXT-SERVER!/$next/g;
    134 $file =~ s/!PXE-RANGE!/$pxerange/g;
    135 #$file =~ s/.*#.*(option routers) !BCCDROUTER!;/$1 $router;/g
    136 #    if(defined($router));
    137 
    138 open(CONF, "> $dhcp_conf") ||
    139     $Bccd->log_and_die("ERROR",$sub,"Can't open file: $!");
    140 
    141 print CONF "$file\n";
    142 
    143 close(CONF);
    144 
    145 $file = $Bccd->snarf_file($template_pxelinux);
    146 
    147 $file =~ s/!NEXT-SERVER!/$next/g;
    148 
    149 open(CONF, "> $pxelinux") ||
    150     $Bccd->log_and_die("ERROR",$sub,"Can't open file $pxelinux: $!");
    151 
    152 print CONF "$file\n";
    153 
    154 close(CONF);
    155 
    156 if(-f $template_diskless_fstab) {
    157     $file = $Bccd->snarf_file($template_diskless_fstab);
    158 
    159     $file =~ s/!NEXT-SERVER!/$next/g;
    160 
    161     open(CONF, "> $diskless_fstab") ||
    162         $Bccd->log_and_die("ERROR",$sub,"Can't open file $diskless_fstab: $!");
    163 
    164     print CONF "$file\n";
    165 
    166     close(CONF);
    167 }
    168 
    169 ($rc,$out) = $Bccd->exec_system([
    170         'invoke-rc.d',
    171         'isc-dhcp-server',
    172         'status',
    173     ]);
    174 if(!$rc) {
    175     ($rc,$out) = $Bccd->exec_system([
    176             'invoke-rc.d',
    177             'isc-dhcp-server',
    178             'restart',
    179         ]);
    180     $Bccd->log_and_cont("NOTICE",$sub,"Couldn't restart DHCP server: $out\n")
    181         if($rc);
    182 }
    183 
    184 ($rc,$out) = $Bccd->exec_system([
    185         'touch',
    186         $configured,
    187     ]);
    188 $Bccd->log_and_die("ERROR",$sub,"Couldn't touch $configured flag file: $!") if(WEXITSTATUS($rc));
     47exit $?
Note: See TracChangeset for help on using the changeset viewer.