说明:
tomcat_home:tomcat安装目录
bak_home:备份Tomcat目录
war_name:war包名字,后面不要加.war
- hosts: pay vars: tomcat_home: /usr/local/apache-tomcat bak_home: /var/storages/bak war_name: pay remote_user: root tasks: - name: backup {{ war_name }}.war to {{ bak_home }} shell: cp -pr {{ tomcat_home }}/webapps/{{ war_name }}.war /var/storages/bak/{{ war_name }}-`date +%F-%H-%M`.war - name: stop tomcat shell: ps -ef | grep {{ tomcat_home }} | grep -v grep | awk '{print $2}'| xargs kill -9 ignore_errors: yes - name: stop tomcat2 shell: ps -ef | grep {{ tomcat_home }} | grep -v grep | awk '{print $2}'| xargs kill -9 ignore_errors: yes - name: stop tomcat3 shell: ps -ef | grep {{ tomcat_home }} | grep -v grep | awk '{print $2}'| xargs kill -9 ignore_errors: yes - name: check tomcat shell: ps -ef | grep {{ tomcat_home }} - name: delete {{ tomcat_home }} {{ war_name }} shell: rm -rf {{ tomcat_home }}/webapps/{{ war_name }}* ignore_errors: yes - name: delete tomcat work dir shell: rm -f {{ tomcat_home }}/work/* - name: delete catalina.out shell: rm -f {{ tomcat_home }}/logs/catalina.out ignore_errors: yes - name: update {{ war_name }}.war to {{ tomcat_home }} copy: src=/tmp/{{ war_name }}.war dest={{ tomcat_home }}/webapps/{{ war_name }}.war - name: start tomcat shell: "source /etc/profile;nohup {{ tomcat_home }}/bin/startup.sh &" - name: check tomcat shell: ps -ef | grep {{ tomcat_home }}
评论区