Last active
April 9, 2024 07:41
-
-
Save marsyang1/36c6bcb5c14618cee5589ebd87edfeee to your computer and use it in GitHub Desktop.
ansible-restart tomcat playbook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # host usually use all , sometime and apply to some server role | |
| # but also can use ansible-playbook with --limit , more dynamicly | |
| # reference | |
| # https://gist.github.com/gomes/7697353 | |
| # http://stackoverflow.com/questions/3510673/find-and-kill-a-process-in-one-line-using-bash-and-regex | |
| # kill $(ps aux | grep '[/]home/testworkspace/qleoffice' | awk '{print $2}') | |
| - hosts: all | |
| # sudo permission | |
| become: true | |
| vars: | |
| tomcat_folder: qleoffice | |
| tomcat_path: "/home/testworkspace/{{ tomcat_folder }}" | |
| grep_string: "[/]home/testworkspace/{{ tomcat_folder }}" | |
| tasks: | |
| - name: ==> shutdown qle tomcat ,path = "{{ tomcat_path }}/bin/" | |
| command: sh {{ tomcat_path }}/bin/shutdown.sh | |
| - name: ==> sleep 3s | |
| command: sleep 3s | |
| - name: Check if Apache is running | |
| shell: ps aux | grep '{{ grep_string }}' | awk '{print $2}' | |
| ignore_errors: yes | |
| changed_when: false | |
| register: service_apache_status | |
| - debug: msg="Check if Apache is running {{ service_apache_status }}" | |
| - debug: msg="service_apache_status.stdout != '' = {{ service_apache_status.stdout != ''}}" | |
| - name: kill process is tomcat is still running | |
| shell: kill $(ps aux | grep '{{ grep_string }}' | awk '{print $2}') | |
| when: service_apache_status.stdout != '' | |
| - command: sleep 1s | |
| when: service_apache_status.stdout != '' | |
| - name: ==> startup qle tomcat , path = {{ tomcat_path }}/bin/startup.sh | |
| shell: setsid /bin/sh -i -c "{{ tomcat_path }}/bin/startup.sh" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| projectPathName="$1" | |
| projectPath="/home/www/$projectPathName" | |
| echo $projectPath | |
| echo $(ps aux | grep $projectPath/ | awk '{print $2}') | |
| kill $(ps aux | grep $projectPath/ | awk '{print $2}') | |
| echo "pause 3 second" | |
| sleep 3s | |
| cd $projectPath | |
| sh bin/shutdown.sh && sleep 8s && sh bin/startup.sh && tail -f logs/catalina.out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| projectPathName="xxxx" | |
| sh restart_template.sh $projectPathName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment