forked from rayduan/jenkinslib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c2a332
commit a56bb59
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
# This playbook deploys a simple to deploy. | ||
|
||
- hosts: {{deployServer}} | ||
# remote_user: root | ||
become: yes | ||
become_method: sudo | ||
|
||
roles: | ||
- scm | ||
- ops |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
workspace=/var/app/ | ||
localserver=localhost | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
- hosts: "{{ deployServer }}" | ||
remote_user: root | ||
tasks: | ||
# 获取进程号 | ||
- name: get pid of api | ||
tags: | ||
- getPid | ||
shell: "ps -ef | grep -v grep | grep {{ artifactId }} | awk '{print $2}'" | ||
register: running_processes | ||
|
||
# 发送停止运行信号 | ||
- name: Kill running processes | ||
tags: | ||
- stopApp | ||
shell: "kill {{ item }}" | ||
tags: | ||
- killService | ||
with_items: "{{ running_processes.stdout_lines }}" | ||
|
||
# 等待60s钟,确认获取的到的pid是否都停止运行 | ||
- wait_for: | ||
path: "/proc/{{ item }}/status" | ||
state: absent | ||
timeout: 60 | ||
tags: | ||
- waitKillService | ||
with_items: "{{ running_processes.stdout_lines }}" | ||
ignore_errors: yes | ||
register: killed_processes | ||
# 强制杀死,未停止运行的进程 | ||
- name: Force kill stuck processes | ||
tags: | ||
- forceStopApp | ||
shell: "kill -9 {{ item }}" | ||
with_items: "{{ killed_processes.results | select('failed') | map(attribute='item') | list }}" | ||
|
||
# 启动新的jar包 | ||
- name: start wechat-api | ||
tags: | ||
- startApp | ||
shell: "nohup java -jar {{ workspace }}{{ artifactId }}-{{ appVersion }}.jar --name={{ artifactId }} &" | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
--- | ||
- hosts: "{{ deployServer }}" | ||
remote_user: root | ||
tasks: | ||
- file: "path={{ workspace }}{{ artifactId }} state=directory" | ||
delegate_to: localhost | ||
#从nexus中获取jar包 | ||
- name: get jar from nexus | ||
tags: | ||
- getJar | ||
maven_artifact: | ||
group_id: "{{ groupId }}" | ||
artifact_id: "{{ artifactId }}" | ||
repository_url: '{{ repository }}' | ||
dest: "{{ workspace }}{{ artifactId }}/" | ||
username: "{{ username }}" | ||
password: "{{ password }}" | ||
version: "{{ appVersion }}" | ||
delegate_to: localhost | ||
- name: copy to dest | ||
tags: | ||
- pushJar | ||
copy: | ||
src: "{{ workspace }}{{ artifactId }}/" | ||
dest: "{{ workspace }}" | ||
- name: delete local package | ||
tags: | ||
- deteleOldPackage | ||
file: "path={{ workspace }}{{ artifactId }} state=absent force=yes" | ||
delegate_to: {{ localserver }} | ||
|