main.yml
1.26 KB
---
# tasks file for java.restart
- name: restart {{ deploy_path }}
shell: sh /home/master/{{ deploy_path }}/deploy/bin/killws.sh && sh /home/master/{{ deploy_path }}/deploy/bin/startws.sh
async: 90
# 获取服务启动时间(ts)
- name: check service runtime
raw: date -d "`ps -eo lstart,etime,cmd | grep {{ deploy_path }}|grep -Ev 'grep|ansible|python'|awk '{print substr($0,1,24)}'`" +%s
register: service_runtime
changed_when: False
# 获取服务器当前系统时间(ts)
- name: system current time
shell: date +%s
register: current_time
changed_when: False
# 对比服务启动时间与当前时间
- name: Compare service uptime & current time
debug:
msg:
- "Service {{ deploy_path }} last uptime is: {{ lookup('pipe','date -d @'+service_runtime.stdout) }}"
- "Current system time is: {{ lookup('pipe','date -d @'+current_time.stdout) }}"
- "interval is: {{ current_time.stdout|int - service_runtime.stdout|int }}"
# 服务启动时间与系统时间间隔超过120秒则标记为重启失败
- name: check restart status
fail:
msg: "服务启动时间与系统时间间隔超过 120 秒, interval: {{ current_time.stdout|int - service_runtime.stdout|int }} !"
when: current_time.stdout|int - service_runtime.stdout|int > 120