java.restart-service.yml 1.25 KB
- hosts: java-{{ service }}
  serial: "50%"
  remote_user: root
  vars:
    yoho_services: ['gateway','message','sns','users']
    yohobuy_services: ['activity','bigdata','brower','order','product','promotion','resources','risk','union','wechat']
    uniq_services: ['uic']
  become: true
  become_method: sudo
  become_user: master

  tasks:
  - name: match yoho deploy path
    set_fact:
      deploy_path: yoho-{{ service }}
    when: service in yoho_services

  - name: match yohobuy deploy path
    set_fact:
      deploy_path: yohobuy-{{ service }}
    when: service in yohobuy_services

  - name: match uniq deploy path
    set_fact:
      deploy_path: "{{ service }}"
    when: service in uniq_services

  - name: match erpgateway deploy path
    set_fact:
      deploy_path: "yoho-erp-gateway"
    when: service == "erpgateway"

  - name: restart {{ deploy_path }}
    shell: sh /home/master/{{ deploy_path }}/deploy/bin/killws.sh && sh /home/master/{{ deploy_path }}/deploy/bin/startws.sh
    async: 60

  - name: check service runtime
    shell: ps -ef|grep java|grep {{ deploy_path }}|grep -v grep|awk '{print $5}'
    register: service_runtime

  - name: print service uptime
    debug: msg="Serivce {{ deploy_path }} last uptime is {{ service_runtime.stdout }}"