tomcat啟動與關閉指令碼

2021-10-07 22:08:03 字數 1942 閱讀 5213

需求:

apache-tomcat-7.0.37

python2.*

#!/usr/bin/evn python

# _*_ coding:utf-8 _*_

import commands

import time

###############redmain################

#此指令碼只能用於tomcat服務restart。如果有新的tomcat需要修改以下三點

#1、把tomcat原始檔路徑寫入classpath=""中

#2、把tomcat快取路徑寫到tomcatcache=""

#3、修改當前啟動的tomcat埠在指令碼最下方有tomcat_port='8000'引數,這裡預設是8000

#切記:以上兩點必須絕對路徑,乙個指令碼只能對應乙個tomcat

classpath = "/opt/apache-tomcat-7.0.37"

tomcatcache = "/opt/apache-tomcat-7.0.37/work"

file_time = time.strftime('%y%m%d_%h:%m:%s')

def tomcat_start():

print("正在啟動.....")

time.sleep(5)

start_status,start_tomcat = commands.getstatusoutput("/bin/bash %s/bin/startup.sh" % classpath)

print(start_status,start_tomcat)

def tomcat_cache_mv():

mv_command = ("mv %s/catalina %s/catalina_%s" % (tomcatcache,tomcatcache,file_time))

commands.getstatusoutput(mv_command)

print("快取移動中.....")

time.sleep(5)

file_status,file_none = commands.getstatusoutput("ls %s/*_%s" % (tomcatcache,file_time))

print(file_none)

if file_none == "":

print("快取已移動,%s自動啟動中!" % classpath)+time.strftime(' == %y%m%d %h:%m:%s')

def tomcat_stop():

print("%s關閉中....!" % classpath)+time.strftime(' == %y%m%d %h:%m:%s')

commands.getstatusoutput("kill -9 %s" % pids)

time.sleep(5)

if __name__ == "__main__":

tomcat_port = "8000"

status,pids = commands.getstatusoutput("ps aux | grep %s | grep -v 'grep' | awk ''"% classpath)

tomcat_post_status,tomcat_post = commands.getstatusoutput("netstat -luntp| grep %s" % tomcat_port)

if pids == "" and tomcat_post =="":

print("%s未啟用!" % classpath)

tomcat_cache_mv()

tomcat_start()

else:

print("%s正在動行,即將關閉tomcat!" % classpath)

tomcat_stop()

tomcat_cache_mv()

tomcat_start()

shell指令碼啟動與關閉zookeeper集群

提示 適用於使用shell指令碼控制zookeeper集群的啟動與關閉 1.zookeeper安裝目錄 hadoop zookeeper 3.4.10 2.配置好環境變數 3.三颱主機 或者是虛擬機器 修改了主機名 關閉了防火牆 並配置免密碼登陸,主機ip與主機名的對映關係 stormfct1 19...

windows oracle 啟動關閉指令碼

需要用windows管理員許可權執行,win10下測試通過 oracle安裝時會預設安裝7個service,介紹如下 1.oracle orcl vss writer service 非必須啟動 oracle卷對映拷貝寫入服務,vss volume shadow copy service 能夠讓儲存...

tomcat無法啟動和關閉

在部署專案時,經常碰到tomcat無法啟動和關閉的現象。碰到這些情況時,一般是埠被占用。那麼就需要了解啟動和關閉的埠設定了。tomcat 修改關閉埠 乙個server.xml中只能有乙個server節點,因為它代表著tomcat自身。如果你需要兩個server,就必須執行兩個tomcat例項。shu...