From: <jh...@us...> - 2011-03-11 21:27:07
|
Revision: 265 http://etch.svn.sourceforge.net/etch/?rev=265&view=rev Author: jheiss Date: 2011-03-11 21:27:00 +0000 (Fri, 11 Mar 2011) Log Message: ----------- Add my rc.static-routes and rc.virtfs scripts and associated infrastructure for managing static routes and virtual interfaces on various platforms. Added Paths: ----------- trunk/etchserver-samples/source/etc/network/ trunk/etchserver-samples/source/etc/network/if-up.d/ trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/ trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/config.xml trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/ifup-local trunk/etchserver-samples/source/etc/rc.static-routes/ trunk/etchserver-samples/source/etc/rc.static-routes/config.xml trunk/etchserver-samples/source/etc/rc.static-routes/rc.static-routes trunk/etchserver-samples/source/etc/rc.virtifs/ trunk/etchserver-samples/source/etc/rc.virtifs/config.xml trunk/etchserver-samples/source/etc/rc.virtifs/rc.virtifs trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/ trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/S70static-routes trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/config.xml trunk/etchserver-samples/source/etc/static-routes/ trunk/etchserver-samples/source/etc/static-routes/config.xml trunk/etchserver-samples/source/etc/static-routes/static-routes.etchconf trunk/etchserver-samples/source/etc/static-routes/static-routes.group1 trunk/etchserver-samples/source/etc/static-routes/static-routes.group2 trunk/etchserver-samples/source/etc/static-routes/static-routes.script trunk/etchserver-samples/source/etc/virtifs/ trunk/etchserver-samples/source/etc/virtifs/config.xml trunk/etchserver-samples/source/etc/virtifs/virtifs.etchconf trunk/etchserver-samples/source/etc/virtifs/virtifs.script trunk/etchserver-samples/source/sbin/ trunk/etchserver-samples/source/sbin/ifup-local/ trunk/etchserver-samples/source/sbin/ifup-local/config.xml trunk/etchserver-samples/source/sbin/ifup-local/ifup-local Added: trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/config.xml =================================================================== --- trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/config.xml (rev 0) +++ trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/config.xml 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,11 @@ +<config> + <file> + <!-- Shell script --> + <perms>555</perms> + <warning_on_second_line/> + <source> + <plain operatingsystem="/Debian|Ubuntu/">ifup-local</plain> + </source> + </file> +</config> + Added: trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/ifup-local =================================================================== --- trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/ifup-local (rev 0) +++ trunk/etchserver-samples/source/etc/network/if-up.d/ifup-local/ifup-local 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,7 @@ +#!/bin/sh + +# Setup any virtual interfaces needed on this system +/etc/rc.virtifs +# Setup any custom routing needed on this system +/etc/rc.static-routes + Added: trunk/etchserver-samples/source/etc/rc.static-routes/config.xml =================================================================== --- trunk/etchserver-samples/source/etc/rc.static-routes/config.xml (rev 0) +++ trunk/etchserver-samples/source/etc/rc.static-routes/config.xml 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,16 @@ +<config> + <file> + <!-- Shell script --> + <perms>555</perms> + <warning_on_second_line/> + <source> + <plain>rc.static-routes</plain> + </source> + </file> + <test> + <exec kernel="Linux">ping -c1 -W20 -q etch</exec> + <exec operatingsystem="Solaris">ping etch 20</exec> + <exec operatingsystem="FreeBSD">ping -c1 -t20 -q etch</exec> + </test> +</config> + Added: trunk/etchserver-samples/source/etc/rc.static-routes/rc.static-routes =================================================================== --- trunk/etchserver-samples/source/etc/rc.static-routes/rc.static-routes (rev 0) +++ trunk/etchserver-samples/source/etc/rc.static-routes/rc.static-routes 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,445 @@ +#!/usr/bin/perl -w +############################################################################## +# This script controls routing on systems which need some form of static +# routing configuration. +############################################################################## + +$ENV{PATH} = '/bin:/sbin:/usr/bin:/usr/sbin'; + +my $OS = `uname -s`; +chomp $OS; + +my $ROUTE_CONFIG = "/etc/static-routes"; + +# Silently exit if the route config file doesn't exist, that's an +# indication that this machine doesn't need any special routing. +exit if (! -f $ROUTE_CONFIG); + +# First clean out any existing static routes +clean_routing_table(); + +# Then add the desired static routes +open(RC, "<$ROUTE_CONFIG") || die; +while(<RC>) +{ + next if (/^\s*#/); # Skip comments + next if (/^\s*$/); # And blank lines + + # Lines in the file contain two fields, seperated by whitespace. + # The first field is a destination (network and netmask) in + # nnn.nnn.nnn.nnn/xx format. + # The second field is either a gateway IP, or a network + # interface name. + # Examples: + # 10.0.0.0/4 10.8.90.1 + # 224.0.0.0/4 eth0 + + my ($dest, $via) = split; + if ($dest && $via) + { + if (($dest =~ /\//) || ($dest eq "default")) + { + if ($via =~ /^\d+\.\d+\.\d+\.\d+$/) + { + add_route_via_gateway($dest, $via); + } + else + { + add_route_via_interface($dest, $via); + } + } + else + { + if ($via =~ /^\d+\.\d+\.\d+\.\d+$/) + { + add_host_route_via_gateway($dest, $via); + } + else + { + add_host_route_via_interface($dest, $via); + } + } + } +} +close(RC); + +# +# Subroutines +# + +sub clean_routing_table +{ + # Look through the routing table for things that look like + # static routes and remove them. + open(NETSTAT, 'netstat -rn |') || die; + while(<NETSTAT>) + { + if ($OS eq 'Linux') + { + my ($dest, $gw, $mask, + $flags, $mss, $window, $irtt, $if) = split; + # On Linux it seems that if the Gateway field + # is an IP address but isn't 0.0.0.0 then the + # route is static. + # Except for routes specified by interface + # instead of gateway. It seems impossible to + # distinguish those in a general sense, so we + # cheat and make an exception for our multicast + # route. + if ($gw && + $gw =~ /^\d+\.\d+\.\d+\.\d+$/ && + $gw ne '0.0.0.0') + { + if ($flags && $flags =~ /H/) + { + delete_host_route_via_gateway($dest, $gw); + } + else + { + delete_route_via_gateway($dest, $gw, $mask); + } + } + elsif ($dest && $dest eq '224.0.0.0') + { + if ($flags && $flags =~ /H/) + { + delete_host_route_via_interface($dest, $if, $mask); + } + else + { + delete_route_via_interface($dest, $if, $mask); + } + } + + } + elsif ($OS eq 'SunOS') + { + my ($dest, $gw, $flags, $ref, $use, $if) = split; + # On Solaris it seems that if the Interface + # field is empty then the route is static. + # Except for routes specified by interface + # instead of gateway. It seems impossible to + # distinguish those in a general sense, so we + # cheat and make an exception for our multicast + # route. + if ($gw && $gw =~ /^\d+\.\d+\.\d+\.\d+$/ && ! $if) + { + if ($flags && $flags =~ /H/) + { + delete_host_route_via_gateway($dest, $gw); + } + else + { + # There doesn't appear to be a way to + # get Solaris to show you the netmask + # associated with existing routes, but + # you need the netmask to remove the + # routes. So guess at the netmask for + # standard routes in our environment and + # hope for the best. + if ($dest =~ /^10.0/) + { + $dest .= "/8"; + } + elsif ($dest =~ /^10./) + { + $dest .= "/16"; + } + elsif ($dest =~ /^172.16/) + { + $dest .= "/12"; + } + elsif ($dest =~ /^192.168/) + { + $dest .= "/16"; + } + elsif ($dest =~ /^224/) + { + $dest .= "/4"; + } + + delete_route_via_gateway($dest, $gw); + } + } + elsif ($dest && $dest eq '224.0.0.0') + { + if ($flags && $flags =~ /H/) + { + delete_host_route_via_interface($dest, $if); + } + else + { + # Guess at the netmask here too + $dest .= "/4"; + + delete_route_via_interface($dest, $if); + } + } + } + elsif ($OS eq 'FreeBSD') + { + my ($dest, $gw, $flags, $ref, $use, $if) = split; + # On FreeBSD if the 'Flags' field contains a 'S' + # then the route is static. How civilized. + if ($flags && $flags =~ /S/) + { + if ($gw =~ /^\d+\.\d+\.\d+\.\d+$/) + { + if ($flags && $flags =~ /H/) + { + delete_host_route_via_gateway($dest, $gw); + } + else + { + delete_route_via_gateway($dest, $gw); + } + } + else + { + if ($flags && $flags =~ /H/) + { + delete_host_route_via_interface($dest, $if); + } + else + { + delete_route_via_interface($dest, $if); + } + } + } + } + } + close(NETSTAT); +} + +sub add_route_via_gateway +{ + # We expect that the netmask for the route will be attached to + # the destination using the /xx format. + my ($dest, $gw) = @_; + + if ($OS eq 'Linux') + { + system("route add -net $dest gw $gw"); + } + elsif ($OS eq 'SunOS') + { + system("route add -net $dest $gw"); + } + elsif ($OS eq 'FreeBSD') + { + system("route add -net $dest $gw"); + } +} + +sub add_host_route_via_gateway +{ + # We expect that the netmask for the route will be attached to + # the destination using the /xx format. + my ($dest, $gw) = @_; + + if ($OS eq 'Linux') + { + system("route add -host $dest gw $gw"); + } + elsif ($OS eq 'SunOS') + { + system("route add -host $dest $gw"); + } + elsif ($OS eq 'FreeBSD') + { + system("route add -host $dest $gw"); + } +} + +sub add_route_via_interface +{ + # We expect that the netmask for the route will be attached to + # the destination using the /xx format. + my ($dest, $if) = @_; + + if ($OS eq 'Linux') + { + system("route add -net $dest dev $if"); + } + elsif ($OS eq 'SunOS') + { + my $ifip; + # Solaris is kinda wacky in that interface routes have + # to be added/delete using the IP of the interface, not + # the name of the interface. + open(IFCONFIG, "ifconfig $if |") || die; + while(<IFCONFIG>) + { + if (/inet (\d+\.\d+\.\d+\.\d+)/) + { + $ifip = $1; + } + } + close(IFCONFIG); + + if ($ifip) + { + system("route add -net $dest -interface $ifip"); + } + } + elsif ($OS eq 'FreeBSD') + { + system("route add -net $dest -interface $if"); + } +} + +sub add_host_route_via_interface +{ + # We expect that the netmask for the route will be attached to + # the destination using the /xx format. + my ($dest, $if) = @_; + + if ($OS eq 'Linux') + { + system("route add -host $dest dev $if"); + } + elsif ($OS eq 'SunOS') + { + my $ifip; + # Solaris is kinda wacky in that interface routes have + # to be added/delete using the IP of the interface, not + # the name of the interface. + open(IFCONFIG, "ifconfig $if |") || die; + while(<IFCONFIG>) + { + if (/inet (\d+\.\d+\.\d+\.\d+)/) + { + $ifip = $1; + } + } + close(IFCONFIG); + + if ($ifip) + { + system("route add -host $dest -interface $ifip"); + } + } + elsif ($OS eq 'FreeBSD') + { + system("route add -host $dest -interface $if"); + } +} + +sub delete_route_via_gateway +{ + # The mask is only supplied for Linux systems, on Solaris and + # FreeBSD the mask is attached in /xx format to the destination + # This is because netstat -rn on Linux reports the netmask + # associated with each route in a seperate column, rather than + # attaching it to the network number with the /xx format. + # And I'm too lazy to convert it. + my ($dest, $gw, $mask) = @_; + + if ($OS eq 'Linux') + { + system("route del -net $dest netmask $mask gw $gw"); + } + elsif ($OS eq 'SunOS') + { + system("route delete -net $dest $gw"); + } + elsif ($OS eq 'FreeBSD') + { + system("route delete -net $dest $gw"); + } +} + +sub delete_host_route_via_gateway +{ + my ($dest, $gw) = @_; + + if ($OS eq 'Linux') + { + system("route del -host $dest gw $gw"); + } + elsif ($OS eq 'SunOS') + { + system("route delete -host $dest $gw"); + } + elsif ($OS eq 'FreeBSD') + { + system("route delete -host $dest $gw"); + } +} + +sub delete_route_via_interface +{ + # The mask is only supplied for Linux systems, on Solaris and + # FreeBSD the mask is attached in /xx format to the destination. + # This is because netstat -rn on Linux reports the netmask + # associated with each route in a seperate column, rather than + # attaching it to the network number with the /xx format. + # And I'm too lazy to convert it. + my ($dest, $if, $mask) = @_; + + if ($OS eq 'Linux') + { + system("route del -net $dest netmask $mask dev $if"); + } + elsif ($OS eq 'SunOS') + { + my $ifip; + # Solaris is kinda wacky in that interface routes have + # to be added/delete using the IP of the interface, not + # the name of the interface. + open(IFCONFIG, "ifconfig $if |") || die; + while(<IFCONFIG>) + { + if (/inet (\d+\.\d+\.\d+\.\d+)/) + { + $ifip = $1; + } + } + close(IFCONFIG); + + if ($ifip) + { + system("route delete -net $dest -interface $ifip"); + } + } + elsif ($OS eq 'FreeBSD') + { + system("route delete -net $dest -interface $if"); + } +} + +sub delete_host_route_via_interface +{ + my ($dest, $if) = @_; + + if ($OS eq 'Linux') + { + system("route del -host $dest dev $if"); + } + elsif ($OS eq 'SunOS') + { + my $ifip; + # Solaris is kinda wacky in that interface routes have + # to be added/delete using the IP of the interface, not + # the name of the interface. + open(IFCONFIG, "ifconfig $if |") || die; + while(<IFCONFIG>) + { + if (/inet (\d+\.\d+\.\d+\.\d+)/) + { + $ifip = $1; + } + } + close(IFCONFIG); + + if ($ifip) + { + system("route delete -host $dest -interface $ifip"); + } + } + elsif ($OS eq 'FreeBSD') + { + system("route delete -host $dest -interface $if"); + } +} + Added: trunk/etchserver-samples/source/etc/rc.virtifs/config.xml =================================================================== --- trunk/etchserver-samples/source/etc/rc.virtifs/config.xml (rev 0) +++ trunk/etchserver-samples/source/etc/rc.virtifs/config.xml 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,10 @@ +<config> + <file> + <perms>555</perms> + <warning_on_second_line/> + <source> + <plain>rc.virtifs</plain> + </source> + </file> +</config> + Added: trunk/etchserver-samples/source/etc/rc.virtifs/rc.virtifs =================================================================== --- trunk/etchserver-samples/source/etc/rc.virtifs/rc.virtifs (rev 0) +++ trunk/etchserver-samples/source/etc/rc.virtifs/rc.virtifs 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,80 @@ +#!/usr/bin/ruby -w + +require 'facter' +require 'resolv' +require 'ipaddr' + +ENV['PATH'] = '/bin:/sbin:/usr/bin:/usr/sbin' + +VIRTIFS_CONFIG = '/etc/virtifs' + +# Silently exit if the config file doesn't exist, that's an indication +# that this machine doesn't need any virtual interfaces configured. +exit if !File.exist?(VIRTIFS_CONFIG) + +# Tell facter to load everything, otherwise it tries to dynamically +# load the individual fact libraries using a very broken mechanism +Facter.loadfacts + +# Prepare the configuration of our virtual interfaces +virtcounters = {} +virtifs = {} +IO.foreach(VIRTIFS_CONFIG) do |line| + line.chomp! + next if line =~ /^\s*#/ # Skip comments + next if line =~ /^\s*$/ # And blank lines + hostname, cachedip = line.split + + # Try to look up the IP for that hostname + res = Resolv::DNS::new() + ip = nil + begin + addr = res.getaddress(hostname) + ip = addr.to_s + rescue Resolv::ResolvError + ip = cachedip + end + ipaddr = IPAddr.new(ip) + + # Find the physical interface to which this virtual interface should + # belong + Facter['interfaces'].value.split(',').each do |nic| + if nic !~ /:/ && nic !~ /__tmp/ + ifip = Facter["ipaddress_#{nic}"].value + next if ifip.nil? + mask = Facter["netmask_#{nic}"].value + subnetaddr = IPAddr.new("#{ifip}/#{mask}") + if subnetaddr.include?(ipaddr) + # Calculate the virtual interface name + virtif = nic + ':' + if virtcounters.has_key?(nic) + virtcounters[nic] += 1 + else + virtcounters[nic] = 0 + end + virtif << virtcounters[nic].to_s + # Store the interface data + virtifs[virtif] = { 'ip' => ip, 'mask' => mask } + break + end + end + end +end + +# Clean up any existing virtual interfaces +Facter['interfaces'].value.split(',').each do |nic| + if nic =~ /:/ + puts "ifconfig #{nic} down" + system "ifconfig #{nic} down" + end +end + +# Activate our virtual interface configuration +virtifs.each do |virtif, virtifdata| + ip = virtifdata['ip'] + mask = virtifdata['mask'] + + puts "ifconfig #{virtif} #{ip} netmask #{mask}" + system "ifconfig #{virtif} #{ip} netmask #{mask}" +end + Added: trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/S70static-routes =================================================================== --- trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/S70static-routes (rev 0) +++ trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/S70static-routes 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,9 @@ +#!/bin/sh + +# Solaris assumes init scripts are shell scripts and explicity calls +# them via /sbin/sh rather than just executing them. rc.static-routes +# is a Perl script, so this is a simple wrapper around it to make things +# work properly. + +/etc/rc.static-routes "$@" + Added: trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/config.xml =================================================================== --- trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/config.xml (rev 0) +++ trunk/etchserver-samples/source/etc/rc2.d/S70static-routes/config.xml 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,10 @@ +<config> + <file> + <perms>555</perms> + <warning_on_second_line/> + <source> + <plain operatingsystem="Solaris">S70static-routes</plain> + </source> + </file> +</config> + Added: trunk/etchserver-samples/source/etc/static-routes/config.xml =================================================================== --- trunk/etchserver-samples/source/etc/static-routes/config.xml (rev 0) +++ trunk/etchserver-samples/source/etc/static-routes/config.xml 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,20 @@ +<config> + <depend>/etc/rc.static-routes</depend> + + <file> + <source> + <script>static-routes.script</script> + </source> + </file> + + <post> + <exec>/etc/rc.static-routes</exec> + </post> + + <test> + <exec kernel="Linux">ping -c3 -W20 -q etch</exec> + <exec operatingsystem="Solaris">sleep 3 ; ping etch 20</exec> + <exec operatingsystem="FreeBSD">ping -c3 -t20 -q etch</exec> + </test> +</config> + Added: trunk/etchserver-samples/source/etc/static-routes/static-routes.etchconf =================================================================== --- trunk/etchserver-samples/source/etc/static-routes/static-routes.etchconf (rev 0) +++ trunk/etchserver-samples/source/etc/static-routes/static-routes.etchconf 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,4 @@ +# nodegroup # filename +nodegroup1 static-routes.group1 +nodegroup2 static-routes.group2 + Added: trunk/etchserver-samples/source/etc/static-routes/static-routes.group1 =================================================================== --- trunk/etchserver-samples/source/etc/static-routes/static-routes.group1 (rev 0) +++ trunk/etchserver-samples/source/etc/static-routes/static-routes.group1 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,9 @@ +# You might have multiple clients that need a similar set of routes, but +# those clients are on multiple subnets and they need to use the correct +# gateway for their subnet. No worries, just list them all here and +# static-routes.script will only add the routes that are reachable by +# any given client. +default 10.1.8.10 +10.0.0.0/8 10.1.8.1 +default 10.1.10.10 +10.0.0.0/8 10.1.10.1 Added: trunk/etchserver-samples/source/etc/static-routes/static-routes.group2 =================================================================== --- trunk/etchserver-samples/source/etc/static-routes/static-routes.group2 (rev 0) +++ trunk/etchserver-samples/source/etc/static-routes/static-routes.group2 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,10 @@ +# You might have multiple clients that need a similar set of routes, but +# those clients are on multiple subnets and they need to use the correct +# gateway for their subnet. No worries, just list them all here and +# static-routes.script will only add the routes that are reachable by +# any given client. +default 10.1.10.1 +default 10.1.12.1 +default 10.3.12.1 +default 10.3.14.1 +224.0.0.0/4 eth1 Added: trunk/etchserver-samples/source/etc/static-routes/static-routes.script =================================================================== --- trunk/etchserver-samples/source/etc/static-routes/static-routes.script (rev 0) +++ trunk/etchserver-samples/source/etc/static-routes/static-routes.script 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,76 @@ +#!/usr/bin/ruby + +require 'ipaddr' + +# Given an IP return true if the IP is in the same subnet as any of the +# interfaces on this machine +def directly_reachable(target) + number_of_interfaces_checked = 0 + @facts['interfaces'].split(',').each do |inf| + if @facts["ipaddress_#{inf}"] && @facts["netmask_#{inf}"] + number_of_interfaces_checked += 1 + infaddr = IPAddr.new(@facts["ipaddress_#{inf}"] + '/' + @facts["netmask_#{inf}"]) + return true if infaddr.include?(IPAddr.new(target)) + end + end + if number_of_interfaces_checked > 0 + return false + else + # If Facter failed for some reason and didn't send us any interface + # data we don't want to have etch unconfigure/misconfigure the + # networking on the client + abort "No interface addresses/netmasks received" + end +end + +# Filters the supplied routing config file, leaving only routes which have +# a destination directly reachable via one of the client's interfaces. This +# allows us to put the routes for all subnets in one file, rather than +# maintaining a seperate route file for each subnet. This isn't strictly +# necessary on some platforms, as on those platforms attempting to add a +# route to an unreachable destination will fail. However, there are +# platforms that will let you add routes to unreachable destinations, and +# packets taking that route silently disappear. +def filter(file) + output = '' + IO.foreach(file) do |line| + next if line =~ /^\s*$/ # Skip blank lines + next if line =~ /^\s*#/ # Skip comments + + dest, via = line.split + if via =~ /^\d+\.\d+\.\d+\.\d+$/ && directly_reachable(via) + output << line + else + @facts['interfaces'].split(',').each do |inf| + if via == inf + output << line + end + end + end + end + + if !output.empty? + output.insert(0, "# Entries from #{file}\n") + end + output +end + +test_contents = [] +IO.foreach('static-routes.etchconf') do |line| + line.chomp! + next if line =~ /^\s*$/ # Skip blank lines + next if line =~ /^\s*#/ # Skip comments + + group, file = line.split(' ', 2) + if @groups.include?(group) + test_contents << filter(file) + end +end + +if !test_contents.empty? + testpass = '' + test_contents.each { |lines| lines.each { |line| dest, via = line.split ; (testpass = true) if dest == 'default' }} + if testpass == true + test_contents.each { |addme| @contents << addme } + end +end Added: trunk/etchserver-samples/source/etc/virtifs/config.xml =================================================================== --- trunk/etchserver-samples/source/etc/virtifs/config.xml (rev 0) +++ trunk/etchserver-samples/source/etc/virtifs/config.xml 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,14 @@ +<config> + <depend>/etc/rc.virtifs</depend> + + <file> + <source> + <script>virtifs.script</script> + </source> + </file> + + <post> + <exec>/etc/rc.virtifs</exec> + </post> +</config> + Added: trunk/etchserver-samples/source/etc/virtifs/virtifs.etchconf =================================================================== --- trunk/etchserver-samples/source/etc/virtifs/virtifs.etchconf (rev 0) +++ trunk/etchserver-samples/source/etc/virtifs/virtifs.etchconf 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,4 @@ +# Node group Virtual IP or hostname +nodegroup1 10.1.2.3 +nodegroup2 virtual1.example.com + Added: trunk/etchserver-samples/source/etc/virtifs/virtifs.script =================================================================== --- trunk/etchserver-samples/source/etc/virtifs/virtifs.script (rev 0) +++ trunk/etchserver-samples/source/etc/virtifs/virtifs.script 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,21 @@ +#!/usr/bin/ruby + +require 'resolv' + +IO.foreach('virtifs.etchconf') do |line| + line.chomp! + next if line =~ /^\s*$/ # Skip blank lines + next if line =~ /^\s*#/ # Skip comments + + group, hostname = line.split + if @groups.include?(group) + res = Resolv::DNS::new() + addr = res.getaddress(hostname) + if !addr + abort "DNS lookup of virtual interface #{hostname} failed" + end + ip = addr.to_s + @contents << hostname << ' ' << ip << "\n" + end +end + Added: trunk/etchserver-samples/source/sbin/ifup-local/config.xml =================================================================== --- trunk/etchserver-samples/source/sbin/ifup-local/config.xml (rev 0) +++ trunk/etchserver-samples/source/sbin/ifup-local/config.xml 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,11 @@ +<config> + <file> + <!-- Shell script --> + <perms>555</perms> + <warning_on_second_line/> + <source> + <plain operatingsystem="/RedHat|CentOS/">ifup-local</plain> + </source> + </file> +</config> + Added: trunk/etchserver-samples/source/sbin/ifup-local/ifup-local =================================================================== --- trunk/etchserver-samples/source/sbin/ifup-local/ifup-local (rev 0) +++ trunk/etchserver-samples/source/sbin/ifup-local/ifup-local 2011-03-11 21:27:00 UTC (rev 265) @@ -0,0 +1,8 @@ +#!/bin/sh + +# Setup any virtual interfaces needed on this system +/etc/rc.virtifs +# Setup any custom routing needed on this system +/etc/rc.static-routes + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |