如今使用Linux做爲項目運行環境的已經愈來愈多,Linux下tomcat啓動默認是看不到輸出信息的,如平常開發中能夠在eclipse中看到的輸出信息都被輸出到logs/catalina.out.須要查看的話能夠使用python
tail -f logs/catalina.out
筆者常常須要發佈項目新版本,須要不斷操做tomcat啓動和關閉。因而寫了如下tomcat.py的Python腳本:apache
# encoding:utf-8 import os, sys start_operation = ['startup', '-startup', '--startup', 'start', '-start', '--start'] stop_operation = ['shutdown', '-shutdown', '--shutdown', 'stop', '-stop', '--stop'] show_operation = ['show', 'log'] def show_help(): print 'usage: python tomcat.py start|stop|show' print '\n\n' print 'startup operation : ' print start_operation print '----------------------------' print 'stop operation : ' print stop_operation print '----------------------------' print 'show operation :' print show_operation print '----------------------------' if __name__=="__main__": operation = '' try: operation = sys.argv[1] except: show_help() sys.exit(0) if operation in start_operation: # start tomcat os.system('/opt/apache-tomcat-8.0.32/bin/shutdown.sh') os.system('/opt/apache-tomcat-8.0.32/bin/startup.sh') os.system('tail -f /opt/apache-tomcat-8.0.32/logs/catalina.out') elif operation in stop_operation: # stop tomcat os.system('/opt/apache-tomcat-8.0.32/bin/shutdown.sh') os.system('tail -f /opt/apache-tomcat-8.0.32/logs/catalina.out') elif operation in show_operation: os.system('tail -f /opt/apache-tomcat-8.0.32/logs/catalina.out') else: show_help() sys.exit(0)
註釋一下:tomcat