Skip to content
This repository was archived by the owner on Nov 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'devel' into 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ysicing committed Jan 18, 2019
2 parents c32733c + 4bd0f4e commit b8a8dd0
Show file tree
Hide file tree
Showing 22 changed files with 281 additions and 104 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#### Stable version installation

current version: 5.0
current version: 5.0.2

```bash
wget https://pkg.rainbond.com/releases/common/v5.0/grctl
Expand Down
4 changes: 3 additions & 1 deletion ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ callback_plugins = callback_plugins:/usr/share/ansible/plugins/callback:

fact_caching = jsonfile
fact_caching_connection = /tmp
retry_files_enabled = False
retry_files_enabled = False

library = ./library
8 changes: 7 additions & 1 deletion hack/files/bin/grtools/grclis
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ case $1 in
del_role $2 $3
;;
reset)
reset
read -n1 -p "Are you sure you want to continue resetting node [Y/N]?" answer
case $answer in
Y | y)
reset;;
*)
echo "";;
esac
;;
*)
help
Expand Down
23 changes: 23 additions & 0 deletions library/rbdinfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

from ansible.module_utils.basic import *

EXAMPLES = '''
- rbdinfo:
info: 'next step download image.tgz'
'''

def main():
module = AnsibleModule(
argument_spec = dict(
info=dict(type='str', default='The next task may take some time to execute'),
),
supports_check_mode=True
)

infodata = dict(stdout=module.params['info'],changed=False,rc=0,msg=module.params['info'])
module.exit_json(**infodata)

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion roles/etcd-proxy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
when: etcd_is_on_worker.stat.isreg is not defined

- name: Etcd-proxy | start etcd-proxy
shell: "systemctl daemon-reload && systemctl start etcd-proxy"
shell: "systemctl daemon-reload && systemctl enable etcd-proxy && systemctl start etcd-proxy"
when: etcd_is_on_worker.stat.isreg is not defined

2 changes: 1 addition & 1 deletion roles/etcd/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
retries: 3

- name: Etcd | start etcd
shell: "systemctl daemon-reload && systemctl start etcd"
shell: "systemctl daemon-reload && systemctl enable etcd && systemctl start etcd"

18 changes: 15 additions & 3 deletions roles/image/tasks/import_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
stat: path=/grdata/services/offline/images/etcd.tgz
register: check_base_image_tgz_unarchive

- name: Rainbond | Unzip base image
- name: The next task may take some time to execute
debug:
msg: "The next task may take some time to execute: Waiting Unzip base image "

- name: Rainbond | Unzip base image Ok
unarchive:
src: /grdata/services/offline/base.images.tgz
dest: /grdata/services/offline/images
Expand All @@ -13,13 +17,21 @@
stat: path=/grdata/services/offline/images/mq.tgz
register: check_rainbond_image_tgz_unarchive

- name: Rainbond | Unzip rainbond image
- name: The next task may take some time to execute
debug:
msg: "The next task may take some time to execute: Waiting Unzip rainbond image"

- name: Rainbond | Unzip rainbond image Ok
unarchive:
src: /grdata/services/offline/rainbond.images.tgz
dest: /grdata/services/offline/images
when: check_rainbond_image_tgz_unarchive.stat.isreg is not defined

- name: Rainbond | load image from local
- name: The next task may take some time to execute
debug:
msg: "The next task may take some time to execute:Waiting load image Ok"

- name: Rainbond | load image from local ok
shell: "bash {{ base_dir }}/offline/images/load.sh > /tmp/local.image.log"
register: load_task_result
until: load_task_result is succeeded
Expand Down
20 changes: 9 additions & 11 deletions roles/image/tasks/online_download_tgz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,28 @@
stat: path=/grdata/services/offline/base.images.tgz
register: check_image_base_tgz_download

- name: Notice | Downloading base.images.tgz (1.5GB)
shell: echo "download"
- name: The next task may take some time to execute
debug:
msg: "The next task may take some time to execute: Waiting downloading base.images.tgz (1.5GB)"
when: check_image_base_tgz_download.stat.isreg is not defined

- name: Rainbond | Download base image tgz ok
get_url:
url: http://rainbond-pkg.oss-cn-shanghai.aliyuncs.com/offline/5.0/base.images.2018-12-29-5.0.tgz
url: http://rainbond-pkg.oss-cn-shanghai.aliyuncs.com/offline/5.0/base.images.2019-01-18-5.0.2.tgz
dest: /grdata/services/offline/base.images.tgz
when: check_image_base_tgz_download.stat.isreg is not defined

- name: Check | Check if rainbond.image.tgz is download
stat: path=/grdata/services/offline/rainbond.images.tgz
register: check_image_rainbond_tgz_download

- name: Notice | Downloading rainbond.images.tgz (300MB)
shell: echo "download"
- name: The next task may take some time to execute
debug:
msg: "The next task may take some time to execute: Waiting downloading rainbond.images.tgz (300MB)"
when: check_image_rainbond_tgz_download.stat.isreg is not defined

- name: Rainbond | Download rainbond image tgz ok
get_url:
url: http://rainbond-pkg.oss-cn-shanghai.aliyuncs.com/offline/5.0/rainbond.images.2019-01-11-5.0.1.tgz
url: http://rainbond-pkg.oss-cn-shanghai.aliyuncs.com/offline/5.0/rainbond.images.2019-01-18-5.0.2.tgz
dest: /grdata/services/offline/rainbond.images.tgz
when: check_image_rainbond_tgz_download.stat.isreg is not defined

#- name: Rainbond | write download image.tgz done
# file: path=/opt/rainbond/.init/tgz.download state=touch
# when: check_image_tgz_download.stat.isreg is not defined
when: check_image_rainbond_tgz_download.stat.isreg is not defined
31 changes: 31 additions & 0 deletions roles/master/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
- name: Rainbond | Copy ssh PrimaryKey
copy:
src: /grdata/services/ssh/id_rsa
dest: /root/.ssh/id_rsa
mode: 600
backup: yes

- name: Rainbond | Copy ssh PublicKey
copy:
src: /grdata/services/ssh/id_rsa.pub
dest: /root/.ssh/id_rsa.pub
mode: 644
backup: yes

- name: Rainbond | Install ansible Online
shell: "pip install ansible"
when: install_type == "online"

- name: Rainbond | Install ansible Offline
shell: "yum install -y sshpass python-pip ansible"
when: install_type != "online"

- name: Rainbond | Add share
template:
src: share.sh.j2
dest: /tmp/share.sh
mode: 0777

- name: Rainbond | Run share
shell: bash /tmp/share.sh
7 changes: 7 additions & 0 deletions roles/master/templates/share.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

echo "{{ MASTER_IP }}:/opt/rainbond/etc/tools /opt/rainbond/etc/tools nfs rw 0 0" >> /etc/fstab
echo "{{ MASTER_IP }}:/opt/rainbond/.init /opt/rainbond/.init nfs rw 0 0" >> /etc/fstab
echo "{{ MASTER_IP }}:/opt/rainbond/rainbond-ansible /opt/rainbond/rainbond-ansible nfs rw 0 0">> /etc/fstab

mount -a
1 change: 1 addition & 0 deletions roles/node/templates/master.role.j2
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ services:
-e K8S_MASTER=http://127.0.0.1:8181
-v {{ rbd_dir }}/logs/rbd-eventlog:/var/log
-v /grdata/downloads/log:/grdata/logs
-v /opt/rainbond/etc/node:/opt/rainbond/etc/node
-i goodrain.me/{{ eventlog }}
--cluster.bind.ip={{ nodeip }} --cluster.instance.ip={{ nodeip }} --db.type=mysql --db.url="{{ db_user }}:{{ db_pass }}@tcp({{ MASTER_IP }}:3306)/region" --discover.etcd.addr=${ETCD_ENDPOINTS} --eventlog.bind.ip={{ nodeip }} --websocket.bind.ip={{ nodeip }}
stop: docker stop rbd-eventlog
Expand Down
23 changes: 14 additions & 9 deletions roles/nodeinit/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Rainbond | Copy DB Script
template:
src: updatedb.sh.j2
src: donedb.sh.j2
dest: /tmp/updatedb.sh
mode: 0777

Expand All @@ -22,17 +22,21 @@
src: init.sql.j2
dest: /tmp/init.sql

- name: Notice | Next Step will update db
shell: echo "download"
- name: The next task may take some time to execute
debug:
msg: "The next task may take some time to execute: Waiting init db"

- name: Rainbond | Run update DB
shell: "bash /tmp/updatedb.sh >> /tmp/init.log"
- name: Rainbond | Run init db
shell: "bash /tmp/updatedb.sh init >> /tmp/init.log"
register: updatedb_task_result
until: updatedb_task_result is succeeded
retries: 5

#- name: show updatedb_task_result debug info
# debug: var=updatedb_task_result
- name: Rainbond | Check init db
shell: "bash /tmp/updatedb.sh check > /tmp/check.log"
register: checkdb_task_result
until: checkdb_task_result is succeeded
retries: 3

- name: Rainbond | Check goodrain.me
shell: "bash /tmp/check_registries.sh"
Expand All @@ -41,8 +45,9 @@
stat: path=/opt/rainbond/.init/goodrain.me.ok
register: check_goodrainme_done

- name: Notice | Pushing local images to goodrain.me
shell: echo "push"
- name: The next task may take some time to execute
debug:
msg: "The next task may take some time to execute: Waiting Pushing local images to goodrain.me"
when: check_goodrainme_done.stat.isreg is defined

- name: Rainbond | Push local images to goodrain.me
Expand Down
4 changes: 4 additions & 0 deletions roles/nodeinit/templates/check_registries.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
docker info | grep "goodrain.me"
if [ "$?" -eq 0 ];then
echo "ok" > /opt/rainbond/.init/goodrain.me.ok
fi

if [ -f "/etc/docker/certs.d/goodrain.me/server.crt" ];then
echo "ok" > /opt/rainbond/.init/goodrain.me.ok
fi
75 changes: 75 additions & 0 deletions roles/nodeinit/templates/donedb.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

set -x

prepare(){
# IP={{ lbip }}
IP=$(cat /opt/rainbond/.init/domain.yaml | grep iip | awk -F ': ' '{print $2}')
ssl_ca_cert=$(cat {{ region_ca_dir }}/ca.pem)
key_file=$(cat {{ region_ca_dir }}/client.key.pem)
cert_file=$(cat {{ region_ca_dir }}/client.pem)
DOMAIN={{ app_domain }}
cat > /tmp/region_info.sql <<EOF
INSERT INTO \`region_info\` ( \`region_id\`, \`region_name\`, \`region_alias\`, \`url\`, \`token\`, \`status\`, \`desc\`, \`wsurl\`, \`httpdomain\`, \`tcpdomain\`, \`scope\`, \`ssl_ca_cert\`,\`cert_file\`,\`key_file\`) VALUES('asdasdasdasdasdasdasdasdas', 'rainbond', '默认私有数据中心', 'https://region.goodrain.me:8443', NULL, '1', '当前数据中心是默认安装添加的数据中心', 'ws://$IP:6060', '$DOMAIN', '$IP', 'private','$ssl_ca_cert','$cert_file','$key_file');
EOF

}

create_db(){
docker exec rbd-db mysql -e "grant all on *.* to '{{ db_user }}'@'%' identified by '{{ db_pass }}' with grant option; flush privileges";docker exec rbd-db mysql -e "delete from mysql.user where user=''; flush privileges"
docker exec rbd-db mysql -e "CREATE DATABASE IF NOT EXISTS region DEFAULT CHARSET utf8 COLLATE utf8_general_ci;"
docker exec rbd-db mysql -e "CREATE DATABASE IF NOT EXISTS console DEFAULT CHARSET utf8 COLLATE utf8_general_ci;"
}

init(){
for ((i=1;i<=6;i++))
do
docker exec rbd-db mysql -e "show databases;"
status=$?
[ "$status" -eq 0 ] && (
create_db
for ((i=1;i<=60;i++ ));do
sleep 5
uiready=$(docker ps | grep app-ui)
[ ! -z "$uiready" ] && break
done
[ ! -f "/opt/rainbond/.init/.ui.init" ] && (
prepare
docker exec rbd-app-ui python /app/ui/manage.py migrate
[ "$?" -eq 0 ] && touch /opt/rainbond/.init/.ui.init
)
[ -f "/opt/rainbond/.init/.ui.init" ] && (
docker cp /tmp/init.sql rbd-db:/root
docker exec rbd-db mysql -e "use console;truncate table console_sys_config"
docker exec rbd-db mysql -e "use console;source /root/init.sql;"
check=$(docker exec rbd-db mysql -e "select wsurl from console.region_info where region_id='asdasdasdasdasdasdasdasdas';")
if [ -z "$check" ];then
docker cp /tmp/region_info.sql rbd-db:/root
docker exec rbd-db mysql -e "use console;source /root/region_info.sql;"
fi
)
) && break
[ "$status" -ne 0 ] && (
systemctl stop rbd-db && rm -rf /opt/rainbond/data/rbd-db
sleep 20
)
done

}

check(){
check=$(docker exec rbd-db mysql -e "select wsurl from console.region_info where region_id='asdasdasdasdasdasdasdasdas';")
if [ -z "$check" ];then
init
exit 1
fi
}

case $1 in
check)
check
;;
*)
init
;;
esac
43 changes: 0 additions & 43 deletions roles/nodeinit/templates/updatedb.sh.j2

This file was deleted.

Loading

0 comments on commit b8a8dd0

Please sign in to comment.