python實(shí)現(xiàn)系統(tǒng)狀態(tài)監(jiān)測和故障轉(zhuǎn)移實(shí)例方法
#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
#!/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)文章
python中print的不換行即時(shí)輸出的快速解決方法
下面小編就為大家?guī)硪黄猵ython中print的不換行即時(shí)輸出的快速解決方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考2016-07-07
Python中選擇結(jié)構(gòu)實(shí)例講解
在本篇文章里小編給大家整理了關(guān)于Python選擇結(jié)構(gòu)的基礎(chǔ)知識(shí)點(diǎn)及相關(guān)實(shí)例,有需要的朋友們可以學(xué)習(xí)參考下。2022-11-11
python使用pymysql實(shí)現(xiàn)操作mysql
本文給大家講解的是在python中使用pymysql實(shí)現(xiàn)操作mysql的方法匯總,非常的簡單實(shí)用,有需要的小伙伴可以參考下2016-09-09
Python類的動(dòng)態(tài)修改的實(shí)例方法
這篇文章主要介紹了Python類的動(dòng)態(tài)修改的實(shí)例方法的相關(guān)資料,需要的朋友可以參考下2017-03-03
Python定時(shí)執(zhí)行之Timer用法示例
這篇文章主要介紹了Python定時(shí)執(zhí)行之Timer用法,實(shí)例分析了Timer模塊的原理及相關(guān)使用技巧,需要的朋友可以參考下2015-05-05
Django使用Celery異步任務(wù)隊(duì)列的使用
這篇文章主要介紹了Django使用Celery異步任務(wù)隊(duì)列的使用,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-03-03
pandas 如何保存數(shù)據(jù)到excel,csv
這篇文章主要介紹了pandas 如何保存數(shù)據(jù)到excel,csv的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07

