Authored by root

支持多个java服务重启

# yoho services
- hosts: java-gateway
serial: "50%"
vars:
service: 'yoho-gateway'
deploy_path: 'yoho-gateway'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- debug:
msg: "{{ restart_services }}"
- import_role:
name: java.restart
when: service in restart_services
- hosts: java-message
serial: "50%"
vars:
service: 'yoho-message'
deploy_path: 'yoho-message'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
- hosts: java-sns
serial: "50%"
vars:
service: 'yoho-sns'
deploy_path: 'yoho-sns'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- debug:
msg: "{{ restart_services }}"
- import_role:
name: java.restart
when: service in restart_services
- hosts: java-users
serial: "50%"
vars:
service: 'yoho-users'
deploy_path: 'yoho-users'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
- hosts: java-social
serial: "50%"
vars:
service: 'yoho-social'
deploy_path: 'yoho-social'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
# yohobuy services
- hosts: java-activity
serial: "50%"
vars:
service: 'yohobuy-activity'
deploy_path: 'yohobuy-activity'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
- hosts: java-bigdata
serial: "50%"
vars:
service: 'yohobuy-bigdata'
deploy_path: 'yohobuy-bigdata'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
- hosts: java-brower
serial: "50%"
vars:
service: 'yohobuy-brower'
deploy_path: 'yohobuy-brower'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
- hosts: java-order
serial: "50%"
vars:
service: 'yohobuy-order'
deploy_path: 'yohobuy-order'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
- hosts: java-product
serial: "50%"
vars:
service: 'yohobuy-product'
deploy_path: 'yohobuy-product'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
- hosts: java-promotion
serial: "50%"
vars:
service: 'yohobuy-promotion'
deploy_path: 'yohobuy-promotion'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
- hosts: java-resources
serial: "50%"
vars:
service: 'yohobuy-resources'
deploy_path: 'yohobuy-resources'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
- hosts: java-risk
serial: "50%"
vars:
service: 'yohobuy-risk'
deploy_path: 'yohobuy-risk'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
- hosts: java-union
serial: "50%"
vars:
service: 'yohobuy-union'
deploy_path: 'yohobuy-union'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
- hosts: java-wechat
serial: "50%"
vars:
service: 'yohobuy-wechat'
deploy_path: 'yohobuy-wechat'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
# uniq services
- hosts: java-uic
serial: "50%"
vars:
service: 'uic'
deploy_path: 'uic'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
- hosts: java-platform-cms
serial: "50%"
vars:
service: 'platform-cms'
deploy_path: 'platform-cms'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
# special services
- hosts: java-erpgateway
serial: "50%"
vars:
service: 'erpgateway'
deploy_path: 'yoho-erp-gateway'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
# ufo services
- hosts: ufo-fore
serial: "50%"
vars:
service: 'yohoufo-fore'
deploy_path: 'yohoufo-fore'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
- hosts: ufo-platform
serial: "50%"
vars:
service: 'ufo-platform'
deploy_path: 'ufo-platform'
remote_user: root
become: true
become_method: sudo
become_user: master
tasks:
- import_role:
name: java.restart
when: service in restart_services
... ...
... ... @@ -2,9 +2,9 @@
serial: "50%"
remote_user: root
vars:
yoho_services: ['gateway','message','sns','users','social']
yoho_services: ['gateway','message','sns','users','social','ufo-fore']
yohobuy_services: ['activity','bigdata','brower','order','product','promotion','resources','risk','union','wechat']
uniq_services: ['uic','platform-cms']
uniq_services: ['uic','platform-cms','ufo-platform']
become: true
become_method: sudo
become_user: master
... ...
java.restart
=========
> 通过master用户执行killws.sh,startws.sh重启java服务通过master用户执行killws.sh,startws.sh重启java服务并检查最新启动时间
Requirements
------------
None
Role Variables
--------------
> 参考 `playbooks/java.restart.yml`
Author Information
------------------
tiexin.yang@yoho.cn
... ...
---
# defaults file for java.restart
... ...
---
# handlers file for java.restart
... ...
galaxy_info:
author: your name
description: your description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: license (GPLv2, CC-BY, etc)
min_ansible_version: 1.2
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
# Optionally specify the branch Galaxy will use when accessing the GitHub
# repo for this role. During role install, if no tags are available,
# Galaxy will use this branch. During import Galaxy will access files on
# this branch. If Travis integration is configured, only notifications for this
# branch will be accepted. Otherwise, in all cases, the repo's default branch
# (usually master) will be used.
#github_branch:
#
# platforms is a list of platforms, and each platform has a name and a list of versions.
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
\ No newline at end of file
... ...
---
# 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: 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 }}"
... ...
---
# vars file for java.restart
... ...