Initial refactoring

Renamed rhizomatica_base_system to rhizo_base
Split up the init.pp in different subclasses
More work to follow
This commit is contained in:
Ciaby 2015-05-18 14:01:31 -05:00
parent 7b938abede
commit 1c7dffc32a
192 changed files with 547 additions and 430 deletions

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,8 @@
#!/bin/bash
# Check for AMP status on each BTS, from BTS1 up to BTS3
RHIZO_SCRIPT="/home/rhizomatica/bin"
. $RHIZO_SCRIPT/vars.sh
for bts in $BTS1 $BTS2 $BTS3; do
echo "BTS $bts:";
ssh root@$bts sbts2050-util sbts2050-pwr-status | grep Amp;
done

View file

@ -0,0 +1,14 @@
#!/bin/bash
RHIZO_SCRIPT="/home/rhizomatica/bin"
. $RHIZO_SCRIPT/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

View file

@ -0,0 +1,11 @@
#!/bin/bash
RHIZO_SCRIPT="/home/rhizomatica/bin"
. $RHIZO_SCRIPT/vars.sh
LOGFILE="/var/log/monitor_amp.log"
$RHIZO_SCRIPT/check_amp_status.sh | grep -q OFF
if [ $? == 0 ]; then
logc "Amplifier is OFF! Turn on amp"
$RHIZO_SCRIPT/turn_on_amplifier.sh >/dev/null 2>&1
logc 'Procedure completed'
fi

View file

@ -0,0 +1,16 @@
#!/bin/bash
LOGFILE="/var/log/monitor_rapi.log"
function logc() {
txt=$1
echo "[`date '+%d-%m-%Y %H:%M:%S'`] $txt" >> $LOGFILE
}
curl --connect-timeout 180 --max-time 180 -X GET http://localhost:8085/configuration/site 2>/dev/null
if [ $? -gt 0 ]; then
logc "RAPI is not responding kill the process"
PID=`ps axf | grep rapi | grep python | awk '{print $1}'`
kill -9 $PID
logc "RAPI restarted"
fi

View file

@ -0,0 +1,112 @@
#!/bin/bash
# Username to connect to database as. Will default to "postgres" if none specified.
USERNAME=postgres
# This dir will be created if it doesn't exist. This must be writable by the user the script is
# running as.
BACKUP_DIR=/var/rhizo_backups/postgresql/
# Will produce a custom-format backup if set to "yes"
ENABLE_CUSTOM_BACKUPS=yes
# Will produce a gzipped plain-format backup if set to "yes"
ENABLE_PLAIN_BACKUPS=yes
# Which day to take the weekly backup from (1-7 = Monday-Sunday)
DAY_OF_WEEK_TO_KEEP=6
# Number of days to keep daily backups
DAYS_TO_KEEP=7
# How many weeks to keep weekly backups
WEEKS_TO_KEEP=5
function perform_backups()
{
SUFFIX=$1
FINAL_BACKUP_DIR=$BACKUP_DIR"`date +\%Y-\%m-\%d`$SUFFIX/"
echo "Making backup directory in $FINAL_BACKUP_DIR"
if ! mkdir -p $FINAL_BACKUP_DIR; then
echo "Cannot create backup directory in $FINAL_BACKUP_DIR. Go and fix it!" 1>&2
exit 1;
fi;
###########################
###### FULL BACKUPS #######
###########################
FULL_BACKUP_QUERY="select datname from pg_database where not datistemplate and datallowconn order by datname;"
echo -e "\n\nPerforming full backups"
echo -e "--------------------------------------------\n"
for DATABASE in `psql -U "$USERNAME" -At -c "$FULL_BACKUP_QUERY" postgres`
do
if [ $ENABLE_PLAIN_BACKUPS = "yes" ]
then
echo "Plain backup of $DATABASE"
if ! pg_dump -Fp -U "$USERNAME" "$DATABASE" | gzip > $FINAL_BACKUP_DIR"$DATABASE".sql.gz.in_progress; then
echo "[!!ERROR!!] Failed to produce plain backup database $DATABASE" 1>&2
else
mv $FINAL_BACKUP_DIR"$DATABASE".sql.gz.in_progress $FINAL_BACKUP_DIR"$DATABASE".sql.gz
fi
fi
if [ $ENABLE_CUSTOM_BACKUPS = "yes" ]
then
echo "Custom backup of $DATABASE"
if ! pg_dump -Fc -U "$USERNAME" "$DATABASE" -f $FINAL_BACKUP_DIR"$DATABASE".custom.in_progress; then
echo "[!!ERROR!!] Failed to produce custom backup database $DATABASE"
else
mv $FINAL_BACKUP_DIR"$DATABASE".custom.in_progress $FINAL_BACKUP_DIR"$DATABASE".custom
fi
fi
done
echo -e "\nAll database backups complete!"
}
# MONTHLY BACKUPS
DAY_OF_MONTH=`date +%d`
if [ $DAY_OF_MONTH -eq 1 ];
then
# Delete all expired monthly directories
find $BACKUP_DIR -maxdepth 1 -name "*-monthly" -exec rm -rf '{}' ';'
perform_backups "-monthly"
exit 0;
fi
# WEEKLY BACKUPS
DAY_OF_WEEK=`date +%u` #1-7 (Monday-Sunday)
EXPIRED_DAYS=`expr $((($WEEKS_TO_KEEP * 7) + 1))`
if [ $DAY_OF_WEEK = $DAY_OF_WEEK_TO_KEEP ];
then
# Delete all expired weekly directories
find $BACKUP_DIR -maxdepth 1 -mtime +$EXPIRED_DAYS -name "*-weekly" -exec rm -rf '{}' ';'
perform_backups "-weekly"
exit 0;
fi
# DAILY BACKUPS
# Delete daily backups 7 days old or more
find $BACKUP_DIR -maxdepth 1 -mtime +$DAYS_TO_KEEP -name "*-daily" -exec rm -rf '{}' ';'
perform_backups "-daily"

