shell命令

部署ngix 之後發現 部署項目就變得麻煩起來了 之前總是部署一臺tocmat現在要部署n多臺

然後就發現同事寫了個腳本解決了這個問題

就是再taoguan平級目錄下命名了一個tomcat.py的腳本 然後在該目錄下./tomcat.py cp就可以了




import subprocess
import os
import sys
import glob
import time


path = "/usr/local/taoguan/";
tomcat1=path+"tomcat7-1/";
tomcat2=path+"tomcat7-2/";
tomcat3=path+"tomcat7-3/";
tomcat4=path+"tomcat7-4/";
tomcat5=path+"tomcat7-5/";
tomcat6=path+"tomcat7-6/";




#清空日誌
def clearlog():
print '清理tomcat1日誌';
map(os.remove, glob.glob(tomcat1 + "logs/*"))
        map(os.remove, glob.glob(tomcat1 + "idalog/*"))
print '清理tomcat2日誌';
map(os.remove, glob.glob(tomcat2 + "logs/*"))
        map(os.remove, glob.glob(tomcat2 + "idalog/*"))
        print '清理tomcat3日誌';
        map(os.remove, glob.glob(tomcat3 + "logs/*"))
        map(os.remove, glob.glob(tomcat3 + "idalog/*"))
        print '清理tomcat4日誌';
        map(os.remove, glob.glob(tomcat4 + "logs/*"))
        map(os.remove, glob.glob(tomcat4 + "idalog/*"))
        print '清理tomcat5日誌';
        map(os.remove, glob.glob(tomcat5 + "logs/*"))
        map(os.remove, glob.glob(tomcat5 + "idalog/*"))
        print '清理tomcat6日誌';
        map(os.remove, glob.glob(tomcat6 + "logs/*"))
map(os.remove, glob.glob(tomcat6 + "idalog/*"))


#啓動tomcat
def startup():
print '啓動tomcat1.....';
subprocess.call(tomcat1+"bin/startup.sh",shell=True);
print '啓動tomcat2.....';
subprocess.call(tomcat2+"bin/startup.sh",shell=True);
print '啓動tomcat3.....';
subprocess.call(tomcat3+"bin/startup.sh",shell=True);
print '啓動tomcat4.....';
subprocess.call(tomcat4+"bin/startup.sh",shell=True);
print '啓動tomcat5.....';
subprocess.call(tomcat5+"bin/startup.sh",shell=True);
print '啓動tomcat6.....';
subprocess.call(tomcat6+"bin/startup.sh",shell=True);
time.sleep(1);
print 'tomcat啓動完成';
        pid();
#關閉tomcat
def stop():
print '關閉tomcat......';
p =  subprocess.call("kill -9 `ps -ef | grep java| grep tomcat7 |grep -v /bin/sh | awk '{print $2}'`",shell=True);
time.sleep(1);
print '關閉完成';
pid();


#顯示進程
def pid():
print '顯示tomcat進程';
p = subprocess.call("ps -ef | grep java |grep tomcat7 | grep -v /bin/sh",shell=True);
#重啓tomcat
def restart():
stop();
startup();
#cp
def cp():
print '部署idaplusweb...........';
subprocess.call("cp -rf /usr/local/taoguan/idaplusweb/* "+tomcat1+"webapps/idaplusweb/",shell=True);
subprocess.call("cp -rf /usr/local/taoguan/idaplusweb/* "+tomcat2+"webapps/idaplusweb/",shell=True);
subprocess.call("cp -rf /usr/local/taoguan/idaplusweb/* "+tomcat3+"webapps/idaplusweb/",shell=True);
subprocess.call("cp -rf /usr/local/taoguan/idaplusweb/* "+tomcat4+"webapps/idaplusweb/",shell=True);
subprocess.call("cp -rf /usr/local/taoguan/idaplusweb/* "+tomcat5+"webapps/idaplusweb/",shell=True);
subprocess.call("cp -rf /usr/local/taoguan/idaplusweb/* "+tomcat6+"webapps/idaplusweb/",shell=True);
print '部署idaplusweb結束';
def main():
print "Usage:"+sys.argv[0]+"{start 啓動|restart 重啓|stop 關機|pid 查看進程|clog 清理日誌|cp 部署服務}"


if __name__ == "__main__":
if len(sys.argv) == 2:
pass;
else:
main();
sys.exit();


tmp = sys.argv[1];
if tmp == "start":
startup();
elif tmp == "restart":
restart();
elif tmp == "stop":
stop();
elif tmp == "pid":
pid();
elif tmp == "clog":
clearlog();
elif tmp == "cp":
cp();
else:
main();

發佈了100 篇原創文章 · 獲贊 11 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章