From 84475594cce023f7ed420813c41a7dc2ab33765c Mon Sep 17 00:00:00 2001 From: Ciaby Date: Mon, 14 Jul 2014 14:23:00 -0500 Subject: [PATCH] Added basic utilities. --- .../files/bin/bind_check.sh | 12 +++++ .../files/bin/capture_traffic.sh | 10 ++++ .../files/bin/check_amp_status.sh | 4 ++ .../files/bin/check_status.sh | 4 ++ .../files/bin/log_broken_channels.sh | 13 +++++ .../files/bin/turn_on_amplifier.sh | 34 ++++++++++++ .../rhizomatica_base_system/manifests/init.pp | 52 ++++++++++++------- .../templates/vars.sh.erb | 3 ++ 8 files changed, 113 insertions(+), 19 deletions(-) create mode 100755 modules/rhizomatica_base_system/files/bin/bind_check.sh create mode 100755 modules/rhizomatica_base_system/files/bin/capture_traffic.sh create mode 100755 modules/rhizomatica_base_system/files/bin/check_amp_status.sh create mode 100755 modules/rhizomatica_base_system/files/bin/check_status.sh create mode 100755 modules/rhizomatica_base_system/files/bin/log_broken_channels.sh create mode 100755 modules/rhizomatica_base_system/files/bin/turn_on_amplifier.sh create mode 100644 modules/rhizomatica_base_system/templates/vars.sh.erb diff --git a/modules/rhizomatica_base_system/files/bin/bind_check.sh b/modules/rhizomatica_base_system/files/bin/bind_check.sh new file mode 100755 index 0000000..1768050 --- /dev/null +++ b/modules/rhizomatica_base_system/files/bin/bind_check.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +currdate=`date` + +if (grep 'but not bound for Rx' /var/log/osmo-nitb/current > /dev/null); then + echo -e "$currdate - OpenBSC lost RX bind" >> /var/log/bind_check.log + /etc/init.d/kannel restart >/dev/null + :>/var/log/osmo-nitb/current + echo -e "$currdate - Restarted kannel and cleared osmo-nitb log" >> /var/log/bind_check.log +else + echo -e "$currdate - OpenBSC has the RX bind" >> /var/log/bind_check.log +fi diff --git a/modules/rhizomatica_base_system/files/bin/capture_traffic.sh b/modules/rhizomatica_base_system/files/bin/capture_traffic.sh new file mode 100755 index 0000000..5aba194 --- /dev/null +++ b/modules/rhizomatica_base_system/files/bin/capture_traffic.sh @@ -0,0 +1,10 @@ +#!/bin/bash -x +TCPDUMP="/usr/sbin/tcpdump" +CAPTURE_DEVICE="eth1" +CAPTURE_PORTS="port 3002 or port 3003" +CAPTURE_LIMIT="1024" +CAPTURE_SIZE="1" +CAPTURE_BASENAME="/tmp/tcpdump-capture-" +CAPTURE_COMPRESS="-z /usr/sbin/tcpdump-compress" +CAPTURE_OPTIONS="-pi $CAPTURE_DEVICE -s0 -w $CAPTURE_BASENAME -C $CAPTURE_SIZE -W $CAPTURE_LIMIT $CAPTURE_COMPRESS $CAPTURE_PORTS" +$TCPDUMP $CAPTURE_OPTIONS diff --git a/modules/rhizomatica_base_system/files/bin/check_amp_status.sh b/modules/rhizomatica_base_system/files/bin/check_amp_status.sh new file mode 100755 index 0000000..efed5e4 --- /dev/null +++ b/modules/rhizomatica_base_system/files/bin/check_amp_status.sh @@ -0,0 +1,4 @@ +#!/bin/sh +. ./vars.sh +echo "BTS1: " +ssh root@$BTS1 sbts2050-util sbts2050-pwr-status | grep Amp diff --git a/modules/rhizomatica_base_system/files/bin/check_status.sh b/modules/rhizomatica_base_system/files/bin/check_status.sh new file mode 100755 index 0000000..74bfd03 --- /dev/null +++ b/modules/rhizomatica_base_system/files/bin/check_status.sh @@ -0,0 +1,4 @@ +#!/bin/sh +. ./vars.sh +echo "BTS1: " +ssh root@$BTS1 sbts2050-util sbts2050-pwr-status diff --git a/modules/rhizomatica_base_system/files/bin/log_broken_channels.sh b/modules/rhizomatica_base_system/files/bin/log_broken_channels.sh new file mode 100755 index 0000000..ad60b2e --- /dev/null +++ b/modules/rhizomatica_base_system/files/bin/log_broken_channels.sh @@ -0,0 +1,13 @@ +#!/bin/bash +. ./vars.sh + +while (true); +do STR=`echo "show lchan" | nc localhost 4242 | grep BROKEN`; + +if [ -n "$STR" ]; + then echo `date "+%y%m%d_%H%M"` >> /var/tmp/broken_channels_log.txt; + STR=`echo "show lchan" | nc localhost 4242`; + echo -e "Subject:BROKEN Channels\n\nBroken at: `date`\n\n\n$STR" | sendmail $RECIPIENTS +fi; +sleep 600; +done diff --git a/modules/rhizomatica_base_system/files/bin/turn_on_amplifier.sh b/modules/rhizomatica_base_system/files/bin/turn_on_amplifier.sh new file mode 100755 index 0000000..81e9dd4 --- /dev/null +++ b/modules/rhizomatica_base_system/files/bin/turn_on_amplifier.sh @@ -0,0 +1,34 @@ +#!/bin/bash +. ./vars.sh + +echo "Beginning amplifier procedure... brace yourself!" + +echo "turning off osmo-nitb and kannel" +sv stop osmo-nitb +/etc/init.d/kannel stop + +echo "Rebooting first BTS" +ssh root@$BTS1 "/sbin/reboot" + +echo "sleeping 30 seconds..." +sleep 30 + +echo "turning off the second BTS" +ssh root@$BTS1 "/usr/bin/sbts2050-util sbts2050-pwr-enable 1 0 0" + +echo "sleeping 10 seconds..." +sleep 10 + +echo "turning on the amplifier" +ssh root@$BTS1 "/usr/bin/sbts2050-util sbts2050-pwr-enable 1 0 1" + +echo "sleeping 10 seconds..." +sleep 10 + +echo "turning back on the second BTS" +ssh root@$BTS1 "/usr/bin/sbts2050-util sbts2050-pwr-enable 1 1 1" + +echo "turning on osmo-nitb and kannel" +sv start osmo-nitb +sleep 10 +/etc/init.d/kannel start diff --git a/modules/rhizomatica_base_system/manifests/init.pp b/modules/rhizomatica_base_system/manifests/init.pp index 6e99633..549a604 100644 --- a/modules/rhizomatica_base_system/manifests/init.pp +++ b/modules/rhizomatica_base_system/manifests/init.pp @@ -12,20 +12,34 @@ # class rhizomatica_base_system { - $vpn_address = hiera('rhizo::vpn_address') - $postgresql_password = hiera('rhizo::postgresql_password') - $smsc_password= hiera('rhizo::smsc_password') - $kannel_admin_password = ('rhizo::kannel_admin_password') + $vpn_address = hiera('rhizo::vpn_address') + $bts1_address = hiera('rhizo::bts1_address') + $mail_admins = hiera('rhizo::mail_admins') + $postgresql_password = hiera('rhizo::postgresql_password') + $smsc_password = hiera('rhizo::smsc_password') + $kannel_admin_password = hiera('rhizo::kannel_admin_password') $kannel_sendsms_password = hiera('rhizo::kannel_sendsms_password') - include 'ntp' - include 'kannel' + include ntp + include kannel file { '/etc/apt/apt.conf.d/90unsigned': ensure => present, content => 'APT::Get::AllowUnauthenticated "true";', } - + + file { '/home/rhizomatica/bin': + ensure => directory, + source => 'puppet:///modules/rhizomatica_base_system/bin', + recurse => true, + purge => false, + } + + file { '/home/rhizomatica/bin/vars.sh': + ensure => present, + content => template('rhizomatica_base_system/vars.sh.erb'), + } + class { 'apt': } apt::source { 'rhizomatica': @@ -73,26 +87,26 @@ class rhizomatica_base_system { file { '/etc/sv': ensure => directory, - source => "puppet:///modules/rhizomatica_base_system/etc/sv", + source => 'puppet:///modules/rhizomatica_base_system/etc/sv', recurse => true, require => Package['runit'], } file { '/etc/service/osmo-nitb': ensure => link, - target => "/etc/sv/osmo-nitb", - require => File['/etc/sv'], + target => '/etc/sv/osmo-nitb', + require => [ File['/etc/sv'], Package['osmocom-nitb'] ], } -file { '/etc/service/freeswitch': + file { '/etc/service/freeswitch': ensure => link, - target => "/etc/sv/freeswitch", - require => File['/etc/sv'], + target => '/etc/sv/freeswitch', + require => [ File['/etc/sv'], Package['freeswitch'] ], } -file { '/etc/service/rapi': + file { '/etc/service/rapi': ensure => link, - target => "/etc/sv/rapi", + target => '/etc/sv/rapi', require => File['/etc/sv'], } @@ -102,11 +116,11 @@ file { '/etc/service/rapi': } class { 'riak': - version => '1.4.7-1', - template => 'rhizomatica_base_system/app.config.erb', + version => '1.4.7-1', + template => 'rhizomatica_base_system/app.config.erb', vmargs_template => 'rhizomatica_base_system/vm.args.erb', } - + class { 'python': version => 'system', pip => true, @@ -143,4 +157,4 @@ file { '/etc/service/rapi': require => Apt::Source['rhizomatica'], } -} + } diff --git a/modules/rhizomatica_base_system/templates/vars.sh.erb b/modules/rhizomatica_base_system/templates/vars.sh.erb new file mode 100644 index 0000000..2ed0b04 --- /dev/null +++ b/modules/rhizomatica_base_system/templates/vars.sh.erb @@ -0,0 +1,3 @@ +#!/bin/sh +BTS1=<%= @bts1_address %> +RECIPIENTS=<%= @mail_admins %>