zoukankan      html  css  js  c++  java
  • tomcat启动与关闭脚本

    需求:
    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 '{print $2}'"% 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()

  • 相关阅读:
    为什么人们普遍选择城市而非农村
    风物长宜放眼量-创业潮比雾霾消散的要快
    一眼看请考研的目的-本质上的第二次高考
    京都城门考
    翻译的很好的一篇android mediaplayer
    Android MediaProvider数据库模式
    android 多媒体数据库详解
    android usb挂载分析---vold处理内核消息
    android usb挂载分析
    android usb挂载分析---MountService启动
  • 原文地址:https://www.cnblogs.com/TaleG/p/6735048.html
Copyright © 2011-2022 走看看