Authored by root

java重启时间检查

... ... @@ -7,23 +7,26 @@
# 获取服务启动时间(ts)
- name: check service runtime
raw: date -d "`ps -eo lstart,etime,cmd | grep gateway|grep -Ev 'grep|ansible|python'|awk '{print substr($0,1,24)}'`" +%s
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: Service uptime
# 对比服务启动时间与当前时间
- name: Compare service uptime & current time
debug:
msg:
- "Serivce {{ 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 }}"
# 服务启动时间与系统时间间隔超过60秒则标记为重启失败
# 服务启动时间与系统时间间隔超过120秒则标记为重启失败
- name: check restart status
fail:
msg: "System current time and service startup time error exceeds 60 seconds, interval is {{ current_time.stdout|int - service_runtime.stdout|int }} !"
when: current_time.stdout|int - service_runtime.stdout|int > 60
msg: "System current time and service startup time error exceeds 120 seconds, interval is {{ current_time.stdout|int - service_runtime.stdout|int }} !"
when: current_time.stdout|int - service_runtime.stdout|int > 120
... ...