1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #################################################################################### #coding=utf-8 #脚本用途:P2PRELAY升级脚本 #编写时间:2016年8月24日 #脚本作者:乐橙运维组 #################################################################################### #!/usr/bin/env python #载入模块 import os import time #备份原有server并且复制新的server.tar.gz def copy(): os.system( "mv /opt/server/ /opt/server-bak/" ) os.system( "cp /share/yunwei/server.tar.gz /opt" ) os.system( "tar -zxvf /opt/server.tar.gz -C /opt/" ) #拷贝P2PRelay.conf和RelayCount.txt def change_ip(): os.system( "cp -rf /opt/server-bak/P2PRelay.conf /opt/server/" ) os.system( "chmod 755 /opt/server/*" ) os.system( "cp -rf /opt/server-bak/RelayCount.txt /opt/server/" ) #杀死原有的运行程序,并用Dog重新将程序拉起 def kill_start(): print "杀死原有P2P进程,中途会有五秒钟间隔。" os.system( "ps -ef | grep P2PRelayDog | grep -v grep | awk '{print $2}' | xargs kill -9" ) time.sleep( 5 ) os.system( "ps -ef | grep P2PRelay | grep -v grep | awk '{print $2}' | xargs kill -9 " ) print "现在重新启动P2P。" os.system( "cd /opt/server && nohup ./P2PRelayDog.py>/dev/null &" ) os.system( "ps -ef|grep cd|grep -v grep|awk '{print $2}'|xargs kill -9" ) os.system( "ps -ef | grep P2P" ) if __name__ = = '__main__' : copy() change_ip() kill_start() print "整个脚本执行完毕,感谢您的使用!" |