Skip to content

Commit

Permalink
“playbook”
Browse files Browse the repository at this point in the history
  • Loading branch information
15267092875 committed May 9, 2020
1 parent 0c2a332 commit a56bb59
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
11 changes: 11 additions & 0 deletions devops/deploy.yml
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
4 changes: 4 additions & 0 deletions devops/group_vars/deployserver
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

workspace=/var/app/
localserver=localhost

43 changes: 43 additions & 0 deletions devops/roles/ops/main.yml
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 }} &"

32 changes: 32 additions & 0 deletions devops/roles/scm/main.yml
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 }}

0 comments on commit a56bb59

Please sign in to comment.