Authored by root

java重启时间检查

@@ -7,23 +7,26 @@ @@ -7,23 +7,26 @@
7 7
8 # 获取服务启动时间(ts) 8 # 获取服务启动时间(ts)
9 - name: check service runtime 9 - name: check service runtime
10 - raw: date -d "`ps -eo lstart,etime,cmd | grep gateway|grep -Ev 'grep|ansible|python'|awk '{print substr($0,1,24)}'`" +%s 10 + raw: date -d "`ps -eo lstart,etime,cmd | grep {{ deploy_path }}|grep -Ev 'grep|ansible|python'|awk '{print substr($0,1,24)}'`" +%s
11 register: service_runtime 11 register: service_runtime
  12 + changed_when: False
12 13
13 # 获取服务器当前系统时间(ts) 14 # 获取服务器当前系统时间(ts)
14 - name: system current time 15 - name: system current time
15 shell: date +%s 16 shell: date +%s
16 register: current_time 17 register: current_time
  18 + changed_when: False
17 19
18 -- name: Service uptime 20 +# 对比服务启动时间与当前时间
  21 +- name: Compare service uptime & current time
19 debug: 22 debug:
20 msg: 23 msg:
21 - "Serivce {{ deploy_path }} last uptime is: {{ lookup('pipe','date -d @'+service_runtime.stdout) }}" 24 - "Serivce {{ deploy_path }} last uptime is: {{ lookup('pipe','date -d @'+service_runtime.stdout) }}"
22 - "Current system time is: {{ lookup('pipe','date -d @'+current_time.stdout) }}" 25 - "Current system time is: {{ lookup('pipe','date -d @'+current_time.stdout) }}"
23 - "interval is: {{ current_time.stdout|int - service_runtime.stdout|int }}" 26 - "interval is: {{ current_time.stdout|int - service_runtime.stdout|int }}"
24 27
25 -# 服务启动时间与系统时间间隔超过60秒则标记为重启失败 28 +# 服务启动时间与系统时间间隔超过120秒则标记为重启失败
26 - name: check restart status 29 - name: check restart status
27 fail: 30 fail:
28 - msg: "System current time and service startup time error exceeds 60 seconds, interval is {{ current_time.stdout|int - service_runtime.stdout|int }} !"  
29 - when: current_time.stdout|int - service_runtime.stdout|int > 60 31 + msg: "System current time and service startup time error exceeds 120 seconds, interval is {{ current_time.stdout|int - service_runtime.stdout|int }} !"
  32 + when: current_time.stdout|int - service_runtime.stdout|int > 120