SMTP záloha

Z HKfree wiki
Skočit na navigaci Skočit na vyhledávání

jak na to

skript

<bash>#!/bin/bash

  1. IP, kterou nas server natahne na sebe

ROUTE_IP="10.107.3.4"

  1. IP, ktera bude testovana zda-li na ni bezi smtp

WATCH_IP="10.107.35.1" # yzop.hkfree.org WATCH_PORT="25"

  1. heslo do zebry

ENAPASS="$(cat /root/smtp-redir-pokus/zebrapass)"

[ "$ENAPASS" == "" ] && { neni definovane zebra heslo! ; exit 1; }

ip_on(){

  1. nahodime na slave mobilni IP

ifconfig dummy0:40 $ROUTE_IP netmask 255.255.255.255 broadcast $ROUTE_IP up

  1. nastavime ji do lokalni zebry

cat << EoF | nc localhost zebra > /dev/null free enable $ENAPASS configure terminal ip route $ROUTE_IP/32 127.0.0.1 quit quit

EoF

  1. pokud zije ssh na master serveru, shodit u nej mobilni IP

nc -w 3 -z $WATCH_IP 22 && ssh lada@yzop.hkfree.org sudo ifdown dummy0:30

}

ip_off(){

  1. zrusime na slave mobilni IP

ifconfig dummy0:40 down

  1. smazeme ji z lokalni zebry

cat << EoF | nc localhost zebra > /dev/null free enable $ENAPASS configure terminal no ip route $ROUTE_IP/32 127.0.0.1 quit quit

EoF

  1. pokud zije ssh na master serveru, nahodit mobilni IP

nc -w 3 -z $WATCH_IP 22 && ssh lada@yzop.hkfree.org sudo ifup dummy0:30 }

  1. zkusime 2x, jestli port odpovida

master_online(){ nc -w 3 -z $WATCH_IP $WATCH_PORT || nc -w 3 -z $WATCH_IP $WATCH_PORT }

  1. je mobilni IP na slave stroji?

slave_active(){ cat << EoF | nc localhost zebra | grep -q "$ROUTE_IP" free show ip route static exit

EoF }

  1. pravidelna kontrola

do_cronjob(){ MASTERUP=0 master_online && MASTERUP=1

SLAVEACT=0 slave_active && SLAVEACT=1

if [ "$MASTERUP" == "0" ]; then if [ "$SLAVEACT" == "0" ]; then echo "Zapinam zalozni IP" ip_on fi fi

if [ "$MASTERUP" == "1" ]; then if [ "$SLAVEACT" == "1" ]; then echo "Vypinam zalozni IP" ip_off fi fi }

case "$1" in cronjob) do_cronjob; exit 0 ;; on) echo Slave prebira veleni; ip_on ; exit 0;; off) echo Slave vraci veleni masterovi; ip_off; exit 0;; test) echo testuju; master_online && echo Master bezi; master_online || echo Master nebezi; exit 0;; active) slave_active || echo Slave neni aktivni; slave_active && echo Slave je aktivni; exit 0;;

  • ) echo "usage: $0 cronjob|on|off|test|active";exit 0;;

esac

exit 0 </bash>