View file

@ -0,0 +1,87 @@
#!/bin/bash
#Where the SQLite file is located
DATABASE_FILE=/var/lib/osmocom/hlr.sqlite3
#Name of the database backup
DATABASE_NAME=hlr
# This dir will be created if it doesn't exist.
BACKUP_DIR=/var/rhizo_backups/sqlite/
# Which day to take the weekly backup from (1-7 = Monday-Sunday)
DAY_OF_WEEK_TO_KEEP=6
# Number of days to keep daily backups
DAYS_TO_KEEP=7
# How many weeks to keep weekly backups
WEEKS_TO_KEEP=5
function perform_backups()
{
SUFFIX=$1
FINAL_BACKUP_DIR=$BACKUP_DIR"`date +\%Y-\%m-\%d`$SUFFIX/"
echo "Making backup directory in $FINAL_BACKUP_DIR"
if ! mkdir -p $FINAL_BACKUP_DIR; then
echo "Cannot create backup directory in $FINAL_BACKUP_DIR. Go and fix it!" 1>&2
exit 1;
fi;
###########################
###### FULL BACKUPS #######
###########################
echo -e "\n\nPerforming full backup"
echo -e "--------------------------------------------\n"
echo "Plain backup of $DATABASE_FILE"
if ! sqlite3 "$DATABASE_FILE" ".dump" | gzip > $FINAL_BACKUP_DIR"$DATABASE_NAME".sql.gz.in_progress; then
echo "[!!ERROR!!] Failed to produce plain backup database $DATABASE_FILE" 1>&2
else
mv $FINAL_BACKUP_DIR"$DATABASE_NAME".sql.gz.in_progress $FINAL_BACKUP_DIR"$DATABASE_NAME".sql.gz
fi
echo -e "\nDatabase backup complete!"
}
# MONTHLY BACKUPS
DAY_OF_MONTH=`date +%d`
if [ $DAY_OF_MONTH -eq 1 ];
then
# Delete all expired monthly directories
find $BACKUP_DIR -maxdepth 1 -name "*-monthly" -exec rm -rf '{}' ';'
perform_backups "-monthly"
exit 0;
fi
# WEEKLY BACKUPS
DAY_OF_WEEK=`date +%u` #1-7 (Monday-Sunday)
EXPIRED_DAYS=`expr $((($WEEKS_TO_KEEP * 7) + 1))`
if [ $DAY_OF_WEEK = $DAY_OF_WEEK_TO_KEEP ];
then
# Delete all expired weekly directories
find $BACKUP_DIR -maxdepth 1 -mtime +$EXPIRED_DAYS -name "*-weekly" -exec rm -rf '{}' ';'
perform_backups "-weekly"
exit 0;
fi
# DAILY BACKUPS
# Delete daily backups 7 days old or more
find $BACKUP_DIR -maxdepth 1 -mtime +$DAYS_TO_KEEP -name "*-daily" -exec rm -rf '{}' ';'
perform_backups "-daily"

View file

@ -0,0 +1,10 @@
#!/bin/bash
# Turn on AMP on all BTS, from BTS1 to BTS3
RHIZO_SCRIPT="/home/rhizomatica/bin"
. $RHIZO_SCRIPT/vars.sh
LOGFILE="/var/log/monitor_amp.log"
for bts in $BTS1 $BTS2 $BTS3; do
logc "Turning on AMP on BTS $bts:";
ssh root@$bts "sbts2050-util sbts2050-pwr-enable 1 1 1";
done