summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/install-system142
-rwxr-xr-xscripts/keepalived/vyatta-keepalived.pl21
-rwxr-xr-xscripts/keepalived/vyatta-show-vrrp.pl75
-rwxr-xr-xscripts/keepalived/vyatta-vrrp-state.pl9
-rwxr-xr-xscripts/rl-system.init5
-rw-r--r--scripts/snmp/vyatta-snmp.pl35
6 files changed, 192 insertions, 95 deletions
diff --git a/scripts/install-system b/scripts/install-system
index 2823746b..56803420 100755
--- a/scripts/install-system
+++ b/scripts/install-system
@@ -271,16 +271,6 @@ select_partition () {
PARTITION=$lpartition
}
-rename_old_config() {
- files=$(find /mnt/config -mindepth 1 -type f | grep -v pre-glendale)
- for f in $files; do
- if grep -q '/\*XORP Configuration File, v1.0\*/' $f >&/dev/null; then
- CURTIME=$(date +%F-%H%M%S)
- mv $f $f.pre-glendale.$CURTIME
- fi
- done
-}
-
## check_config_partition
# look to see if this partition contains a config file
# and back it up
@@ -291,34 +281,35 @@ check_config_partition() {
mkdir -p /mnt/tmp
output=$(mount /dev/$lpart /mnt/tmp 2>&1)
if [ $? != 0 ]; then
+ echo -e "Cannot mount /dev/$lpart"."\nPlease see $INSTALL_LOG for more details.\nExiting.."
echo -e "Cannot mount /dev/$lpart"."\nmount /dev/$ldrive$part /mnt/tmp\nExiting..." >> $INSTALL_LOG
echo "$output" >> $INSTALL_LOG
- else
- # Look to see if there is a config partition there
- if [ -f /mnt/tmp/opt/vyatta/etc/config/.vyatta_config ] || [ -f /mnt/tmp/.vyatta_config ]; then
- response=''
- while [ -z "$response" ]
- do
- echo "/dev/$lpart has an old configuration directory!"
- echo -ne "Would you like me to save the data on it\nbefore I delete it? (Yes/No) [Yes]: "
- response=$(get_response "Yes" "Yes No Y N")
- if [ "$response" == "yes" ] || [ "$response" == "y" ]; then
- mkdir -p /mnt/config
- if [ -d /mnt/tmp/opt/vyatta/etc/config ]; then
- output=$(cp -pR /mnt/tmp/opt/vyatta/etc/config/* /mnt/config)
- else
- output=$(cp -pR /mnt/tmp/* /mnt/config)
- fi
- if [ -n "$output" ]; then
- echo -e "Warning: error in copying the old config partition.\nSee $INSTALL_LOG for more details."
- echo -e "Warning: error in copying the old config partition.\ncp -pR /mnt/tmp/* /mnt/config\n$output\n" >> $INSTALL_LOG
- fi
- rename_old_config
+ exit 1
+ fi
+
+ # Look to see if there is a config partition there
+ if [ -f /mnt/tmp/opt/vyatta/etc/config/.vyatta_config ] || [ -f /mnt/tmp/.vyatta_config ]; then
+ response=''
+ while [ -z "$response" ]
+ do
+ echo "/dev/$lpart has an old configuration directory!"
+ echo -ne "Would you like me to save the data on it\nbefore I delete it? (Yes/No) [Yes]: "
+ response=$(get_response "Yes" "Yes No Y N")
+ if [ "$response" == "yes" ] || [ "$response" == "y" ]; then
+ mkdir -p /mnt/config
+ if [ -d /mnt/tmp/opt/vyatta/etc/config ]; then
+ output=$(cp -pR /mnt/tmp/opt/vyatta/etc/config/* /mnt/config)
+ else
+ output=$(cp -pR /mnt/tmp/* /mnt/config)
fi
- done
- fi
- umount /mnt/tmp
+ if [ -n "$output" ]; then
+ echo -e "Warning: error in copying the old config partition.\nSee $INSTALL_LOG for more details."
+ echo -e "Warning: error in copying the old config partition.\ncp -pR /mnt/tmp/* /mnt/config\n$output\n" >> $INSTALL_LOG
+ fi
+ fi
+ done
fi
+ umount /mnt/tmp
}
# Delete all existing partitions for an automated install
@@ -566,14 +557,13 @@ install_grub () {
# TODO: This needs to be changed to map to the correct drive
part=$(echo $ROOT_PARTITION | sed 's/[^0-9]//g')
- part=$(($part - 1))
if [ "$(cat /sys/block/$orig_install_drive/removable)" == 0 ]; then
root=$(grep $orig_install_drive $rootfsdir/boot/grub/device.map | /usr/bin/awk -F')' '{ print $1 }')
root="$root,$part)"
else
- echo "This looks like a removable device. Setting root grub device to (0,0)."
- echo "This looks like a removable device. Setting root grub device to (0,0)." >> $INSTALL_LOG
root="(hd0,$part)"
+ echo "This looks like a removable device. Setting root grub device to $root."
+ echo "This looks like a removable device. Setting root grub device to $root." >> $INSTALL_LOG
fi
# Figure out whether we are running on the serial or KVM console:
@@ -585,40 +575,50 @@ install_grub () {
DEFAULT_CONSOLE="0"
fi
- # create the menu.lst file for grub
- # The "default=" line selects which boot option will be used by default.
- # Numbering starts at 0 for the first option.
- grub_file="$rootfsdir/boot/grub/menu.lst"
- echo -e "default=$DEFAULT_CONSOLE\ntimeout=5\n#splashimage=(hd0,0)/grub/splash.xpm.gz\nhiddenmenu" > $grub_file
- # set serial console options
- echo -e "serial --unit=0 --speed=9600\nterminal --timeout=5 console serial\n\n" >> $grub_file
-
- # Set first system boot option. Make KVM the default console in this one.
- echo -e "title Vyatta OFR (KVM console)\n\troot $root" >> $grub_file
- echo -en "\tkernel /boot/vmlinuz root=/dev/$ROOT_PARTITION $ISCF console=ttyS0,9600 console=tty0 \n" >> $grub_file
- echo -e "\tinitrd /boot/initrd.img" >> $grub_file
-
- # Set the second system boot option. Make the serial port be the default
- # console in this one.
- echo >> $grub_file
- echo -e "title Vyatta OFR (Serial console)\n\troot $root" >> $grub_file
- echo -en "\tkernel /boot/vmlinuz root=/dev/$ROOT_PARTITION $ISCF console=tty0 console=ttyS0,9600 \n" >> $grub_file
- echo -e "\tinitrd /boot/initrd.img" >> $grub_file
-
- # Set third and fourth boot options for root password reset. Offer
- # options for both serial and KVM console.
-
- echo >> $grub_file
- echo -e "title Root password reset to factory (KVM console)" >> $grub_file
- echo -e "\troot $root" >> $grub_file
- echo -e "\tkernel /boot/vmlinuz root=/dev/$ROOT_PARTITION $ISCF console=ttyS0,9600 console=tty0 init=$PWRESET" >> $grub_file
- echo -e "\tinitrd /boot/initrd.img" >> $grub_file
-
- echo >> $grub_file
- echo -e "title Root password reset to factory (Serial console)" >> $grub_file
- echo -e "\troot $root" >> $grub_file
- echo -e "\tkernel /boot/vmlinuz root=/dev/$ROOT_PARTITION $ISCF console=tty0 console=ttyS0,9600 init=$PWRESET" >> $grub_file
- echo -e "\tinitrd /boot/initrd.img" >> $grub_file
+ (
+ # create the grub.cfg file for grub
+ # The "default=" line selects which boot option will be used by default.
+ # Numbering starts at 0 for the first option.
+ echo -e "set default=$DEFAULT_CONSOLE"
+ echo "set timeout=5"
+ #echo "#set splashimage=(hd0,0)/grub/splash.xpm.gz"
+ echo "hiddenmenu"
+ # set serial console options
+ echo -e "serial --unit=0 --speed=9600"
+ echo "terminal --timeout=5 console serial"
+ echo "set root=$root"
+ echo
+ echo
+
+ # Set first system boot option. Make KVM the default console in this one.
+ echo -e "menuentry \"Vyatta OFR (KVM console)\" {"
+ echo -en "\tlinux /boot/vmlinuz root=/dev/$ROOT_PARTITION $ISCF console=ttyS0,9600 console=tty0 \n"
+ echo -e "\tinitrd /boot/initrd.img"
+ echo -e "}"
+
+ # Set the second system boot option. Make the serial port be the default
+ # console in this one.
+ echo
+ echo -e "menuentry \"Vyatta OFR (Serial console)\" {"
+ echo -en "\tlinux /boot/vmlinuz root=/dev/$ROOT_PARTITION $ISCF console=tty0 console=ttyS0,9600 \n"
+ echo -e "\tinitrd /boot/initrd.img"
+ echo -e "}"
+
+ # Set third and fourth boot options for root password reset. Offer
+ # options for both serial and KVM console.
+
+ echo
+ echo -e "menuentry \"Root password reset to factory (KVM console)\" {"
+ echo -e "\tlinux /boot/vmlinuz root=/dev/$ROOT_PARTITION $ISCF console=ttyS0,9600 console=tty0 init=$PWRESET"
+ echo -e "\tinitrd /boot/initrd.img"
+ echo -e "}"
+
+ echo
+ echo -e "menuentry \"Root password reset to factory (Serial console)\" {"
+ echo -e "\tkernel /boot/vmlinuz root=/dev/$ROOT_PARTITION $ISCF console=tty0 console=ttyS0,9600 init=$PWRESET"
+ echo -e "\tinitrd /boot/initrd.img"
+ echo -e "}"
+ ) >"$rootfsdir/boot/grub/grub.cfg"
echo "OK"
}
diff --git a/scripts/keepalived/vyatta-keepalived.pl b/scripts/keepalived/vyatta-keepalived.pl
index fff1acf1..55d53715 100755
--- a/scripts/keepalived/vyatta-keepalived.pl
+++ b/scripts/keepalived/vyatta-keepalived.pl
@@ -86,6 +86,21 @@ sub keepalived_get_values {
}
}
+ $config->setLevel("$path vrrp vrrp-group $group run-transition-scripts");
+ my $run_backup_script = $config->returnValue("backup");
+ if(!defined $run_backup_script){
+ $run_backup_script = "null";
+ }
+ my $run_fault_script = $config->returnValue("fault");
+ if(!defined $run_fault_script){
+ $run_fault_script = "null";
+ }
+ my $run_master_script = $config->returnValue("master");
+ if(!defined $run_master_script){
+ $run_master_script = "null";
+ }
+
+
$output .= "vrrp_instance $vrrp_instance \{\n";
if ($preempt eq "false") {
$output .= "\tstate BACKUP\n";
@@ -110,11 +125,11 @@ sub keepalived_get_values {
}
$output .= "\t\}\n";
$output .= "\tnotify_master ";
- $output .= "\"$state_transition_script master $intf $group @vips\" \n";
+ $output .= "\"$state_transition_script master $intf $group $run_master_script @vips\" \n";
$output .= "\tnotify_backup ";
- $output .= "\"$state_transition_script backup $intf $group @vips\" \n";
+ $output .= "\"$state_transition_script backup $intf $group $run_backup_script @vips\" \n";
$output .= "\tnotify_fault ";
- $output .= "\"$state_transition_script fault $intf $group @vips\" \n";
+ $output .= "\"$state_transition_script fault $intf $group $run_fault_script @vips\" \n";
$output .= "\}\n";
}
diff --git a/scripts/keepalived/vyatta-show-vrrp.pl b/scripts/keepalived/vyatta-show-vrrp.pl
index eacba25c..86dbef3d 100755
--- a/scripts/keepalived/vyatta-show-vrrp.pl
+++ b/scripts/keepalived/vyatta-show-vrrp.pl
@@ -64,17 +64,26 @@ sub elapse_time {
return $string;
}
-sub link_updown {
- my ($intf) = @_;
-
- my $status = `sudo /usr/sbin/ethtool $intf | grep Link`;
- if ($status =~ m/yes/) {
- return "up";
+sub get_state_link {
+ my $intf = shift;
+
+ my $IFF_UP = 0x1;
+ my ($state, $link);
+ my $flags = `cat /sys/class/net/$intf/flags 2> /dev/null`;
+ my $carrier = `cat /sys/class/net/$intf/carrier 2> /dev/null`;
+ chomp $flags; chomp $carrier;
+ my $hex_flags = hex($flags);
+ if ($hex_flags & $IFF_UP) {
+ $state = "up";
+ } else {
+ $state = "admin down";
}
- if ($status =~ m/no/) {
- return "down";
+ if ($carrier eq "1") {
+ $link = "up";
+ } else {
+ $link = "down";
}
- return "unknown";
+ return ($state, $link);
}
sub get_master_info {
@@ -102,13 +111,33 @@ sub get_master_info {
}
}
+sub vrrp_showsummary {
+ my ($file) = @_;
+
+ my ($start_time, $intf, $group, $state, $ltime) =
+ VyattaKeepalived::vrrp_state_parse($file);
+ my ($interface_state, $link) = get_state_link($intf);
+ if ($state eq "master" || $state eq "backup" || $state eq "fault") {
+ my ($primary_addr, $priority, $preempt, $advert_int, $auth_type,
+ @vips) = VyattaKeepalived::vrrp_get_config($intf, $group);
+ print "\n$intf\t\t$group\tint\t$primary_addr\t$link\t\t$state";
+ foreach my $vip (@vips){
+ print "\n\t\t\tvip\t$vip";
+
+ }
+ } else {
+ print "Physical interface $intf, State: unknown\n";
+ }
+}
+
+
sub vrrp_show {
my ($file) = @_;
my $now_time = time;
my ($start_time, $intf, $group, $state, $ltime) =
VyattaKeepalived::vrrp_state_parse($file);
- my $link = link_updown($intf);
+ my ($interface_state, $link) = get_state_link($intf);
if ($state eq "master" || $state eq "backup" || $state eq "fault") {
my ($primary_addr, $priority, $preempt, $advert_int, $auth_type,
@vips) = VyattaKeepalived::vrrp_get_config($intf, $group);
@@ -146,9 +175,18 @@ sub vrrp_show {
#
my $intf = "eth";
my $group = "all";
+my $showsummary = 0;
+
if ($#ARGV >= 0) {
- $intf = $ARGV[0];
+
+ if ($ARGV[0] eq "summary") {
+ $showsummary = 1;
+ } else {
+ $intf = $ARGV[0];
+ }
+
}
+
if ($#ARGV == 1) {
$group = $ARGV[1];
}
@@ -158,9 +196,22 @@ if (!VyattaKeepalived::is_running()) {
exit 1;
}
+if ($showsummary == 1) {
+
+ print "\t\tVRRP\tAddr\t\t\tInterface\tVRRP\n";
+ print "Interface\tGroup\tType\tAddress\t\tState\t\tState\n";
+ print "---------\t-----\t----\t-------\t\t-----\t\t-----";
+
+
+}
+
my @state_files = VyattaKeepalived::get_state_files($intf, $group);
foreach my $state_file (@state_files) {
- vrrp_show($state_file);
+ if ($showsummary == 1) {
+ vrrp_showsummary($state_file);
+ } else {
+ vrrp_show($state_file);
+ }
}
exit 0;
diff --git a/scripts/keepalived/vyatta-vrrp-state.pl b/scripts/keepalived/vyatta-vrrp-state.pl
index 8b813529..9e11b649 100755
--- a/scripts/keepalived/vyatta-vrrp-state.pl
+++ b/scripts/keepalived/vyatta-vrrp-state.pl
@@ -55,7 +55,8 @@ sub vrrp_state_log {
my $vrrp_state = $ARGV[0];
my $vrrp_intf = $ARGV[1];
my $vrrp_group = $ARGV[2];
-my $vrrp_vip = $ARGV[3];
+my $vrrp_transitionscript = $ARGV[3];
+my $vrrp_vip = $ARGV[4];
my $sfile = VyattaKeepalived::get_state_file($vrrp_intf, $vrrp_group);
my ($old_time, $old_intf, $old_group, $old_state, $old_ltime) =
@@ -77,6 +78,12 @@ if ($vrrp_state eq "backup") {
system("rm -f $mfile");
}
+
+if (!($vrrp_transitionscript eq "null")){
+ exec("$vrrp_transitionscript");
+}
+
+
exit 0;
# end of file
diff --git a/scripts/rl-system.init b/scripts/rl-system.init
index a70c0a46..5b81a4fd 100755
--- a/scripts/rl-system.init
+++ b/scripts/rl-system.init
@@ -50,8 +50,7 @@ fi
syslog ()
{
-
- date -u "+%b %d %H:%M:%S $hostname $progname: $*" >> $LOGFILE
+ logger -p user.warning -t "$progname" "$*"
}
shopt -s extglob nullglob
@@ -158,8 +157,6 @@ start () {
log_failure_msg "can\'t set reboot on panic"
add_new_serial_if || \
log_failure_msg "can\'t add serial interfaces"
- proc_flags || \
- log_failure_msg "can\'t reset proc flags"
update_version_info
clear_apt_config
add_snmp_stats_module
diff --git a/scripts/snmp/vyatta-snmp.pl b/scripts/snmp/vyatta-snmp.pl
index 0301a041..ea77f7b7 100644
--- a/scripts/snmp/vyatta-snmp.pl
+++ b/scripts/snmp/vyatta-snmp.pl
@@ -34,7 +34,8 @@ use warnings;
my $mibdir = '/opt/vyatta/share/snmp/mibs';
my $snmp_init = '/opt/vyatta/sbin/snmpd.init';
my $snmp_conf = '/etc/snmp/snmpd.conf';
-
+my $snmp_snmpv3_user_conf = '/usr/share/snmp/snmpd.conf';
+my $snmp_snmpv3_createuser_conf = '/var/lib/snmp/snmpd.conf';
sub snmp_init {
#
@@ -61,8 +62,10 @@ sub snmp_get_constants {
my $date = `date`;
chomp $date;
$output = "#\n# autogenerated by vyatta-snmp.pl on $date\n#\n";
- $output .= "trap2sink localhost vyatta 51510\n";
$output .= "sysServices 14\n";
+ $output .= "smuxpeer .1.3.6.1.4.1.3317.1.2.2\n"; # ospfd
+ $output .= "smuxpeer .1.3.6.1.4.1.3317.1.2.5\n"; # bgpd
+ $output .= "smuxpeer .1.3.6.1.4.1.3317.1.2.3\n"; # ripd
return $output;
}
@@ -121,14 +124,38 @@ sub snmp_get_values {
$output .= "syslocation \"$location\" \n";
}
- my @trap_targets = $config->returnValues("trap-target");
+ my @trap_targets = $config->returnValues("trap-target");
+ if ($#trap_targets >= 0) {
+ # code for creating a snmpv3 user, setting access-level for it and use user to do internal snmpv3 requests
+ snmp_create_snmpv3_user();
+ snmp_write_snmpv3_user();
+ $output .= "iquerySecName vyatta\n";
+ # code to activate link up down traps
+ $output .= "linkUpDownNotifications yes\n";
+ }
foreach my $trap_target (@trap_targets) {
- $output .= "trapsink $trap_target\n";
+ $output .= "trap2sink $trap_target\n";
}
return $output;
}
+sub snmp_create_snmpv3_user {
+
+ my $createuser = "createUser vyatta MD5 \"vyatta\" DES";
+ open(my $fh, '>>', $snmp_snmpv3_createuser_conf) || die "Couldn't open $snmp_snmpv3_createuser_conf - $!";
+ print $fh $createuser;
+ close $fh;
+}
+
+sub snmp_write_snmpv3_user {
+
+ my $user = "rwuser vyatta";
+ open(my $fh, '>', $snmp_snmpv3_user_conf) || die "Couldn't open $snmp_snmpv3_user_conf - $!";
+ print $fh $user;
+ close $fh;
+}
+
sub snmp_write_file {
my ($config) = @_;