欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python實(shí)現(xiàn)系統(tǒng)狀態(tài)監(jiān)測(cè)和故障轉(zhuǎn)移實(shí)例方法

 更新時(shí)間:2013年11月18日 10:51:51   作者:  
這篇文章主要介紹了用python實(shí)現(xiàn)系統(tǒng)狀態(tài)監(jiān)測(cè)和故障轉(zhuǎn)移的代碼方法

復(fù)制代碼 代碼如下:

#coding: utf-8
import socket
import select
import time
import os
import threading

def ser():
    s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
    s.bind(("",43244))
    while 1:
        infds,outfds,errfds = select.select([s],[],[],5)
        if infds:
            sms = s.recv(1024)
            if sms=="alived":
                print "peer is alived"
        else:
            print "Can't hear peer!"
            os.system("./failover.sh")

def clt():   
    while 1:
       sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 
       sock.connect(('192.168.10.1', 43244))
       sock.send("alived")
       time.sleep(2)

if __name__=="__main__":
    ser=threading.Thread(target=ser)
    clt=threading.Thread(target=clt)
    ser.start()
    clt.start()
    ser.join()
    clt.join()

failover.sh

復(fù)制代碼 代碼如下:

#!/bin/bash

vip=8.8.8.8

vip_local=`ifconfig |grep -A 1 "eth0:0" |awk '/inet addr/{print $2}'|cut -d ":" -f2`

if [ ! $vip_local ];then ifconfig eth0:0 $vip netmask 255.255.255.0 up;fi

相關(guān)文章

最新評(píng)論