├── .gitmodules ├── release_note.txt ├── requirements.txt ├── deploy ├── nodeconf ├── comm │ ├── __init__.py │ ├── global_var.py │ ├── log.py │ ├── nginx.conf │ ├── utils.py │ ├── mysql.py │ ├── check.py │ └── docker.py ├── docker │ ├── script │ │ ├── web-start.sh │ │ ├── front-start.sh │ │ ├── sign-start.sh │ │ ├── mgr-start.sh │ │ └── wait-for-it.sh │ ├── docker-compose-template.yaml │ └── docker-compose.yaml ├── install.md ├── README-en.md ├── visual-deploy.properties ├── telnet.py ├── common.properties ├── webase-upgrade.sh ├── deploy.py └── upgrade │ ├── upgrade-v1.5.0.sh │ ├── upgrade-v1.5.1.sh │ ├── upgrade-v1.5.2.sh │ ├── upgrade-v1.5.3.sh │ └── upgrade-v1.5.4.sh ├── images ├── contract.png ├── keyUser.png ├── monitor.png ├── frontInfo.png ├── transHash.png └── architecture.png ├── .gitattributes ├── quick-start ├── .gitignore ├── src │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── webank │ │ │ └── webase │ │ │ └── helloworld │ │ │ └── WebaseHelloworldApplicationTests.java │ └── main │ │ ├── resources │ │ ├── application.yml │ │ └── log4j2.xml │ │ └── java │ │ └── com │ │ └── webank │ │ └── webase │ │ ├── Application.java │ │ └── transaction │ │ ├── TransactionParam.java │ │ └── TransactionService.java └── build.gradle ├── .travis.yml ├── README.md ├── quick-start.md ├── README-en.md └── LICENSE /.gitmodules: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /release_note.txt: -------------------------------------------------------------------------------- 1 | v1.5.5 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | requests -------------------------------------------------------------------------------- /deploy/nodeconf: -------------------------------------------------------------------------------- 1 | 127.0.0.1:nodeCounts agencyA 1,2 2 | -------------------------------------------------------------------------------- /images/contract.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WeBankBlockchain/WeBASE/HEAD/images/contract.png -------------------------------------------------------------------------------- /images/keyUser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WeBankBlockchain/WeBASE/HEAD/images/keyUser.png -------------------------------------------------------------------------------- /images/monitor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WeBankBlockchain/WeBASE/HEAD/images/monitor.png -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sh linguist-language=JAVA 2 | *.py linguist-language=JAVA 3 | *.log 4 | *.zip 5 | -------------------------------------------------------------------------------- /images/frontInfo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WeBankBlockchain/WeBASE/HEAD/images/frontInfo.png -------------------------------------------------------------------------------- /images/transHash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WeBankBlockchain/WeBASE/HEAD/images/transHash.png -------------------------------------------------------------------------------- /images/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WeBankBlockchain/WeBASE/HEAD/images/architecture.png -------------------------------------------------------------------------------- /deploy/comm/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | if sys.version_info.major == 3: 5 | import pymysql 6 | pymysql.install_as_MySQLdb() -------------------------------------------------------------------------------- /deploy/docker/script/web-start.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # this script used in docker-compose 4 | echo "start webase-web now..." 5 | nginx -c /data/webase-web/nginx/nginx.conf -g 'daemon off;' -------------------------------------------------------------------------------- /deploy/docker/script/front-start.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # this script used in docker-compose 4 | echo "start webase-front now..." 5 | cp -r /dist/sdk/* /dist/conf/ 6 | echo "finish copy sdk files to front's conf dir" 7 | java ${JAVA_OPTS} -Djdk.tls.namedGroups="secp256k1", -Duser.timezone="Asia/Shanghai" -Djava.security.egd=file:/dev/./urandom, -Djava.library.path=/dist/conf -cp ${CLASSPATH} ${APP_MAIN} -------------------------------------------------------------------------------- /deploy/install.md: -------------------------------------------------------------------------------- 1 | # 快速搭建 2 | ## 简介 3 | 4 | 一键部署可以快速搭建WeBASE管理台环境。包括节点(FISCO-BCOS 2.0+)、节点前置子系统(WeBASE-Front)、签名服务子系统(WeBASE-Sign)、节点管理子系统(WeBASE-Node-Manager)、管理平台(WeBASE-Web)。其中,节点的搭建是可选的,可以通过配置来选择使用已有链或者搭建新链。详细介绍请查看[一键部署在线文档](https://webasedoc.readthedocs.io/zh_CN/latest/docs/WeBASE/install.html)。 5 | 6 | ## 贡献说明 7 | 请阅读我们的贡献文档,了解如何贡献代码,并提交你的贡献。 8 | 9 | 希望在您的参与下,WeBASE会越来越好! 10 | 11 | ## 社区 12 | 联系我们:webase@webank.com 13 | -------------------------------------------------------------------------------- /quick-start/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/** 6 | !**/src/test/** 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | out/ 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /quick-start/src/test/java/com/webank/webase/helloworld/WebaseHelloworldApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.webank.webase.helloworld; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class WebaseHelloworldApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /quick-start/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | transactionUrl: http://127.0.0.1:5002/WeBASE-Front/trans/handle 2 | groupId: 1 3 | userAddress: "0x0a2db6c29e5bda45e8e2cd74c2ea2cf7be59c0a2" 4 | useAes: true 5 | contract: 6 | name: HelloWorld 7 | address: "0xaaed0c18786747b4d4c90ba072dee16dda08ccc3" 8 | funcName: set 9 | funcParam: "[\"abc\"]" 10 | contractAbi: "[{\"constant\":false,\"inputs\":[{\"name\":\"n\",\"type\":\"string\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" 11 | -------------------------------------------------------------------------------- /deploy/README-en.md: -------------------------------------------------------------------------------- 1 | # Quick build 2 | ## Introduction 3 | 4 | One-click deployment quickly builds A WeBASE management desk environment. Includes node (FISCO-BCOS 2.0), node front subsystem (WeBASE-Front), private key and sign managerment subsystem (WeBASE-Sign), node management subsystem (WeBASE-Node-Manager), management platform (WeBASE-Web). Among them, the configuration of the node is optional, you can choose to use the existing chain or build a new chain. For more information, check out the online documentation for one-click deployment (https://webasedoc.readthedocs.io/zh_CN/latest/docs/WeBASE/install.html). 5 | 6 | ## A description of the contribution 7 | Read our contribution documentation to learn how to contribute code and submit your contribution. 8 | 9 | Hopefully with your participation, WeBASE will get better and better! 10 | 11 | ## The community 12 | Contact us: webase@webank.com 13 | -------------------------------------------------------------------------------- /deploy/comm/global_var.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # encoding: utf-8 3 | 4 | default='default' 5 | install_all='installAll' 6 | visual_deploy='installWeBASE' 7 | 8 | ## deploy type to file mapping 9 | _type_file_dict = { 10 | default: 'common.properties', 11 | install_all: 'common.properties', 12 | visual_deploy: 'visual-deploy.properties' 13 | } 14 | 15 | ## deploy type pass in as a parameter 16 | deploy_type = default 17 | 18 | ## set deploy type 19 | def set_install_all(): 20 | global deploy_type 21 | global install_all 22 | deploy_type = install_all 23 | 24 | def set_visual_deploy(): 25 | global deploy_type 26 | global visual_deploy 27 | deploy_type = visual_deploy 28 | 29 | 30 | ## get properties file 31 | def get_file(): 32 | try: 33 | global deploy_type 34 | return _type_file_dict[deploy_type] 35 | except KeyError: 36 | global default 37 | return _type_file_dict[default] 38 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | sudo: enabled 3 | services: 4 | - mysql 5 | matrix: 6 | include: 7 | - name: "Python 3.5 on Xenial Linux" 8 | python: 3.5 9 | dist: xenial 10 | before_install: 11 | - pip install PyMySQL 12 | - name: "Python 3.6 on Xenial Linux" 13 | python: 3.6 14 | dist: xenial 15 | before_install: 16 | - pip install PyMySQL 17 | - name: "Python 3.7 on Xenial Linux" 18 | python: 3.7 19 | dist: xenial 20 | before_install: 21 | - pip install PyMySQL 22 | addons: 23 | apt: 24 | packages: 25 | - git 26 | - openssl 27 | - curl 28 | - nginx 29 | - dos2unix 30 | - unzip 31 | - wget 32 | homebrew: 33 | packages: 34 | - git 35 | - openssl 36 | - curl 37 | - nginx 38 | - dos2unix 39 | - unzip 40 | - wget 41 | install: 42 | - pip install -r requirements.txt 43 | script: 44 | - java -version 45 | - cd deploy 46 | - sed -i "s%dbUsername%root%g" common.properties 47 | - sed -i "s%dbPassword%%g" common.properties 48 | - python3 deploy.py installAll travis && python telnet.py 49 | -------------------------------------------------------------------------------- /quick-start/src/main/java/com/webank/webase/Application.java: -------------------------------------------------------------------------------- 1 | package com.webank.webase; 2 | 3 | import com.webank.webase.transaction.TransactionService; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.ConfigurableApplicationContext; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.http.client.SimpleClientHttpRequestFactory; 9 | import org.springframework.web.client.RestTemplate; 10 | 11 | @SpringBootApplication 12 | public class Application { 13 | 14 | public static void main(String[] args) { 15 | ConfigurableApplicationContext applicationContext = SpringApplication.run(Application.class, args); 16 | TransactionService tranService = applicationContext.getBean(TransactionService.class); 17 | tranService.sendTransaction(); 18 | } 19 | 20 | @Bean 21 | public RestTemplate getRestTemplate() { 22 | SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); 23 | factory.setReadTimeout(10000);// ms 24 | factory.setConnectTimeout(10000);// ms 25 | return new RestTemplate(factory); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /quick-start/src/main/java/com/webank/webase/transaction/TransactionParam.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package com.webank.webase.transaction; 15 | 16 | import java.util.List; 17 | 18 | import lombok.Data; 19 | import lombok.NoArgsConstructor; 20 | 21 | /** 22 | * param of send transaction. 23 | */ 24 | @Data 25 | @NoArgsConstructor 26 | public class TransactionParam { 27 | 28 | private Integer groupId; 29 | private String user; 30 | private String contractName; 31 | private String funcName; 32 | private String contractAddress; 33 | private Boolean useAes; 34 | private List funcParam; 35 | private List contractAbi; 36 | 37 | } -------------------------------------------------------------------------------- /deploy/visual-deploy.properties: -------------------------------------------------------------------------------- 1 | [common] 2 | 3 | # Webase Subsystem Version (v1.1.0 or above) 4 | webase.web.version=v1.5.5 5 | webase.mgr.version=v1.5.5 6 | webase.sign.version=v1.5.5 7 | fisco.webase.docker.cdn.version=v1.5.5 8 | 9 | # Mysql database configuration of WeBASE-Node-Manager 10 | mysql.ip=localhost 11 | mysql.port=3306 12 | mysql.user=dbUsername 13 | mysql.password=dbPassword 14 | mysql.database=webasenodemanager 15 | 16 | # Mysql database configuration of WeBASE-Sign 17 | sign.mysql.ip=localhost 18 | sign.mysql.port=3306 19 | sign.mysql.user=dbUsername 20 | sign.mysql.password=dbPassword 21 | sign.mysql.database=webasesign 22 | 23 | # WeBASE-Web service port 24 | web.port=5000 25 | # enable WeBASE-Web overview pages for mobile phone 26 | # (0: disable, 1: enable) 27 | web.h5.enable=1 28 | 29 | # WeBASE-Node-Manager service port 30 | mgr.port=5001 31 | 32 | # WeBASE-Sign service ip 33 | # 在[可视化部署中],不能使用127.0.0.1或localhost 34 | sign.ip=127.0.0.1 35 | # WeBASE-Sign service port 36 | sign.port=5004 37 | 38 | 39 | # Encrypt type (0: standard, 1: guomi) 40 | encrypt.type=0 41 | 42 | # Load node+front image from cdn, required docker installed and active 43 | # if [yes], auto pull image of [cdn.version] from cdn and load in docker 44 | if.load.image=yes 45 | -------------------------------------------------------------------------------- /deploy/comm/log.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # encoding: utf-8 3 | 4 | import logging, os 5 | 6 | class Logger: 7 | def __init__(self, path, clever=logging.DEBUG, Flevel=logging.DEBUG): 8 | self.logger = logging.getLogger(path) 9 | self.logger.setLevel(logging.DEBUG) 10 | log_format = logging.Formatter('[%(asctime)s] [%(levelname)s] %(message)s', '%Y-%m-%d %H:%M:%S') 11 | fh = logging.FileHandler(path) 12 | fh.setFormatter(log_format) 13 | fh.setLevel(Flevel) 14 | self.logger.addHandler(fh) 15 | 16 | def debug(self, message): 17 | self.logger.debug(message) 18 | 19 | def info(self, message): 20 | self.logger.info(message) 21 | 22 | def infoPrint(self, mesage): 23 | print (mesage) 24 | self.logger.info(mesage) 25 | 26 | def war(self, message): 27 | self.logger.warn(message) 28 | 29 | def error(self, message): 30 | self.logger.error(message) 31 | 32 | def cri(self, message): 33 | self.logger.critical(message) 34 | 35 | 36 | loggermap = {} 37 | def getLocalLogger(): 38 | logPath ="./log/" 39 | logName="info.log" 40 | isExists=os.path.exists(logPath) 41 | if not isExists: 42 | os.makedirs(logPath) 43 | if logPath+logName in loggermap: 44 | return loggermap[logPath+logName] 45 | else: 46 | logger = Logger(logPath+logName, logging.INFO, logging.INFO) 47 | loggermap[logPath+logName] = logger 48 | return logger 49 | 50 | if __name__ == '__main__': 51 | log = getLocalLogger() 52 | log.info("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv") -------------------------------------------------------------------------------- /deploy/docker/script/sign-start.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # sql start with 4 | # mysql -u${WEBASE_DB_UNAME} -p${WEBASE_DB_PWD} -h${WEBASE_DB_IP} -P${WEBASE_DB_PORT} -e 'use ${WEBASE_DB_NAME}' 5 | # init db if not exist 6 | echo "check database of ${WEBASE_DB_NAME}" 7 | echo "using u ${WEBASE_DB_UNAME} p ${WEBASE_DB_PWD} -h ${WEBASE_DB_IP} -P ${WEBASE_DB_PORT}" 8 | useCommand="use ${WEBASE_DB_NAME}" 9 | createCommand="create database ${WEBASE_DB_NAME} default character set utf8;" 10 | # echo "run command: [mysql -u${WEBASE_DB_UNAME} -p${WEBASE_DB_PWD} -h${WEBASE_DB_IP} -P${WEBASE_DB_PORT} -e ${useCommand}]" 11 | # echo "run command: [mysql -u${WEBASE_DB_UNAME} -p${WEBASE_DB_PWD} -h${WEBASE_DB_IP} -P${WEBASE_DB_PORT} -e ${createCommand}]" 12 | 13 | 14 | while true ; do 15 | #command 16 | sleep 1 17 | echo "check mysql status..." 18 | echo "select version();" | mysql -u${WEBASE_DB_UNAME} -p${WEBASE_DB_PWD} -h${WEBASE_DB_IP} -P${WEBASE_DB_PORT} 19 | if [ $? == 0 ] ; then 20 | echo "======== mysql is on" 21 | break; 22 | else 23 | (( ex_count = ${ex_count} + 1 )) 24 | echo "Waiting mysql to start! ex_count = ${ex_count}." 25 | if [ ${ex_count} -ge 10 ]; then 26 | echo "======== Connect to mysql timeout failed!" 27 | break; 28 | fi 29 | fi 30 | done 31 | 32 | echo "${useCommand}" | mysql -u${WEBASE_DB_UNAME} -p${WEBASE_DB_PWD} -h${WEBASE_DB_IP} -P${WEBASE_DB_PORT} 33 | if [ $? == 0 ]; then 34 | echo "database of [${WEBASE_DB_UNAME}] already exist, skip init" 35 | else 36 | # if return 1(db not exist), create db 37 | echo "now create database [${WEBASE_DB_NAME}]" 38 | echo "${createCommand}" | mysql -u${WEBASE_DB_UNAME} -p${WEBASE_DB_PWD} -h${WEBASE_DB_IP} -P${WEBASE_DB_PORT} --default-character-set=utf8 39 | if [ $? == 0 ]; then 40 | echo "========create database success!" 41 | else 42 | echo "======== create database of [${WEBASE_DB_NAME}] failed!" 43 | fi 44 | fi 45 | 46 | # this script used in docker-compose 47 | echo "start webase-sign now..." 48 | java ${JAVA_OPTS} -Djdk.tls.namedGroups="secp256k1", -Duser.timezone="Asia/Shanghai" -Djava.security.egd=file:/dev/./urandom, -Djava.library.path=/dist/conf -cp ${CLASSPATH} ${APP_MAIN} -------------------------------------------------------------------------------- /quick-start/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ./logs 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 28 | 30 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /quick-start/src/main/java/com/webank/webase/transaction/TransactionService.java: -------------------------------------------------------------------------------- 1 | package com.webank.webase.transaction; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONArray; 5 | import lombok.Data; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.beans.factory.annotation.Value; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.web.client.RestTemplate; 11 | 12 | import java.util.Objects; 13 | 14 | 15 | @Slf4j 16 | @Data 17 | @Service 18 | public class TransactionService { 19 | @Autowired 20 | private RestTemplate rest; 21 | @Value("${transactionUrl}") 22 | private String url; 23 | @Value("${userAddress}") 24 | private String user; 25 | @Value("${groupId}") 26 | private int groupId; 27 | @Value("${useAes}") 28 | private Boolean useAes; 29 | @Value("${contract.name}") 30 | private String contractName; 31 | @Value("${contract.address}") 32 | private String contractAddress; 33 | @Value("${contract.funcName}") 34 | private String funcName; 35 | @Value("${contract.funcParam}") 36 | private String funcParam; 37 | @Value("${contract.contractAbi}") 38 | private String contractAbi; 39 | 40 | public void sendTransaction() { 41 | 42 | try { 43 | TransactionParam transParam = new TransactionParam(); 44 | transParam.setGroupId(groupId); 45 | transParam.setContractAddress(contractAddress); 46 | transParam.setUseAes(useAes); 47 | transParam.setUser(user); 48 | transParam.setContractName(contractName); 49 | transParam.setFuncName(funcName); 50 | transParam.setFuncParam(JSONArray.parseArray(funcParam)); 51 | transParam.setContractAbi(JSONArray.parseArray(contractAbi)); 52 | 53 | log.info("transaction param:{}", JSON.toJSONString(transParam)); 54 | Object rsp = rest.postForObject(url, transParam, Object.class); 55 | String rspStr = "null"; 56 | if (Objects.nonNull(rsp)) { 57 | rspStr = JSON.toJSONString(rsp); 58 | } 59 | log.info("transaction result:{}", rspStr); 60 | } catch (Exception ex) { 61 | log.error("fail sendTransaction", ex); 62 | } 63 | System.exit(1); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /deploy/telnet.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | # encoding: utf-8 3 | 4 | import sys 5 | from comm.utils import * 6 | 7 | def do(): 8 | deploy_ip = "127.0.0.1" 9 | web_port = int(getCommProperties("web.port")) 10 | mgr_port = int(getCommProperties("mgr.port")) 11 | front_port = int(getCommProperties("front.port")) 12 | 13 | telnet_web = net_if_used_no_msg(deploy_ip,web_port) 14 | telnet_mgr = net_if_used_no_msg(deploy_ip,mgr_port) 15 | telnet_front = net_if_used_no_msg(deploy_ip,front_port) 16 | print ("telnet_web:{} telnet_mgr:{} telnet_front:{}".format(telnet_web, telnet_mgr, telnet_front)) 17 | 18 | if telnet_web and telnet_mgr and telnet_front: 19 | print ("deploy success.") 20 | else: 21 | print ("============= deploy log =============") 22 | deploy_log = doCmdIgnoreException("cat ./log/info.log") 23 | print (deploy_log["output"]) 24 | if not telnet_web: 25 | print ("============================ WeBASE-Web fail... ============================") 26 | context = doCmdIgnoreException("cat ./webase-web/log/access.log") 27 | print (context["output"]) 28 | if not telnet_mgr: 29 | print ("============================ WeBASE-Node-Manager fail... ============================") 30 | print ("============= node-manager.out =============") 31 | context1 = doCmdIgnoreException("cat ./webase-node-mgr/log/node-manager.out") 32 | print (context1["output"]) 33 | print ("============= WeBASE-Node-Manager.log =============") 34 | context2 = doCmdIgnoreException("cat ./webase-node-mgr/log/WeBASE-Node-Manager.log") 35 | print (context2["output"]) 36 | if not telnet_front: 37 | print ("============================ WeBASE-Front fail... ============================") 38 | print ("============= front.out =============") 39 | context1 = doCmdIgnoreException("cat ./webase-front/log/front.out") 40 | print (context1["output"]) 41 | print ("============= WeBASE-Front.log =============") 42 | context2 = doCmdIgnoreException("cat ./webase-front/log/WeBASE-Front.log") 43 | print (context2["output"]) 44 | print ("============= web3sdk.log =============") 45 | context3 = doCmdIgnoreException("cat ./webase-front/log/web3sdk.log") 46 | print (context3["output"]) 47 | raise Exception("deploy fail.") 48 | if __name__ == '__main__': 49 | do() 50 | pass -------------------------------------------------------------------------------- /quick-start/build.gradle: -------------------------------------------------------------------------------- 1 | group = 'com.webank.webase' 2 | version = '0.0.1-SNAPSHOT' 3 | 4 | apply plugin: 'maven' 5 | apply plugin: 'java' 6 | apply plugin: 'idea' 7 | apply plugin: 'eclipse' 8 | 9 | 10 | sourceCompatibility = 1.8 11 | targetCompatibility = 1.8 12 | 13 | [compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8' 14 | 15 | // In this section you declare where to find the dependencies of your project 16 | repositories { 17 | maven {url "http://maven.aliyun.com/nexus/content/groups/public/"} 18 | 19 | mavenLocal() 20 | mavenCentral() 21 | } 22 | 23 | def springboot_version="2.1.2.RELEASE" 24 | List springboot = [ 25 | "org.springframework.boot:spring-boot-starter-web:$springboot_version", 26 | "org.springframework.boot:spring-boot-starter-log4j2:$springboot_version" 27 | ] 28 | 29 | 30 | List lombok = [ 31 | "org.projectlombok:lombok:1.18.2" 32 | ] 33 | 34 | List test = [ 35 | "org.springframework.boot:spring-boot-starter-test:$springboot_version" 36 | ] 37 | 38 | 39 | dependencies { 40 | compile springboot 41 | // compile "org.apache.commons:commons-lang3:3.8.1" 42 | compile "com.alibaba:fastjson:1.2.60" 43 | 44 | compileOnly lombok 45 | 46 | testCompile test 47 | } 48 | 49 | configurations { 50 | all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' 51 | all*.exclude group: 'org.slf4j', module: 'slf4j-log4j12' 52 | all*.exclude group: 'log4j', module: 'log4j' 53 | all*.exclude group: 'org.ow2.asm', module: 'asm' 54 | all*.exclude group: 'jline', module: 'jline' 55 | all*.exclude group: 'com.google.protobuf', module: 'protobuf-java' 56 | all*.exclude group: 'javax.annotation', module: 'javax.annotation-api' 57 | } 58 | 59 | sourceSets { 60 | main { 61 | java { 62 | srcDir 'src/main/java' 63 | } 64 | resources { 65 | srcDir 'src/main/resources' 66 | } 67 | } 68 | } 69 | 70 | clean { 71 | delete 'dist' 72 | delete 'build' 73 | } 74 | 75 | 76 | jar { 77 | destinationDir file('dist/apps') 78 | archiveName project.name + '.jar' 79 | exclude '**/*.xml' 80 | exclude '**/*.yml' 81 | exclude '**/*.properties' 82 | 83 | doLast { 84 | copy { 85 | from file('src/main/resources/') 86 | into 'dist/conf' 87 | } 88 | copy { 89 | from file('script/') 90 | into 'dist/script' 91 | } 92 | copy { 93 | from configurations.runtime 94 | into 'dist/lib' 95 | } 96 | copy { 97 | from file('.').listFiles().findAll{File f -> (f.name.endsWith('.bat') || f.name.endsWith('.sh') || f.name.endsWith('.env'))} 98 | into 'dist' 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /deploy/common.properties: -------------------------------------------------------------------------------- 1 | [common] 2 | 3 | # Webase Subsystem Version (v1.1.0 or above) 4 | webase.web.version=v1.5.5 5 | webase.mgr.version=v1.5.5 6 | webase.sign.version=v1.5.5 7 | webase.front.version=v1.5.5 8 | 9 | ##################################################################### 10 | # if use [installDockerAll] to install WeBASE by docker 11 | # if use [installAll] or [installWeBASE], ignore configuration here 12 | 13 | # 1: enable mysql in docker 14 | # 0: mysql run in host, required fill in the configuration of webase-node-mgr and webase-sign 15 | docker.mysql=1 16 | 17 | # if [docker.mysql=1], mysql run in host (only works in [installDockerAll]) 18 | # run mysql 5.6 by docker 19 | docker.mysql.port=23306 20 | # default user [root] 21 | docker.mysql.password=123456 22 | ##################################################################### 23 | 24 | # Mysql database configuration of WeBASE-Node-Manager 25 | mysql.ip=localhost 26 | mysql.port=3306 27 | mysql.user=dbUsername 28 | mysql.password=dbPassword 29 | mysql.database=webasenodemanager 30 | 31 | # Mysql database configuration of WeBASE-Sign 32 | sign.mysql.ip=localhost 33 | sign.mysql.port=3306 34 | sign.mysql.user=dbUsername 35 | sign.mysql.password=dbPassword 36 | sign.mysql.database=webasesign 37 | # if docker mysql disabled[docker.mysql=0] above 38 | 39 | # H2 database name of WeBASE-Front (docker mode ignore this) 40 | front.h2.name=webasefront 41 | front.org=fisco 42 | 43 | # WeBASE-Web service port 44 | web.port=5000 45 | # enable WeBASE-Web overview pages for mobile phone(docker mode not support h5 yet) 46 | # (0: disable, 1: enable) 47 | web.h5.enable=1 48 | 49 | # WeBASE-Node-Manager service port 50 | mgr.port=5001 51 | 52 | # WeBASE-Front service port 53 | front.port=5002 54 | 55 | # WeBASE-Sign service port 56 | sign.port=5004 57 | 58 | # Node listening IP 59 | node.listenIp=127.0.0.1 60 | # Node p2p service port 61 | node.p2pPort=30300 62 | # Node channel service port 63 | node.channelPort=20200 64 | # Node rpc service port 65 | node.rpcPort=8545 66 | 67 | # Encrypt type (0: standard, 1: guomi) 68 | encrypt.type=0 69 | # ssl encrypt type (0: standard ssl, 1: guomi ssl) 70 | # only guomi type support guomi ssl 71 | encrypt.sslType=0 72 | 73 | # Use existing chain or not (yes/no) 74 | if.exist.fisco=no 75 | 76 | ### if build new chain, [if.exist.fisco=no] 77 | # Configuration required when building a new chain 78 | # Fisco-bcos version (v2.11.0) 79 | fisco.version=v2.11.0 80 | # Number of building nodes (default value: 2) 81 | node.counts=nodeCounts 82 | 83 | ### if using exited chain, [if.exist.fisco=yes] 84 | # The path of the existing chain, the path of the start_all.sh script 85 | # Under the path, there should be a 'sdk' directory where the SDK certificates (ca.crt, sdk.crt, node.key and gm directory(gm ssl)) are stored 86 | fisco.dir=/data/app/nodes/127.0.0.1 87 | # Node directory in [fisco.dir] for WeBASE-Front to connect 88 | # example: 'node.dir=node0' would auto change to '/data/app/nodes/127.0.0.1/node0' 89 | # Under the path, there is a conf directory where node certificates (ca.crt, node.crt and node.key) are stored 90 | node.dir=node0 91 | 92 | -------------------------------------------------------------------------------- /deploy/docker/script/mgr-start.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # sql start with 4 | # mysql -u${WEBASE_DB_UNAME} -p${WEBASE_DB_PWD} -h${WEBASE_DB_IP} -P${WEBASE_DB_PORT} -e 'use ${WEBASE_DB_NAME}' 5 | # init db if not exist 6 | echo "check database of ${WEBASE_DB_NAME}" 7 | echo "using u ${WEBASE_DB_UNAME} p ${WEBASE_DB_PWD} -h ${WEBASE_DB_IP} -P ${WEBASE_DB_PORT}" 8 | 9 | useCommand="use ${WEBASE_DB_NAME}" 10 | createCommand="create database ${WEBASE_DB_NAME} default character set utf8" 11 | # echo "run command: [mysql -u${WEBASE_DB_UNAME} -p${WEBASE_DB_PWD} -h${WEBASE_DB_IP} -P${WEBASE_DB_PORT} -e ${useCommand}]" 12 | # echo "run command: [mysql -u${WEBASE_DB_UNAME} -p${WEBASE_DB_PWD} -h${WEBASE_DB_IP} -P${WEBASE_DB_PORT} -e ${createCommand}]" 13 | 14 | while true ; do 15 | #command 16 | sleep 1 17 | echo "check mysql status..." 18 | echo "select version();" | mysql -u${WEBASE_DB_UNAME} -p${WEBASE_DB_PWD} -h${WEBASE_DB_IP} -P${WEBASE_DB_PORT} 19 | if [ $? == 0 ] ; then 20 | echo "mysql is on" 21 | break; 22 | else 23 | (( ex_count = ${ex_count} + 1 )) 24 | echo "Waiting mysql to start! ex_count = ${ex_count}." 25 | if [ ${ex_count} -ge 10 ]; then 26 | echo "Connect to mysql timeout failed!" 27 | break; 28 | fi 29 | fi 30 | done 31 | 32 | echo "${useCommand}" | mysql -u${WEBASE_DB_UNAME} -p${WEBASE_DB_PWD} -h${WEBASE_DB_IP} -P${WEBASE_DB_PORT} 33 | if [ $? == 0 ]; then 34 | echo "database of [${WEBASE_DB_UNAME}] already exist, skip init" 35 | else 36 | # if return 1(db not exist), create db 37 | echo "now create database [${WEBASE_DB_NAME}]" 38 | echo "${createCommand}" | mysql -u${WEBASE_DB_UNAME} -p${WEBASE_DB_PWD} -h${WEBASE_DB_IP} -P${WEBASE_DB_PORT} --default-character-set=utf8 39 | if [ $? == 0 ]; then 40 | echo "======== create database success!" 41 | echo "now create tables" 42 | # sed /dist/script/webase.sh 43 | # sed -i "s:defaultAccount:${WEBASE_DB_UNAME}:g" /dist/script/webase.sh 44 | # sed -i "s:defaultPassword:${WEBASE_DB_PWD}:g" /dist/script/webase.sh 45 | # create table 46 | mysql -u${WEBASE_DB_UNAME} -p${WEBASE_DB_PWD} -h${WEBASE_DB_IP} -P${WEBASE_DB_PORT} -D ${WEBASE_DB_NAME} --default-character-set=utf8 -e "source /dist/script/webase-ddl.sql" 47 | if [ $? == 0 ]; then 48 | echo "now init table data" 49 | mysql -u${WEBASE_DB_UNAME} -p${WEBASE_DB_PWD} -h${WEBASE_DB_IP} -P${WEBASE_DB_PORT} -D ${WEBASE_DB_NAME} --default-character-set=utf8 -e "source /dist/script/webase-dml.sql" 50 | if [ $? == 0 ]; then 51 | echo "======== init table data success!" 52 | else 53 | echo "======= int table data of [webase-dml.sql] failed!" 54 | fi 55 | else 56 | echo " ======= create tables of [webase-ddl.sql] failed!" 57 | fi 58 | else 59 | echo "======= create database of [${WEBASE_DB_NAME}] failed!" 60 | fi 61 | fi 62 | 63 | 64 | # this script used in docker-compose 65 | echo "start webase-node-mgr now..." 66 | java ${JAVA_OPTS} -Djdk.tls.namedGroups="secp256k1", -Duser.timezone="Asia/Shanghai" -Djava.security.egd=file:/dev/./urandom, -Djava.library.path=/dist/conf -cp ${CLASSPATH} ${APP_MAIN} -------------------------------------------------------------------------------- /deploy/comm/nginx.conf: -------------------------------------------------------------------------------- 1 | user root; 2 | worker_processes 1; 3 | 4 | error_log log_path/error.log; 5 | 6 | pid pid_file; 7 | 8 | events { 9 | worker_connections 1024; 10 | } 11 | 12 | http { 13 | include /etc/nginx/mime.types; 14 | default_type application/octet-stream; 15 | 16 | #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 17 | # '$status $body_bytes_sent "$http_referer" ' 18 | # '"$http_user_agent" "$http_x_forwarded_for"'; 19 | 20 | access_log log_path/access.log ; 21 | 22 | sendfile on; 23 | #tcp_nopush on; 24 | 25 | #keepalive_timeout 0; 26 | keepalive_timeout 65; 27 | 28 | #gzip on; 29 | add_header X-Frame-Options SAMEORIGIN; 30 | upstream node_mgr_server{ 31 | server 127.0.0.1:5001; 32 | } 33 | server { 34 | listen 5000 default_server; 35 | server_name 127.0.0.1; 36 | location / { 37 | # default pc page url 38 | root web_page_url; 39 | # if using phone 40 | if ( $http_user_agent ~ "(MIDP)|(WAP)|(UP.Browser)|(Smartphone)|(Obigo)|(Mobile)|(AU.Browser)|(wxd.Mms)|(WxdB.Browser)|(CLDC)|(UP.Link)|(KM.Browser)|(UCWEB)|(SEMC-Browser)|(Mini)|(Symbian)|(Palm)|(Nokia)|(Panasonic)|(MOT-)|(SonyEricsson)|(NEC-)|(Alcatel)|(Ericsson)|(BENQ)|(BenQ)|(Amoisonic)|(Amoi-)|(Capitel)|(PHILIPS)|(SAMSUNG)|(Lenovo)|(Mitsu)|(Motorola)|(SHARP)|(WAPPER)|(LG-)|(LG/)|(EG900)|(CECT)|(Compal)|(kejian)|(Bird)|(BIRD)|(G900/V1.0)|(Arima)|(CTL)|(TDG)|(Daxian)|(DAXIAN)|(DBTEL)|(Eastcom)|(EASTCOM)|(PANTECH)|(Dopod)|(Haier)|(HAIER)|(KONKA)|(KEJIAN)|(LENOVO)|(Soutec)|(SOUTEC)|(SAGEM)|(SEC-)|(SED-)|(EMOL-)|(INNO55)|(ZTE)|(iPhone)|(Android)|(Windows CE)|(Wget)|(Java)|(curl)|(Opera)" ) 41 | { 42 | root phone_page_url; 43 | } 44 | index index.html index.htm; 45 | try_files $uri $uri/ /index.html =404; 46 | } 47 | 48 | include /etc/nginx/default.d/*.conf; 49 | 50 | location /mgr { 51 | proxy_pass http://node_mgr_server/; 52 | proxy_set_header Host $host; 53 | proxy_set_header X-Real-IP $remote_addr; 54 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 55 | } 56 | 57 | error_page 404 /404.html; 58 | location = /40x.html { 59 | } 60 | 61 | error_page 500 502 503 504 /50x.html; 62 | location = /50x.html { 63 | } 64 | 65 | # zip solidity js file 66 | gzip on; 67 | gzip_min_length 10k; 68 | gzip_buffers 32 4k; 69 | gzip_http_version 1.0; 70 | gzip_comp_level 1; 71 | gzip_proxied any; 72 | gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/vnd.ms-fontobject font/ttf font/opentype font/x-woff image/svg+xml; 73 | gzip_vary on; 74 | gzip_disable "MSIE [1-6]\."; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /deploy/webase-upgrade.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | 6 | ################################################ 7 | # 2024.10.12:deprecated upgrade by cdn 8 | #根据新版本到CDN下载对应版本的upgrade.sh脚本文件,并执行 9 | ################################################ 10 | 11 | ####### error code 12 | SUCCESS=0 13 | 14 | PARAM_ERROR=5 15 | 16 | ## default one host, one node+front 17 | old_version= 18 | new_version= 19 | 20 | # download url prefix 21 | cdn_url_pre="https://osp-1257653870.cos.ap-guangzhou.myqcloud.com/WeBASE/releases/download" 22 | logfile=${PWD}/upgrade.log 23 | 24 | # dependencies 25 | depend_list=("python3" "dos2unix" "unzip" "mysql" "mysqldump" "curl") 26 | 27 | LOG_WARN() 28 | { 29 | local content=${1} 30 | echo -e "\033[31m[WARN] ${content}\033[0m" 31 | echo "[WARN] ${content}" >> ${logfile} 32 | } 33 | 34 | LOG_INFO() 35 | { 36 | local content=${1} 37 | echo -e "\033[32m[INFO] ${content}\033[0m" 38 | echo "[INFO] ${content}" >> ${logfile} 39 | } 40 | 41 | ####### 参数解析 ####### 42 | cmdname=$(basename "$0") 43 | 44 | # usage help doc. 45 | usage() { 46 | cat << USAGE >&2 47 | Usage: 48 | $cmdname [-o old_version] [-n new_version] 49 | 50 | -o old version, ex: v1.4.3 51 | -n new version, ex: v1.5.0 52 | USAGE 53 | exit ${PARAM_ERROR} 54 | } 55 | 56 | 57 | while getopts o:n:h OPT;do 58 | case ${OPT} in 59 | o) 60 | old_version="$OPTARG" 61 | ;; 62 | n) 63 | new_version="$OPTARG" 64 | ;; 65 | h) 66 | usage 67 | exit ${PARAM_ERROR} 68 | ;; 69 | \?) 70 | usage 71 | exit ${PARAM_ERROR} 72 | ;; 73 | esac 74 | done 75 | 76 | function checkCurl() { 77 | for package in ${depend_list[@]}; 78 | do 79 | if [[ ! $(command -v ${package}) ]]; then 80 | LOG_WARN "dependencies of [${package}] not installed, please install it and try again!" 81 | exit 1 82 | fi 83 | done 84 | LOG_INFO "check dependencies passed!" 85 | } 86 | 87 | function get_upgrade() { 88 | if [[ ! -f "${PWD}/upgrade-${new_version}.sh" ]]; then 89 | LOG_INFO "upgrade-${new_version}.sh script exists, now delete and re-download" 90 | rm -f ${PWD}/upgrade-${new_version}.sh 91 | fi 92 | curl -#LO "${cdn_url_pre}/${new_version}/upgrade-${new_version}.sh" 93 | if [[ "$(ls -al . | grep upgrade-${new_version}.sh | awk '{print $5}')" -lt "10000" ]];then # 1m=1048576b 94 | LOG_WARN "download upgrade script failed, exit!" 95 | exit 1 96 | fi 97 | chmod +x upgrade-${new_version}.sh 98 | source upgrade-${new_version}.sh 99 | } 100 | 101 | 102 | ## 版本号获取数字,v1.5.0 => 150 103 | function get_version_num() { 104 | old_version_num=`echo "${old_version}" | tr -cd "[0-9]"` 105 | new_version_num=`echo "${new_version}" | tr -cd "[0-9]"` 106 | if [[ "${old_version_num}" -eq "" || "${new_version_num}" -eq "" ]];then 107 | LOG_WARN "error! please type in version" 108 | usage 109 | exit 1 110 | fi 111 | LOG_INFO "Tips: upgrade script only support nearing version (new: ${new_version_num}, old: ${old_version_num} )upgrade" 112 | } 113 | 114 | get_version_num 115 | get_upgrade 116 | -------------------------------------------------------------------------------- /deploy/docker/docker-compose-template.yaml: -------------------------------------------------------------------------------- 1 | services: 2 | 3 | webase-front: 4 | image: webasepro/webase-front:v1.5.3 5 | container_name: webase-front-5002 6 | network_mode: "host" 7 | environment: 8 | SPRING_PROFILES_ACTIVE: docker 9 | SERVER_PORT: 5002 10 | SDK_IP: 127.0.0.1 11 | SDK_CHANNEL_PORT: 20200 12 | KEY_SERVER: "127.0.0.1:5004" 13 | volumes: 14 | - /webase-deploy/nodes/127.0.0.1/sdk:/dist/sdk 15 | # - /webase-deploy/webase-front/application-docker.yml:/dist/conf/application-docker.yml 16 | - /webase-deploy/webase-front/log:/dist/log 17 | - /webase-deploy/webase-front/h2:/h2 18 | - ./script/wait-for-it.sh:/wait-for-it.sh # chmod +x wait-for-it.sh 19 | - ./script/front-start.sh:/start.sh 20 | depends_on: 21 | - webase-sign 22 | entrypoint: ["/wait-for-it.sh", "127.0.0.1:20200", "--timeout=5", "--strict", "--", "bash", "/start.sh"] 23 | 24 | webase-node-mgr: 25 | image: webasepro/webase-node-mgr:v1.5.3 26 | container_name: webase-node-mgr-5001 27 | network_mode: "host" 28 | environment: 29 | SPRING_PROFILES_ACTIVE: docker 30 | SERVER_PORT: 5001 31 | WEBASE_DB_IP: 127.0.0.1 32 | WEBASE_DB_PORT: 23306 33 | WEBASE_DB_NAME: webasenodemanager 34 | WEBASE_DB_UNAME: root 35 | WEBASE_DB_PWD: 123456 36 | ENCRYPT_TYPE: 0 37 | volumes: 38 | # - /webase-deploy/webase-node-mgr/application-docker.yml:/dist/conf/application-docker.yml 39 | - /webase-deploy/webase-node-mgr/log:/dist/log 40 | - ./script/wait-for-it.sh:/wait-for-it.sh 41 | - ./script/mgr-start.sh:/start.sh 42 | depends_on: 43 | - mysql 44 | - webase-sign 45 | - webase-front 46 | entrypoint: ["/wait-for-it.sh", "127.0.0.1:23306", "--timeout=10", "--strict", "--", "bash", "/start.sh"] 47 | 48 | 49 | webase-sign: 50 | image: webasepro/webase-sign:v1.5.3 51 | container_name: webase-sign-5004 52 | network_mode: "host" 53 | environment: 54 | SPRING_PROFILES_ACTIVE: docker 55 | SERVER_PORT: 5004 56 | WEBASE_DB_IP: 127.0.0.1 57 | WEBASE_DB_PORT: 23306 58 | WEBASE_DB_NAME: webasesign 59 | WEBASE_DB_UNAME: root 60 | WEBASE_DB_PWD: 123456 61 | volumes: 62 | # - /webase-deploy/webase-sign/application-docker.yml:/dist/conf/application-docker.yml 63 | - /webase-deploy/webase-sign/log:/dist/log 64 | - ./script/wait-for-it.sh:/wait-for-it.sh 65 | - ./script/sign-start.sh:/start.sh 66 | depends_on: 67 | - mysql 68 | entrypoint: ["/wait-for-it.sh", "127.0.0.1:23306", "--timeout=10", "--strict", "--", "bash", "/start.sh"] 69 | 70 | webase-web: 71 | image: webasepro/webase-web:v1.5.3 72 | container_name: webase-web-5000 73 | network_mode: "host" 74 | volumes: 75 | - /webase-deploy/webase-web/nginx-docker.conf:/data/webase-web/nginx/nginx.conf 76 | - /webase-deploy/webase-web/log:/dist/log 77 | - ./script/wait-for-it.sh:/wait-for-it.sh 78 | - ./script/web-start.sh:/start.sh 79 | depends_on: 80 | - webase-node-mgr 81 | entrypoint: ["/wait-for-it.sh", "127.0.0.1:5001", "--timeout=30", "--", "bash", "/start.sh"] 82 | 83 | mysql: 84 | image: mysql:5.6 85 | environment: 86 | MYSQL_ROOT_PASSWORD: 123456 87 | ports: 88 | - "23306:3306" 89 | container_name: mysql-webase-23306 90 | volumes: 91 | - /webase-deploy/mysql/data:/var/lib/mysql 92 | 93 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 中文|[English](README-en.md) 2 | 3 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://webasedoc.readthedocs.io/zh_CN/latest/docs/WeBASE/CONTRIBUTING.html) 4 | [![Code Lines](https://tokei.rs/b1/github/WeBankBlockchain/WeBASE?category=code)](https://github.com/WeBankBlockchain/WeBASE) 5 | [![license](http://img.shields.io/badge/license-Apache%20v2-blue.svg)](http://www.apache.org/licenses/) 6 | [![GitHub (pre-)release](https://img.shields.io/github/release/WeBankBlockchain/WeBASE/all.svg)](https://github.com/WeBankBlockchain/WeBASE/releases) 7 | 8 | ![image](https://webasedoc.readthedocs.io/zh_CN/latest/_images/logo.jpg) 9 | 10 | # 什么是WeBASE 11 | 12 | **WeBASE**(WeBank Blockchain Application Software Extension) 是在区块链应用和FISCO BCOS节点之间搭建的一套通用组件,围绕交易、合约、密钥管理,数据,可视化管理来设计各个模块。开发者可以根据业务所需,选择子系统进行部署。 13 | 14 | **WeBASE**屏蔽了区块链底层的复杂度,降低开发者的门槛,大幅提高区块链应用的开发效率,包含**节点前置**、**节点管理**、**Web管理平台**、**签名服务**、**数据导出**等子系统。 15 | 16 | **WeBASE**将区块链应用开发标准化,搭建完FISCO BCOS节点后,只需按照五步标准流程进行区块链应用开发,开发流程请参阅 [使用WeBASE开发区块链应用](https://github.com/WeBankBlockchain/WeBASE-Doc/blob/master/docs/WeBASE/quick-start.md) 17 | 18 | **WeBASE一键部署**(FISCO BCOS + WeBASE-Front + WeBASE-Node-Manager + WeBASE-Sign + WeBASE-Web)可以参考[WeBASE一键部署文档](https://webasedoc.readthedocs.io/zh_CN/latest/docs/WeBASE/install.html),**WeBASE**整体结构设计与各子系统功能与安装部署的详细介绍,请参考[WeBASE在线文档](https://webasedoc.readthedocs.io/zh_CN/latest/index.html) 19 | 20 | 21 | ## 技术文档 22 | - **WeBASE 1.x版本** 适用于FISCO-BCOS **2.x版本**,可查看 [WeBASE 1.x文档](https://webasedoc.readthedocs.io/zh_CN/latest/index.html) (stable) 23 | - **WeBASE 3.x版本** 适用于FISCO-BCOS **3.x版本**,可查看 [WeBASE 3.x文档](https://webasedoc.readthedocs.io/zh_CN/lab),相关代码位于master-3.0分支 24 | 25 | ## 各子系统简介 26 | * **节点前置服务 [WeBASE-Front](https://github.com/WeBankBlockchain/WeBASE-Front)** 27 | 集成java-sdk,提供restful风格的接口,客户端可以使用http的形式和节点进行交互,内置内存数据库,采集节点健康度数据。内置web控制台,实现节点的可视化、合约部署IDE等功能。 28 | 29 | * **节点管理服务 [WeBASE-Node-Manager](https://github.com/WeBankBlockchain/WeBASE-Node-Manager)** 30 | 处理WeBASE-Web前端页面所有web请求,基于前置服务,管理各个节点的状态,管理链上所有智能合约,对区块链的数据进行统计、分析,对异常交易的审计,私钥管理等。 31 | 32 | * **WeBASE管理平台 [WeBASE-Web](https://github.com/WeBankBlockchain/WeBASE-Web)** 33 | 基于节点管理服务的可视化操作平台,可基于此平台查看节点信息,开发智能合约等。 34 | 35 | * **交易服务 [WeBASE-Transcation](https://github.com/WeBankBlockchain/WeBASE-Transaction)** 36 | 接收交易请求,缓存交易到数据库中,异步上链,可大幅提升吞吐量,解决区块链的tps瓶颈问题。 37 | 38 | * **私钥托管和签名服务 [WeBASE-Sign](https://github.com/WeBankBlockchain/WeBASE-Sign)** 39 | 托管用户私钥,提供云端签名。 40 | 41 | * **数据导出代码生成工具 [WeBASE-Codegen-Monkey](https://github.com/WeBankBlockchain/WeBASE-Codegen-Monkey)** 42 | 代码生成工具,通过配置可以生成数据导出的核心代码。 43 | 44 | * **数据导出服务 [WeBASE-Collect-Bee](https://github.com/WeBankBlockchain/WeBASE-Collect-Bee)** 45 | 导出区块链上的基础数据,如当前块高、交易总量等,通过智能合约的配置,导出区块链上合约的业务数据,包括event、构造函数、合约地址、执行函数的信息等。 46 | 47 | * **链管理服务 [WeBASE-Chain-Manager](https://github.com/WeBankBlockchain/WeBASE-Chain-Manager)** 48 | 链管理服务支持管理多条链,支持国密链、非国密链。对外提供群组的增删查改接口,让用户可以便捷地建立自己应用的群组。 49 | 50 | * **合约安全检测服务 [WeBASE-Solidity-Security](https://github.com/WeBankBlockchain/WeBASE-Solidity-Security)** 51 | 合约安全检测服务继承了solidity合约检测工具slither,对外提供检测接口。 52 | 53 | * **数据统计服务 [WeBASE-Stat](https://github.com/WeBankBlockchain/WeBASE-Stat)** 54 | 统计数据服务以前置为基础,拉取CPU、内存、IO、群组大小、群组gas、群组网络流量的数据,记录数据库。 55 | 56 | * **数据监管服务 [WeBASE-Data](https://github.com/WeBankBlockchain/WeBASE-Data)** 57 | 数据监管服务以前置为基础,导出区块链数据并解析,提供一个可视化的监管视图。可以查询交易属于哪条链,哪个用户,哪个合约,保证链上数据可查可管。 58 | 59 | 60 | ## 贡献说明 61 | 请阅读我们的[贡献文档](https://webasedoc.readthedocs.io/zh_CN/latest/docs/WeBASE/CONTRIBUTING.html),了解如何贡献代码,并提交你的贡献。 62 | 63 | 希望在您的参与下,WeBASE会越来越好! 64 | 65 | ## 社区 66 | 联系我们:webase@webank.com 67 | 68 | 社区小助手微信ID : WeBank_Blockchain 69 | -------------------------------------------------------------------------------- /deploy/docker/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | services: 2 | 3 | webase-front: 4 | image: webasepro/webase-front:v0.0.2 5 | container_name: webase-front-5002 6 | network_mode: "host" 7 | environment: 8 | SPRING_PROFILES_ACTIVE: docker 9 | SERVER_PORT: 5002 10 | SDK_IP: sdkIp 11 | SDK_CHANNEL_PORT: sdkChannelPort 12 | KEY_SERVER: signIpPort 13 | volumes: 14 | - /webase-deploy/nodes/127.0.0.1/sdk:/dist/sdk 15 | # - /webase-deploy/webase-front/application-docker.yml:/dist/conf/application-docker.yml 16 | - /webase-deploy/webase-front/log:/dist/log 17 | - /webase-deploy/webase-front/h2:/h2 18 | - ./script/wait-for-it.sh:/wait-for-it.sh # chmod +x wait-for-it.sh 19 | - ./script/front-start.sh:/start.sh 20 | depends_on: 21 | - webase-sign 22 | entrypoint: ["/wait-for-it.sh", "sdkIp:sdkChannelPort", "--timeout=10", "--strict", "--", "bash", "/start.sh"] 23 | 24 | webase-node-mgr: 25 | image: webasepro/webase-node-mgr:v0.0.2 26 | container_name: webase-node-mgr-5001 27 | network_mode: "host" 28 | environment: 29 | SPRING_PROFILES_ACTIVE: docker 30 | SERVER_PORT: 5001 31 | WEBASE_DB_IP: mgrDbIp 32 | WEBASE_DB_PORT: mgrDbPort 33 | WEBASE_DB_NAME: webasenodemanager 34 | WEBASE_DB_UNAME: mgrDefaultAccount 35 | WEBASE_DB_PWD: mgrDefaultPassword 36 | ENCRYPT_TYPE: mgrEncryptType 37 | volumes: 38 | # - /webase-deploy/webase-node-mgr/application-docker.yml:/dist/conf/application-docker.yml 39 | - /webase-deploy/webase-node-mgr/log:/dist/log 40 | - ./script/wait-for-it.sh:/wait-for-it.sh 41 | - ./script/mgr-start.sh:/start.sh 42 | depends_on: 43 | - mysql 44 | - webase-sign 45 | - webase-front 46 | entrypoint: ["/wait-for-it.sh", "mgrDbIp:mgrDbPort", "--timeout=5", "--strict", "--", "bash", "/start.sh"] 47 | 48 | 49 | webase-sign: 50 | image: webasepro/webase-sign:v0.0.2 51 | container_name: webase-sign-5004 52 | network_mode: "host" 53 | environment: 54 | SPRING_PROFILES_ACTIVE: docker 55 | SERVER_PORT: 5004 56 | WEBASE_DB_IP: signDbIp 57 | WEBASE_DB_PORT: signDbPort 58 | WEBASE_DB_NAME: webasesign 59 | WEBASE_DB_UNAME: signDefaultAccount 60 | WEBASE_DB_PWD: signDefaultPassword 61 | volumes: 62 | # - /webase-deploy/webase-sign/application-docker.yml:/dist/conf/application-docker.yml 63 | - /webase-deploy/webase-sign/log:/dist/log 64 | - ./script/wait-for-it.sh:/wait-for-it.sh 65 | - ./script/sign-start.sh:/start.sh 66 | depends_on: 67 | - mysql 68 | entrypoint: ["/wait-for-it.sh", "signDbIp:signDbPort", "--timeout=5", "--strict", "--", "bash", "/start.sh"] 69 | 70 | webase-web: 71 | image: webasepro/webase-web:v0.0.2 72 | container_name: webase-web-5000 73 | network_mode: "host" 74 | volumes: 75 | - /webase-deploy/webase-web/nginx-docker.conf:/data/webase-web/nginx/nginx.conf 76 | - /webase-deploy/webase-web/log:/dist/log 77 | - ./script/wait-for-it.sh:/wait-for-it.sh 78 | - ./script/web-start.sh:/start.sh 79 | depends_on: 80 | - webase-node-mgr 81 | entrypoint: ["/wait-for-it.sh", "127.0.0.1:5001", "--timeout=30", "--", "bash", "/start.sh"] 82 | 83 | mysql: 84 | image: mysql:5.6 85 | environment: 86 | MYSQL_ROOT_PASSWORD: 123456 87 | ports: 88 | - "23306:3306" 89 | container_name: mysql-webase-23306 90 | volumes: 91 | - /webase-deploy/mysql/data:/var/lib/mysql 92 | # entrypoint: ["echo", "Service [mysql] disabled"] 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /quick-start.md: -------------------------------------------------------------------------------- 1 | # 使用WeBASE开发区块链应用 2 | 3 | ## 1 部署WeBASE 4 | 搭建WeBASE, 请参考[快速部署](https://webasedoc.readthedocs.io/zh_CN/latest/docs/WeBASE/install.html) 5 | 6 | ## 2 登录WeBASE管理平台进行配置 7 | 安装WeBASE完成后,需要将节点信息添加到WeBASE平台中,这样WeBASE才可和节点进行通信。需要添加的信息包含节点信息,生成用户的私钥等。如下图所示: 8 | 9 | * 节点信息: 10 | ![[节点]](./images/frontInfo.png) 11 | 12 | * 私钥用户: 13 | ![[私钥用户]](./images/keyUser.png) 14 | 15 | ## 3 开发智能合约 16 | 以HelloWorld.sol为例 17 | ``` 18 | pragma solidity ^0.4.2; 19 | 20 | contract HelloWorld{ 21 | string name; 22 | 23 | function HelloWorld(){ 24 | name = "Hello, World!"; 25 | } 26 | 27 | function get()constant returns(string){ 28 | return name; 29 | } 30 | 31 | function set(string n){ 32 | name = n; 33 | } 34 | } 35 | ``` 36 | 37 | * 通过智能合约IDE部署合约,并获取合约地址等信息, 38 | ![[合约]](./images/contract.png) 39 | 40 | 41 | 42 | ## 4 应用层开发 43 | 44 | ### 4.1 根据所写合约和交易api的格式,发送交易。 45 | 请参考[交易接口](https://webasedoc.readthedocs.io/zh_CN/latest/docs/WeBASE-Front/interface.html#id235) 46 | 47 | 从IDE中的输出信息,拷贝合约地址,合约名,方法名等信息,同时获取用户的公钥信息,调用交易接口。 48 | 具体代码请参考 [HelloWorld范例](https://github.com/WeBankFinTech/WeBASE/tree/master/quick-start) 49 | 50 | ### 4.2 接口调用的主要代码: 51 | * application.yml 52 | ``` 53 | transactionUrl: http://127.0.0.1:5002/WeBASE-Front/trans/handle 54 | groupId: 1 55 | userAddress: "0x4f08eac5af5e77b7006d11bee94adba2f721def8" 56 | useAes: true 57 | contract.name: HelloWorld 58 | contract.address: "0xca597170829f4ad5054b618425a56e0be23cbc55" 59 | contract.funcName: set 60 | contract.funcParam: "[\"abc\"]" 61 | contract.contractAbi: "[{\"constant\":false,\"inputs\":[{\"name\":\"n\",\"type\":\"string\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" 62 | ``` 63 | * TransactionService.java 64 | ``` 65 | @Slf4j 66 | @Data 67 | @Service 68 | public class TransactionService { 69 | @Autowired 70 | private RestTemplate rest; 71 | @Value("${transactionUrl}") 72 | private String url; 73 | @Value("${userAddress}") 74 | private String user; 75 | @Value("${groupId}") 76 | private int groupId; 77 | @Value("${useAes}") 78 | private Boolean useAes; 79 | @Value("${contract.name}") 80 | private String contractName; 81 | @Value("${contract.address}") 82 | private String contractAddress; 83 | @Value("${contract.funcName}") 84 | private String funcName; 85 | @Value("${contract.funcParam}") 86 | private String funcParam; 87 | @Value("${contract.contractAbi}") 88 | private String contractAbi; 89 | 90 | public void sendTransaction() { 91 | 92 | try { 93 | TransactionParam transParam = new TransactionParam(); 94 | transParam.setGroupId(groupId); 95 | transParam.setContractAddress(contractAddress); 96 | transParam.setUseAes(useAes); 97 | transParam.setUser(user); 98 | transParam.setContractName(contractName); 99 | transParam.setFuncName(funcName); 100 | transParam.setFuncParam(JSONArray.parseArray(funcParam)); 101 | transParam.setContractAbi(JSONArray.parseArray(contractAbi)); 102 | 103 | log.info("transaction param:{}", JSON.toJSONString(transParam)); 104 | Object rsp = rest.postForObject(url, transParam, Object.class); 105 | String rspStr = "null"; 106 | if (Objects.nonNull(rsp)) { 107 | rspStr = JSON.toJSONString(rsp); 108 | } 109 | log.info("transaction result:{}", rspStr); 110 | } catch (Exception ex) { 111 | log.error("fail sendTransaction", ex); 112 | } 113 | System.exit(1); 114 | } 115 | } 116 | ``` 117 | 118 | ## 5 运维管理 119 | 应用层发布后,持续发送交易,可在WeBASE管理平台查看数据概览,节点监控,查看交易解析,交易审计等管理功能。 120 | * 查看交易解析 121 | ![[交易解析]](./images/transHash.png) 122 | 123 | 124 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /README-en.md: -------------------------------------------------------------------------------- 1 | [中文](README.md)|English 2 | 3 | ![image](https://webasedoc.readthedocs.io/zh_CN/latest/_images/logo.jpg) 4 | 5 | # What's WeBASE? 6 | 7 | **WeBASE** (WeBank Blockchain Application Software Extension) is a set of general components building between blockchain application and FISCO-BCOS Nodes. Each module is designed around blockchain transaction, contract, key management, data and visual management. Developers can choose subsystems for deployment according to business needs. 8 | 9 | **WeBASE** shields the complexity of the bottom layer of the blockchain, reduces the threshold of developers, and greatly improves the development efficiency of the blockchain application. It includes subsystems such as node front, node management, web management platform, sign service, data export etc.. 10 | 11 | **WeBASE** standardizes the application and development of blockchain. After building the FISCO BCOS nodes, only five steps needed to develop and build the application of blockchain. For details of developing process, please refer to [Using WeBASE to develop blockchain application](https://github.com/WeBankFinTech/WeBASE-Doc/blob/master/docs/WeBASE/quick-start.md) 12 | 13 | **WeBASE One Click Installation** (including FISCO BCOS nodes + WeBASE-Front + WeBASE-Node-Manager + WeBASE-Web) refers to [WeBASE One-Click-Installation Documentation](https://webasedoc.readthedocs.io/zh_CN/latest/docs/WeBASE/install.html),**WeBASE**'s overall structure design and the detailed introduction of the functions and installation of each subsystem, please refer to [WeBASE Online Documentation](https://webasedoc.readthedocs.io/zh_CN/latest/index.html) 14 | 15 | ## Subsystem introduction 16 | * **Node Front service [WeBASE-Front](https://github.com/WeBankFinTech/WeBASE-Front)** 17 | It integrates fisco-bcos-java-sdk and provides restful interface. The client can interact with the node in the form of HTTP. The built-in memory database collects the health data of the node. Built in Web console to realize the visual operation of nodes and solidity IDE etc.. 18 | 19 | * **Node management service [WeBASE-Node-Manager](https://github.com/WeBankFinTech/WeBASE-Node-Manager)** 20 | Based on WeBASE-Front, handle all web requests from WeBASE-Web pages, manage the status of each node, manage all smart contracts on the chain, make statistics and Analysis on the data of the blockchain, audit abnormal transactions, private key management, etc. 21 | 22 | * **WeBASE management platform [WeBASE-Web](https://github.com/WeBankFinTech/WeBASE-Web)** 23 | Visual operation platform, based on which node information can be viewed and smart contracts can be developed. 24 | 25 | * **Transcation service [WeBASE-Transcation](https://github.com/WeBankFinTech/WeBASE-Transcation)** 26 | Receive transaction request, cache transaction to database and asynchronously chain up, which can greatly improve throughput and solve the TPS bottleneck problem of blockchain. 27 | 28 | * **Private key Hosting and cloud signature service [WeBASE-Sign](https://github.com/WeBankFinTech/WeBASE-Sign)** 29 | Hosting user private key, providing cloud signature. 30 | 31 | * **Data export code generation tool [WeBASE-Codegen-Monkey](https://github.com/WeBankFinTech/WeBASE-Codegen-Monkey)** 32 | The code generation tool can generate the core code of data export through configuration. 33 | 34 | * **Data export service [WeBASE-Collect-Bee](https://github.com/WeBankFinTech/WeBASE-Collect-Bee)** 35 | Export the basic data on the blockchain, such as the current block height, total transaction volume, etc. export the business data of the contract on the blockchain, including the event, constructor, contract address, execution function information, etc. through the configuration of the smart contract. 36 | 37 | * **Chain manage service [WeBASE-Chain-Manager](https://github.com/WeBankFinTech/WeBASE-Chain-Manager)** 38 | Manage multiple chains, support national secret chain, non-national secret chain. Provide group add, delete, check and change interface, so that users can easily establish their own application groups. 39 | 40 | * **Contract security check service [WeBASE-Solidity-Security](https://github.com/WeBankFinTech/WeBASE-Solidity-Security)** 41 | Inherit contract detection tool Slither, provide external detection interface. 42 | 43 | * **Data statistics service [WeBASE-Stat](https://github.com/WeBankFinTech/WeBASE-Stat)** 44 | Rely on WeBASE-Front,drag data on CPU, memory, IO, group size, group GAS, group network traffic and store into database. 45 | 46 | * **Data monitoring service [WeBASE-Data](https://github.com/WeBankFinTech/WeBASE-Data)** 47 | Rely on WeBASE-Front,export and parse blockchain data to provide a visual view of governance. You can check which chain, which user and which contract the transaction belongs to, and ensure that the data on the chain can be checked and managed. 48 | 49 | ## Contribution 50 | Please read our [contribution document](https://webasedoc.readthedocs.io/zh_CN/latest/docs/WeBASE/CONTRIBUTING.html) to learn how to contribute your code and submit your contribution. 51 | 52 | I hope that with your participation, WeBASE will get better and better! 53 | 54 | ## Community 55 | Contact us: webase@webank.com 56 | 57 | WeChat Community ID : WeBank_Blockchain 58 | -------------------------------------------------------------------------------- /deploy/deploy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | # encoding: utf-8 3 | 4 | import sys 5 | 6 | # check python version first 7 | # check before import in case of avoiding error of mysql lib not found in comm.check package 8 | if not sys.version_info.major == 3 and sys.version_info.minor >= 6: 9 | print("This script requires Python 3.6 or higher!") 10 | print("You are using Python {}.{}.".format(sys.version_info.major, sys.version_info.minor)) 11 | sys.exit(1) 12 | 13 | import comm.check as commCheck 14 | import comm.build as commBuild 15 | import comm.global_var as gl 16 | 17 | def do(): 18 | if len(sys.argv)==1: 19 | help() 20 | return 21 | param = sys.argv[1] 22 | if "installAll" == param: 23 | gl.set_install_all() 24 | commCheck.do() 25 | commBuild.do() 26 | elif "startAll" == param: 27 | commCheck.checkPort() 28 | commBuild.start() 29 | elif "stopAll" == param: 30 | commBuild.end() 31 | elif "installWeBASE" == param: 32 | gl.set_visual_deploy() 33 | commCheck.visual_do() 34 | commBuild.visual_do() 35 | elif "startWeBASE" == param: 36 | commCheck.visualCheckPort() 37 | commBuild.visualStart() 38 | elif "stopWeBASE" == param: 39 | commBuild.visualEnd() 40 | elif "installDockerAll" == param: 41 | commCheck.docker_do() 42 | commBuild.docker_do() 43 | elif "startDockerAll" == param: 44 | commCheck.checkPort() 45 | commBuild.dockerStartAll() 46 | elif "stopDockerAll" == param: 47 | commBuild.dockerEndAll() 48 | elif "pullDockerAll" == param: 49 | commBuild.dockerPull() 50 | elif "startDocker" == param: 51 | commCheck.checkPort() 52 | commBuild.dockerStart() 53 | elif "stopDocker" == param: 54 | commBuild.dockerEnd() 55 | elif "startNode" == param: 56 | commBuild.startNode() 57 | elif "stopNode" == param: 58 | commBuild.stopNode() 59 | elif "startWeb" == param: 60 | commBuild.startWeb() 61 | elif "stopWeb" == param: 62 | commBuild.stopWeb() 63 | elif "startManager" == param: 64 | commBuild.startManager() 65 | elif "stopManager" == param: 66 | commBuild.stopManager() 67 | elif "startFront" == param: 68 | commBuild.startFront() 69 | elif "stopFront" == param: 70 | commBuild.stopFront() 71 | elif "startSign" == param: 72 | commBuild.startSign() 73 | elif "stopSign" == param: 74 | commBuild.stopSign() 75 | elif "check"== param: 76 | commCheck.do() 77 | elif "help"== param: 78 | help() 79 | else: 80 | paramError() 81 | return 82 | 83 | def help(): 84 | helpMsg = ''' 85 | Usage: python deploy [Parameter] 86 | 87 | Parameter: 88 | check: check the environment [one-click mode] 89 | installAll: check the environment, deploy FISCO-BCOS and all service [one-click mode] 90 | startAll: check service port, start all service [one-click mode] 91 | stopAll: stop all service [one-click mode] 92 | installWeBASE: check the environment, deploy without FISCO-BCOS nodes and WeBASE-Front service [visual mode] 93 | startWeBASE: check service port, start all service deploy under visual deploy model [visual mode] 94 | stopWeBASE: stop all service deploy under visual deploy model [visual mode] 95 | startNode: start FISCO-BCOS nodes [one-click mode or docker mode] 96 | stopNode: stop FISCO-BCOS nodes [one-click mode or docker mode] 97 | startWeb: start WeBASE-Web service [one-click mode or visual mode] 98 | stopWeb: stop WeBASE-Web service [one-click mode or visual mode] 99 | startManager: start WeBASE-Node-Manager service [one-click mode or visual mode] 100 | stopManager: stop WeBASE-Node-Manager service [one-click mode or visual mode] 101 | startFront: start WeBASE-Front service [one-click mode] 102 | stopFront: stop WeBASE-Front service [one-click mode] 103 | startSign: start WeBASE-Sign service [one-click mode or visual mode] 104 | stopSign: stop WeBASE-Sign service [one-click mode or visual mode] 105 | installDockerAll check dependency, deploy FISCO-BCOS nodes and all service, start by docker 106 | startDockerAll check docker container, start FISCO-BCOS nodes and all service by docker 107 | stopDockerAll stop FISCO-BCOS nodes and all service in docker 108 | pullDockerAll pull FISCO-BCOS, WeBASE and mysql images from dockerhub 109 | startDocker check docker container, start all webase service by docker 110 | stopDocker stop all webase service in docker 111 | 112 | Attention: 113 | 1. Need to install python3.6, jdk, mysql, PyMySQL first 114 | 2. Need to ensure a smooth network 115 | 3. You need to install git,openssl,curl,wget,nginx,dos2unix; if it is not installed, the installation script will automatically install these components, but this may fail. 116 | ''' 117 | print (helpMsg) 118 | return 119 | 120 | def paramError(): 121 | print ("") 122 | print ("Param error! Please check.") 123 | help() 124 | return 125 | 126 | if __name__ == '__main__': 127 | do() 128 | pass 129 | -------------------------------------------------------------------------------- /deploy/docker/script/wait-for-it.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Use this script to test if a given TCP host/port are available 3 | 4 | WAITFORIT_cmdname=${0##*/} 5 | 6 | echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi } 7 | 8 | usage() 9 | { 10 | cat << USAGE >&2 11 | Usage: 12 | $WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args] 13 | -h HOST | --host=HOST Host or IP under test 14 | -p PORT | --port=PORT TCP port under test 15 | Alternatively, you specify the host and port as host:port 16 | -s | --strict Only execute subcommand if the test succeeds 17 | -q | --quiet Don't output any status messages 18 | -t TIMEOUT | --timeout=TIMEOUT 19 | Timeout in seconds, zero for no timeout 20 | -- COMMAND ARGS Execute command with args after the test finishes 21 | USAGE 22 | exit 1 23 | } 24 | 25 | wait_for() 26 | { 27 | if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then 28 | echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT" 29 | else 30 | echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout" 31 | fi 32 | WAITFORIT_start_ts=$(date +%s) 33 | while : 34 | do 35 | if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then 36 | nc -z $WAITFORIT_HOST $WAITFORIT_PORT 37 | WAITFORIT_result=$? 38 | else 39 | (echo -n > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1 40 | WAITFORIT_result=$? 41 | fi 42 | if [[ $WAITFORIT_result -eq 0 ]]; then 43 | WAITFORIT_end_ts=$(date +%s) 44 | echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds" 45 | break 46 | fi 47 | sleep 1 48 | done 49 | return $WAITFORIT_result 50 | } 51 | 52 | wait_for_wrapper() 53 | { 54 | # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692 55 | if [[ $WAITFORIT_QUIET -eq 1 ]]; then 56 | timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT & 57 | else 58 | timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT & 59 | fi 60 | WAITFORIT_PID=$! 61 | trap "kill -INT -$WAITFORIT_PID" INT 62 | wait $WAITFORIT_PID 63 | WAITFORIT_RESULT=$? 64 | if [[ $WAITFORIT_RESULT -ne 0 ]]; then 65 | echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT" 66 | fi 67 | return $WAITFORIT_RESULT 68 | } 69 | 70 | # process arguments 71 | while [[ $# -gt 0 ]] 72 | do 73 | case "$1" in 74 | *:* ) 75 | WAITFORIT_hostport=(${1//:/ }) 76 | WAITFORIT_HOST=${WAITFORIT_hostport[0]} 77 | WAITFORIT_PORT=${WAITFORIT_hostport[1]} 78 | shift 1 79 | ;; 80 | --child) 81 | WAITFORIT_CHILD=1 82 | shift 1 83 | ;; 84 | -q | --quiet) 85 | WAITFORIT_QUIET=1 86 | shift 1 87 | ;; 88 | -s | --strict) 89 | WAITFORIT_STRICT=1 90 | shift 1 91 | ;; 92 | -h) 93 | WAITFORIT_HOST="$2" 94 | if [[ $WAITFORIT_HOST == "" ]]; then break; fi 95 | shift 2 96 | ;; 97 | --host=*) 98 | WAITFORIT_HOST="${1#*=}" 99 | shift 1 100 | ;; 101 | -p) 102 | WAITFORIT_PORT="$2" 103 | if [[ $WAITFORIT_PORT == "" ]]; then break; fi 104 | shift 2 105 | ;; 106 | --port=*) 107 | WAITFORIT_PORT="${1#*=}" 108 | shift 1 109 | ;; 110 | -t) 111 | WAITFORIT_TIMEOUT="$2" 112 | if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi 113 | shift 2 114 | ;; 115 | --timeout=*) 116 | WAITFORIT_TIMEOUT="${1#*=}" 117 | shift 1 118 | ;; 119 | --) 120 | shift 121 | WAITFORIT_CLI=("$@") 122 | break 123 | ;; 124 | --help) 125 | usage 126 | ;; 127 | *) 128 | echoerr "Unknown argument: $1" 129 | usage 130 | ;; 131 | esac 132 | done 133 | 134 | if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then 135 | echoerr "Error: you need to provide a host and port to test." 136 | usage 137 | fi 138 | 139 | WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15} 140 | WAITFORIT_STRICT=${WAITFORIT_STRICT:-0} 141 | WAITFORIT_CHILD=${WAITFORIT_CHILD:-0} 142 | WAITFORIT_QUIET=${WAITFORIT_QUIET:-0} 143 | 144 | # Check to see if timeout is from busybox? 145 | WAITFORIT_TIMEOUT_PATH=$(type -p timeout) 146 | WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH) 147 | 148 | WAITFORIT_BUSYTIMEFLAG="" 149 | if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then 150 | WAITFORIT_ISBUSY=1 151 | # Check if busybox timeout uses -t flag 152 | # (recent Alpine versions don't support -t anymore) 153 | if timeout &>/dev/stdout | grep -q -e '-t '; then 154 | WAITFORIT_BUSYTIMEFLAG="-t" 155 | fi 156 | else 157 | WAITFORIT_ISBUSY=0 158 | fi 159 | 160 | if [[ $WAITFORIT_CHILD -gt 0 ]]; then 161 | wait_for 162 | WAITFORIT_RESULT=$? 163 | exit $WAITFORIT_RESULT 164 | else 165 | if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then 166 | wait_for_wrapper 167 | WAITFORIT_RESULT=$? 168 | else 169 | wait_for 170 | WAITFORIT_RESULT=$? 171 | fi 172 | fi 173 | 174 | if [[ $WAITFORIT_CLI != "" ]]; then 175 | if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then 176 | echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess" 177 | exit $WAITFORIT_RESULT 178 | fi 179 | exec "${WAITFORIT_CLI[@]}" 180 | else 181 | exit $WAITFORIT_RESULT 182 | fi -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /deploy/comm/utils.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # encoding: utf-8 3 | 4 | import os 5 | import sys 6 | import comm.global_var as gl 7 | 8 | try: 9 | import ConfigParser 10 | except: 11 | try: 12 | import configparser as ConfigParser 13 | except: 14 | from six.moves import configparser as ConfigParser 15 | if sys.version_info.major == 2: 16 | import commands 17 | else: 18 | import subprocess 19 | from . import log as deployLog 20 | import socket 21 | import fcntl 22 | import struct 23 | import telnetlib 24 | import platform 25 | import shutil 26 | import json 27 | from urllib import request 28 | from distutils.dir_util import copy_tree 29 | # support timeout 30 | import signal 31 | import subprocess 32 | 33 | log = deployLog.getLocalLogger() 34 | platformStr = platform.platform() 35 | unameStr = platform.uname()[1] 36 | versionStr = platform.uname()[3] 37 | 38 | def getIpAddress(ifname): 39 | s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 40 | return socket.inet_ntoa(fcntl.ioctl( 41 | s.fileno(), 42 | 0x8915, # SIOCGIFADDR 43 | struct.pack('256s', ifname[:15]) 44 | )[20:24]) 45 | 46 | def getLocalIp(): 47 | return getIpAddress("eth0") 48 | 49 | def net_if_used(ip,port): 50 | s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) 51 | s.settimeout(0.5) 52 | try: 53 | result=s.connect_ex((ip, int(port))) 54 | if result==0: 55 | print (" error! port {} has been used. please check.".format(port)) 56 | return True 57 | else: 58 | return False 59 | finally: 60 | s.close() 61 | 62 | def net_if_used_no_msg(ip,port): 63 | s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) 64 | s.settimeout(0.5) 65 | try: 66 | result=s.connect_ex((ip, int(port))) 67 | if result==0: 68 | return True 69 | else: 70 | return False 71 | finally: 72 | s.close() 73 | 74 | def isUbuntu(): 75 | return platformStr.lower().find("ubuntu") > -1 or unameStr.lower().find("ubuntu") > -1 or versionStr.lower().find("ubuntu") > -1 76 | 77 | def isCentos(): 78 | # support redhat 79 | return platformStr.lower().find("centos") > -1 or unameStr.lower().find("centos") > -1 or unameStr.lower().find("redhat") > -1 or versionStr.lower().find("centos") > -1 80 | 81 | def isSuse(): 82 | return platformStr.lower().find("suse") > -1 or unameStr.lower().find("suse") > -1 or versionStr.lower().find("suse") > -1 83 | 84 | def getBaseDir(): 85 | cwd = os.getcwd() 86 | log.info(" os.getcwd() is {}".format(cwd)) 87 | path = os.path.abspath(os.path.join(os.getcwd(), "..")) 88 | return path 89 | 90 | def getCurrentBaseDir(): 91 | cwd = os.getcwd() 92 | log.info(" os.getcwd() is {}".format(cwd)) 93 | path = os.path.abspath(os.path.join(os.getcwd(), ".")) 94 | return path 95 | 96 | def copytree(src, dst): 97 | copy_tree(src,dst) 98 | return 99 | 100 | def doCmd(cmd): 101 | log.info(" execute cmd start ,cmd : {}".format(cmd)) 102 | result = dict() 103 | if sys.version_info.major == 2: 104 | (status, output) = commands.getstatusoutput(cmd) 105 | else: 106 | (status, output) = subprocess.getstatusoutput(cmd) 107 | result["status"] = status 108 | result["output"] = output 109 | log.info(" execute cmd end ,cmd : {},status :{} , output: {}".format(cmd,status,output)) 110 | if (0 != status): 111 | raise Exception("execute cmd error ,cmd : {}, status is {} ,output is {}".format(cmd,status, output)) 112 | return result 113 | 114 | def doCmdIgnoreException(cmd): 115 | log.info(" execute cmd start ,cmd : {}".format(cmd)) 116 | result = dict() 117 | if sys.version_info.major == 2: 118 | (status, output) = commands.getstatusoutput(cmd) 119 | else: 120 | (status, output) = subprocess.getstatusoutput(cmd) 121 | result["status"] = status 122 | result["output"] = output 123 | log.info(" execute cmd end ,cmd : {},status :{} , output: {}".format(cmd, status, output)) 124 | return result 125 | 126 | 127 | def doCmdTimeout(cmd_string, timeout=20): 128 | log.info(" execute cmd start, cmd: {}, timeout: {}".format(cmd_string, timeout)) 129 | p = subprocess.Popen(cmd_string, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=True, close_fds=True, start_new_session=True) 130 | format = 'utf-8' 131 | try: 132 | (msg, errs) = p.communicate(timeout=timeout) 133 | ret_code = p.poll() 134 | if ret_code: 135 | status = 1 136 | output = "[Error]Called Error : " + str(msg.decode(format)) 137 | else: 138 | status = 0 139 | output = str(msg.decode(format)) 140 | except subprocess.TimeoutExpired: 141 | # 注意:不能只使用p.kill和p.terminate,无法杀干净所有的子进程,需要使用os.killpg 142 | p.kill() 143 | p.terminate() 144 | os.killpg(p.pid, signal.SIGTERM) 145 | # 注意:如果开启下面这两行的话,会等到执行完成才报超时错误,但是可以输出执行结果 146 | # (outs, errs) = p.communicate() 147 | # print(outs.decode('utf-8')) 148 | status = 0 149 | log.info("[ERROR]Timeout Error : Command '" + cmd_string + "' timed out after " + str(timeout) + " seconds") 150 | output = "timeout" 151 | except Exception as e: 152 | status = 1 153 | output = "[ERROR]Unknown Error : " + str(e) 154 | 155 | result = dict() 156 | result["status"] = status 157 | result["output"] = output 158 | log.info(" execute cmd end ,cmd : {},status :{} , output: {}".format(cmd_string, status, output)) 159 | if (0 != status): 160 | raise Exception("execute cmd error ,cmd : {}, status is {} ,output is {}".format(cmd_string, status, output)) 161 | return result 162 | 163 | 164 | 165 | def getCommProperties(paramsKey): 166 | current_dir = getCurrentBaseDir() 167 | cf = ConfigParser.ConfigParser() 168 | propertiesDir =current_dir + '/' + gl.get_file() 169 | cf.read(propertiesDir) 170 | log.info(" commProperties is {} ".format(propertiesDir)) 171 | cf.sections() 172 | value = cf.get('common', paramsKey,fallback=None) 173 | return value 174 | 175 | def replaceConf(fileName,oldStr,newStr): 176 | if not os.path.isfile(fileName): 177 | print ("{} is not a file ".format(fileName)) 178 | return 179 | oldData ="" 180 | with open(fileName, "r") as f: 181 | for line in f: 182 | if oldStr in line: 183 | line = line.replace(oldStr, newStr) 184 | oldData += line 185 | with open(fileName, "w") as f: 186 | f.write(oldData) 187 | return 188 | 189 | def replaceConfDir(filePath,oldStr,newStr): 190 | if not os.path.isdir(filePath): 191 | print ("{} is not a dir ".format(filePath)) 192 | return 193 | for root, dirs, files in os.walk(filePath): 194 | for file in files: 195 | replaceConf(os.path.join(root,file),oldStr,newStr) 196 | return 197 | 198 | def copyFiles(sourceDir, targetDir): 199 | log.info(" copyFiles sourceDir: {} ".format(sourceDir)) 200 | for f in os.listdir(sourceDir): 201 | sourceF = os.path.join(sourceDir, f) 202 | targetF = os.path.join(targetDir, f) 203 | if os.path.isfile(sourceF): 204 | # check dir 205 | if not os.path.exists(targetDir): 206 | os.makedirs(targetDir) 207 | # copy file 208 | shutil.copy(sourceF,targetF) 209 | # check sub folder 210 | if os.path.isdir(sourceF): 211 | copyFiles(sourceF, targetF) 212 | 213 | def do_telnet(host,port): 214 | try: 215 | tn = telnetlib.Telnet(host, port, timeout=5) 216 | tn.close() 217 | except: 218 | return False 219 | return True 220 | 221 | # required docker command not need sudo 222 | def pullDockerImage(gitComm,fileName,repo_name): 223 | if not os.path.exists("{}/{}".format(getCurrentBaseDir(),fileName)): 224 | print (gitComm) 225 | # get tar file from this gitComm command 226 | os.system(gitComm) 227 | else: 228 | info = "n" 229 | if sys.version_info.major == 2: 230 | info = raw_input("{} already exists. Do you want to re-download and overwrite it?[y/n]:".format(fileName)) 231 | else: 232 | info = input("{} already exists. Do you want to re-download and overwrite it?[y/n]:".format(fileName)) 233 | if info == "y" or info == "Y": 234 | doCmd("rm -rf {}".format(fileName)) 235 | print (gitComm) 236 | # get tar file from this gitComm command 237 | os.system(gitComm) 238 | 239 | doCmd("docker load -i {}".format(fileName)) 240 | 241 | result = doCmd("docker image ls {} | wc -l".format(repo_name)) 242 | print ("Uzip image result {} ".format(result)) 243 | if int(result["output"]) <= 1 : 244 | print ("Unzip docker image from file {} failed!".format(fileName)) 245 | sys.exit(0) 246 | 247 | # repo_name ex: fiscoorg/fiscobcos, webasepro/webase-front:v1.5.3 248 | def checkDockerImageExist(repo_name): 249 | result = doCmd("docker image ls {} | wc -l".format(repo_name)) 250 | log.info("local image result {} ".format(result)) 251 | if int(result["output"]) <= 1 : 252 | print ("Local docker image {} not exist!".format(repo_name)) 253 | return False 254 | else: 255 | return True 256 | 257 | def pullSourceExtract(gitComm,fileName): 258 | if not os.path.exists("{}/{}.zip".format(getCurrentBaseDir(),fileName)): 259 | print (gitComm) 260 | os.system(gitComm) 261 | else: 262 | info = "n" 263 | if sys.version_info.major == 2: 264 | info = raw_input("{}.zip already exists. Do you want to re-download and overwrite it?[y/n]:".format(fileName)) 265 | else: 266 | info = input("{}.zip already exists. Do you want to re-download and overwrite it?[y/n]:".format(fileName)) 267 | if info == "y" or info == "Y": 268 | doCmd("rm -rf {}.zip".format(fileName)) 269 | doCmd("rm -rf {}".format(fileName)) 270 | print (gitComm) 271 | os.system(gitComm) 272 | if not os.path.exists("{}/{}".format(getCurrentBaseDir(),fileName)): 273 | doCmd("unzip -o {}.zip".format(fileName)) 274 | if not os.path.exists("{}/{}".format(getCurrentBaseDir(),fileName)): 275 | print ("{}.zip extract failed!".format(fileName)) 276 | sys.exit(0) 277 | else: 278 | info1 = "n" 279 | if sys.version_info.major == 2: 280 | info1 = raw_input("directory '{}' is not empty. Do you want delete and re-unzip {}.zip?[y/n]:".format(fileName,fileName)) 281 | else: 282 | info1 = input("directory '{}' is not empty. Do you want delete and re-unzip {}.zip?[y/n]:".format(fileName,fileName)) 283 | if info1 == "y" or info1 == "Y": 284 | doCmd("rm -rf {}".format(fileName)) 285 | doCmd("unzip -o {}.zip".format(fileName)) 286 | if not os.path.exists("{}/{}".format(getCurrentBaseDir(),fileName)): 287 | print ("{}.zip extract failed!".format(fileName)) 288 | sys.exit(0) 289 | 290 | def checkFileName(dir,fileName): 291 | Files=os.listdir(dir) 292 | for k in range(len(Files)): 293 | Files[k]=os.path.splitext(Files[k])[0] 294 | fileName = fileName + ".mv" 295 | if fileName in Files: 296 | return True 297 | else: 298 | return False 299 | 300 | def checkPathExists(pathName): 301 | if os.path.exists(pathName): 302 | return True 303 | else: 304 | print ("======={} is not exists.=======".format(pathName)) 305 | return False 306 | 307 | def get_str_btw(s, f, b): 308 | par = s.partition(f) 309 | return (par[2].partition(b))[0][:] 310 | 311 | def rest_get(url): 312 | log.info("rest_get url: {}".format(url)) 313 | try: 314 | res = request.urlopen(url) 315 | log.info("rest_get success: {}".format(res.read())) 316 | return res 317 | except: 318 | log.error("rest_get fail: {}".format(sys.exc_info())) 319 | return '' 320 | 321 | def rest_post(url,data): 322 | log.info("rest_post url: {}, data:{}".format(url, data)) 323 | raw_params = json.dumps(data) 324 | params = bytes(raw_params, 'utf8') 325 | headers = {'Accept-Charset': 'utf-8', 'Content-Type': 'application/json'} 326 | try: 327 | req = request.Request(url=url, data=params, headers=headers, method='POST') 328 | res = request.urlopen(req).read() 329 | res_dict = json.loads(res) 330 | log.info("rest_post success: {}".format(res_dict)) 331 | return res_dict 332 | except: 333 | log.error("rest_post fail: {}".format(sys.exc_info())) 334 | return '' 335 | 336 | def rest_getClientVersion(chainRpcUrl): 337 | data={"jsonrpc":"2.0","method":"getClientVersion","params":[],"id":1} 338 | resJson = rest_post(chainRpcUrl,data) 339 | result = resJson['result'] 340 | log.info("rest_getClientVersion result: {}".format(result)) 341 | return result 342 | 343 | if __name__ == '__main__': 344 | print(getIpAddress("eth0")) 345 | pass 346 | -------------------------------------------------------------------------------- /deploy/upgrade/upgrade-v1.5.0.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | ################################################ 6 | # 下载新的zip包,已存在则移动到{old_version}的目录中 7 | 8 | # 解压新的zip包到webase-front.zip => webase-front-v1.5.0 9 | 10 | # 停止原有的,python3 deploy.py stopAll 11 | 12 | # webase-web 直接复制全部 13 | # 复制已有front的conf/*.yml, *.key, *.crt, *.so,覆盖当前的文件 14 | # 复制已有sign的conf/*.yml 15 | # 复制已有node-mgr已有的conf的*.yml,conf/log目录 16 | # 更新旧的yml,更新版本号 17 | 18 | # mv操作,备份已有的,移动到{old_version}的目录中 19 | 20 | # 备份node-mgr数据库到webase-node-mgr-v1.5.0/backup.sql 21 | # 从common.properties中获取两个数据库密码 22 | 23 | # 到node-mgr中检测script/upgrade目录,有匹配v143开头的,v150的结尾的,有则执行 mysql -e "source $sql_file" 24 | # 到sign...同上(当前版本不增加) 25 | 26 | # 启动新的,执行python3 deploy.py startAll 27 | ################################################ 28 | 29 | 30 | ## zip name 31 | zip_list=("webase-sign" "webase-front" "webase-web" "webase-web-mobile" "webase-node-mgr") 32 | 33 | function main() { 34 | 35 | # pull 36 | if [[ ! -f "deploy.py" ]];then 37 | LOG_WARN "deploy.py not in this directory!" 38 | exit 1 39 | fi 40 | 41 | LOG_INFO "start pull zip of new webase..." 42 | 43 | # pull 44 | if [[ ! -f "${old_version}" ]];then 45 | # backup old zip 46 | mkdir "${old_version}" 47 | fi 48 | 49 | for webase_name in ${zip_list[@]}; 50 | do 51 | echo "now [${webase_name}] pull new version zip" 52 | pull_zip "$webase_name" 53 | done 54 | 55 | # stop 56 | LOG_INFO "==========now webase stop all==========" 57 | python3 deploy.py stopAll 58 | # todo 判断是否已停止 59 | 60 | # change new webase's config file, backup old webase and data 61 | for webase_name in ${zip_list[@]}; 62 | do 63 | echo "now [${webase_name}] copy old version config & backup old files & update new data" 64 | copy_webase "$webase_name" 65 | done 66 | 67 | # update version 68 | LOG_INFO "==========now update webase version in yml==========" 69 | update_webase_yml_version 70 | 71 | # restart 72 | LOG_INFO "==========now webase start all==========" 73 | python3 deploy.py startAll 74 | } 75 | 76 | 77 | function pull_zip() { 78 | local webase_name="$1" 79 | local zip="${webase_name}.zip" 80 | # delete old zip 81 | if [[ -f "$zip" ]];then 82 | LOG_INFO "move old version zip $zip to directory of [$PWD/${old_version}]" 83 | if [[ -f "${old_version}/${zip}" ]];then 84 | LOG_WARN "old version zip of ${zip} already in directory ./${old_version}" 85 | rm -rf "${PWD}/${zip}" 86 | else 87 | mv "$zip" "${old_version}/" 88 | fi 89 | fi 90 | LOG_INFO "pull zip of $zip" 91 | curl -#LO "${cdn_url_pre}/${new_version}/${zip}" 92 | if [[ "$(ls -al . | grep ${zip} | awk '{print $5}')" -lt "500000" ]];then # 1m=1048576b 93 | LOG_WARN "download ${zip} failed, exit!" 94 | exit 1 95 | fi 96 | # webase-web.zip => webase-web-v1.5.0/webase-web 97 | #注:unzip后变成了webase-web-v1.5.0/webase-web 98 | if [[ -d "${webase_name}-${new_version}" ]];then 99 | LOG_WARN "unzip destination dir already exist, now rm and re-unzip" 100 | rm -rf "${PWD}/${webase_name}-${new_version}" 101 | fi 102 | unzip -o "$zip" -d "${webase_name}-${new_version}" > /dev/null 103 | } 104 | 105 | ## copy config and cert to new unzip dir 106 | # 先复制到新目录,然后再备份旧的文件夹 107 | function copy_webase() { 108 | local webase_name="$1" 109 | case ${webase_name} in 110 | "webase-web") 111 | backup "webase-web" 112 | backup "webase-web-mobile" 113 | update_nginx_conf 114 | ;; 115 | "webase-front") 116 | copy_front 117 | backup "webase-front" 118 | ##update_front_yml 119 | ;; 120 | "webase-node-mgr") 121 | copy_node_mgr 122 | backup "webase-node-mgr" 123 | update_node_mgr_yml 124 | upgrade_mgr_sql 125 | ;; 126 | "webase-sign") 127 | copy_sign 128 | backup "webase-sign" 129 | ##update_sign_yml 130 | ##upgrade_sign_sql 131 | ;; 132 | \?) 133 | LOG_WARN "not support update this service [${webase_name}]" 134 | ;; 135 | esac 136 | 137 | } 138 | 139 | function copy_front() { 140 | LOG_INFO "copy webase-front config files" 141 | if [[ -d "${PWD}/webase-front" && -d "${PWD}/webase-front-${new_version}" ]]; then 142 | cp -f "${PWD}/webase-front/conf/application.yml" "${PWD}/webase-front-${new_version}/webase-front/conf/" 143 | cp -f "${PWD}/webase-front/conf/log4j2.xml" "${PWD}/webase-front-${new_version}/webase-front/conf/" 144 | cp -f "${PWD}/webase-front/conf/ca.crt" "${PWD}/webase-front-${new_version}/webase-front/conf/" 145 | cp -f "${PWD}/webase-front/conf/sdk.crt" "${PWD}/webase-front-${new_version}/webase-front/conf/" 146 | cp -f "${PWD}/webase-front/conf/sdk.key" "${PWD}/webase-front-${new_version}/webase-front/conf/" 147 | cp -rf "${PWD}/webase-front/conf/gm" "${PWD}/webase-front-${new_version}/webase-front/conf/" 148 | cp -f "${PWD}/webase-front/conf/libsigar-aarch64-linux.so" "${PWD}/webase-front-${new_version}/webase-front/conf/" 149 | cp -f "${PWD}/webase-front/conf/libsigar-amd64-linux.so" "${PWD}/webase-front-${new_version}/webase-front/conf/" 150 | cp -f "${PWD}/webase-front/conf/libsigar-universal64-macosx.dylib" "${PWD}/webase-front-${new_version}/webase-front/conf/" 151 | cp -f "${PWD}/webase-front/conf/libsigar-x86-linux.so" "${PWD}/webase-front-${new_version}/webase-front/conf/" 152 | if [[ -f "${PWD}/webase-front/conf/node.key" ]]; then 153 | cp -f "${PWD}/webase-front/conf/node.crt" "${PWD}/webase-front-${new_version}/webase-front/conf/" 154 | cp -f "${PWD}/webase-front/conf/node.key" "${PWD}/webase-front-${new_version}/webase-front/conf/" 155 | fi 156 | else 157 | LOG_WARN "copy directory of ${PWD}/webase-front not exist!" 158 | exit 1 159 | fi 160 | } 161 | 162 | function copy_node_mgr() { 163 | LOG_INFO "copy webase-node-mgr config files" 164 | if [[ -d "${PWD}/webase-node-mgr" && -d "${PWD}/webase-node-mgr-${new_version}" ]]; then 165 | cp -f "${PWD}/webase-node-mgr/conf/application.yml" "${PWD}/webase-node-mgr-${new_version}/webase-node-mgr/conf/" 166 | #cp -r "${PWD}/webase-node-mgr/conf/log" "${PWD}/webase-node-mgr-${new_version}/webase-node-mgr/conf/" 167 | else 168 | LOG_WARN "copy directory of webase-node-mgr not exist!" 169 | exit 1 170 | fi 171 | } 172 | 173 | function copy_sign() { 174 | LOG_INFO "copy sign config files" 175 | if [[ -d "${PWD}/webase-sign" && -d "${PWD}/webase-sign-${new_version}/webase-sign" ]]; then 176 | cp -f "${PWD}/webase-sign/conf/application.yml" "${PWD}/webase-sign-${new_version}/webase-sign/conf/" 177 | else 178 | LOG_WARN "config directory of webase-sign not exist!" 179 | exit 1 180 | fi 181 | } 182 | 183 | 184 | 185 | # backup webase package and use new version package 186 | function backup() { 187 | local webase_name="$1" 188 | LOG_INFO "now backup old data of ${webase_name}" 189 | if [[ -d "${PWD}/${webase_name}" ]]; then 190 | mv "${PWD}/${webase_name}" "${PWD}/${old_version}/" 191 | else 192 | # skip v1.5.0 web-mobile upgrade, cuz added in v1.5.0 193 | if [[ "${new_version}" == "v1.5.0" && "${webase_name}" == "webase-web-mobile" ]]; then 194 | LOG_INFO "jump over webase-web-mobile backup: ${webase_name}" 195 | else 196 | LOG_WARN "backup directory of ${PWD}/${webase_name} not exist!" 197 | exit 1 198 | fi 199 | fi 200 | mv "${PWD}/${webase_name}-${new_version}/${webase_name}" "${PWD}/${webase_name}" 201 | } 202 | 203 | 204 | config_properties="${PWD}/common.properties" 205 | # 定义一个函数从properties文件读取key 206 | function prop() { 207 | local key="${1}" 208 | if [[ -f "$config_properties" ]]; then 209 | dos2unix $config_properties 210 | grep -P "^\s*[^#]?${key}=.*$" $config_properties | cut -d'=' -f2 211 | else 212 | LOG_WARN "webase $config_properties file not found!" 213 | exit 1 214 | fi 215 | } 216 | 217 | 218 | # upgrade table of node-mgr after backup webase-node-mgr dir 219 | function upgrade_mgr_sql() { 220 | # check whether old=>new .sql shell in new webase-node-mgr/script 221 | mgr_script_name="${PWD}/webase-node-mgr/script/upgrade/v${old_version_num}_v${new_version_num}.sql" 222 | if [[ -f "${mgr_script_name}" ]];then 223 | # get sql config of mgr from common.properties 224 | local ip=$(prop "mysql.ip") 225 | local port=$(prop "mysql.port") 226 | local user=$(prop "mysql.user") 227 | local password=$(prop "mysql.password") 228 | local database=$(prop "mysql.database") 229 | LOG_INFO "get propertise user: ${user} host: ${ip} port: ${port} db: ${database} " 230 | local backup_mgr_dir="webase-node-mgr-${old_version}/backup_node_mgr_${old_version}.sql" 231 | LOG_INFO "now backup the whole database of node-mgr in $backup_mgr_dir" 232 | mysqldump --user=${user} --password=${password} --host=${ip} --port=${port} ${database} > ${backup_mgr_dir} 233 | # exec .sql by mysql -e 234 | LOG_INFO "now upgrade database of node-mgr with script $mgr_script_name" 235 | mysql --user=$user --password=$password --host=$ip --port=$port --database=$database --default-character-set=utf8 -e "source ${mgr_script_name}" 236 | else 237 | LOG_WARN "node-mgr upgrade sql file of ${mgr_script_name} not exist!" 238 | exit 1 239 | fi 240 | } 241 | 242 | 243 | # update old yml 244 | # 根据版本号执行其中一段 245 | # 空格需要转义 246 | function update_node_mgr_yml() { 247 | mgr_yml="${PWD}/webase-node-mgr/conf/application.yml" 248 | LOG_INFO "now update yml value of node-mgr in $mgr_yml" 249 | if [[ ! -f $mgr_yml ]]; then 250 | LOG_WARN "yml of node-mgr in $mgr_yml not exist!" 251 | exit 1 252 | fi 253 | if [[ "${new_version}x" == "v1.5.0x" ]]; then 254 | LOG_INFO "update update_node_mgr_yml of version ${new_version}" 255 | # v1.5.0 key config to check if already add 256 | if [[ `grep -c "appStatusCheckCycle" ${mgr_yml}` -eq '0' ]]; then 257 | # 将constant:开头替换为 258 | local old_app_config="constant:" 259 | local new_app_config="constant:\n\ \ deployedModifyEnable:\ true\n\ \ appRequestTimeOut:\ 300000\n\ \ appStatusCheckCycle:\ 3000\n\ \ statBlockRetainMax:\ 100000\n\ \ statBlockFixedDelay: 5000\n\ \ statBlockPageSize:\ 10\n\ \ enableExternalFromBlock:\ true\n" 260 | sed -i "/${old_app_config}/c${new_app_config}" ${mgr_yml} 261 | fi 262 | if [[ `grep -c "\/api\/*" ${mgr_yml}` -eq '0' ]]; then 263 | # 需要空格开头 264 | local old_url_config="permitUrlArray:\ \/account\/login" 265 | local new_url_config="\ \ permitUrlArray:\ \/account\/login,\/account\/pictureCheckCode,\/login,\/user\/privateKey\/**,\/config\/encrypt,\/config\/version,\/front\/refresh,\/api\/*" 266 | sed -i "/${old_url_config}/c${new_url_config}" ${mgr_yml} 267 | fi 268 | fi 269 | } 270 | 271 | # copy webase-web and webase-web-mobile 272 | function update_nginx_conf() { 273 | LOG_INFO "now update webase-web nginx file in ${PWD}/comm/nginx.conf" 274 | if [[ ! -f "${PWD}/comm/nginx.conf" ]]; then 275 | LOG_WARN "nginx config file not exist, cannot auto update, now jump over!" 276 | #exit 1 277 | fi 278 | local zip="webase-deploy.zip" 279 | curl -#LO "${cdn_url_pre}/${new_version}/${zip}" 280 | if [[ "$(ls -al . | grep ${zip} | awk '{print $5}')" -lt "10000" ]];then 281 | LOG_WARN "update_nginx_conf pull newer webase-deploy.zip failed, exit now" 282 | #exit 1 283 | fi 284 | unzip -o "$zip" -d "temp-deploy" > /dev/null 285 | # backup nginx conf in {old_version} 286 | mv "${PWD}/comm/nginx.conf" "${PWD}/${old_version}/" 287 | # copy new one into ./comm 288 | cp -f "${PWD}/temp-deploy/webase-deploy/comm/nginx.conf" "${PWD}/comm/" 289 | # sed new conf file 290 | web_port=$(prop "web.port") 291 | mgr_port=$(prop "mgr.port") 292 | local pid_file="${PWD}/nginx-webase-web.pid" 293 | local web_dir="${PWD}/webase-web" 294 | local web_log_dir="${web_dir}/log" 295 | local h5_web_dir="${PWD}/webase-web-mobile" 296 | # create log dir 297 | if [[ ! -d "${PWD}/${web_log_dir}" ]]; then 298 | mkdir -p "$web_log_dir" 299 | fi 300 | 301 | sed -i "s/5000/${web_port}/g" "${PWD}/comm/nginx.conf" 302 | sed -i "s/5001/${mgr_port}/g" "${PWD}/comm/nginx.conf" 303 | sed -i "s:log_path:${web_log_dir}:g" "${PWD}/comm/nginx.conf" 304 | sed -i "s:pid_file:${pid_file}:g" "${PWD}/comm/nginx.conf" 305 | # set web_page_url(root & static) globally 306 | sed -i "s:web_page_url:${web_dir}:g" "${PWD}/comm/nginx.conf" 307 | # set mobile phone phone_page_url globally 308 | sed -i "s:phone_page_url:${h5_web_dir}:g" "${PWD}/comm/nginx.conf" 309 | # remove temp dir 310 | rm -rf "${PWD}/temp-deploy" 311 | } 312 | 313 | 314 | ## sed all yml's version 315 | function update_webase_yml_version() { 316 | LOG_INFO "start update version of new webase..." 317 | for webase_name in ${zip_list[@]}; 318 | do 319 | local yml_path="${PWD}/${webase_name}/conf/application.yml" 320 | if [[ -f $yml_path ]]; then 321 | # check new version exist 322 | if [[ `grep -c "${new_version}" ${yml_path}` -eq '0' ]]; then 323 | local old_app_config="version:" 324 | local new_app_config="version:\ ${new_version}\n" 325 | sed -i "/${old_app_config}/c${new_app_config}" ${yml_path} 326 | fi 327 | else 328 | echo "jump over webase-web(or mobile)" 329 | fi 330 | done 331 | } 332 | 333 | 334 | exit_with_tips() 335 | { 336 | local content=${1} 337 | echo -e "\033[31m[ERROR] ${content}\033[0m" 338 | echo "use webase subsystem files in ${PWD}/${old_version} to recover " 339 | exit 1 340 | } 341 | 342 | # checkDependencies 343 | # get_version_num 344 | main && LOG_INFO "upgrade script finished from ${old_version} to ${new_version}" 345 | echo "end of script" 346 | exit ${SUCCESS} 347 | -------------------------------------------------------------------------------- /deploy/upgrade/upgrade-v1.5.1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | ################################################ 6 | # 下载新的zip包,已存在则移动到{old_version}的目录中 7 | 8 | # 解压新的zip包到webase-front.zip => webase-front-v1.5.0 9 | 10 | # 停止原有的,python3 deploy.py stopAll 11 | 12 | # webase-web 直接复制全部 13 | # 复制已有front的conf/*.yml, *.key, *.crt, *.so,覆盖当前的文件 14 | # 复制已有sign的conf/*.yml 15 | # 复制已有node-mgr已有的conf的*.yml,conf/log目录 16 | # 更新旧的yml,更新版本号 17 | 18 | # mv操作,备份已有的,移动到{old_version}的目录中 19 | 20 | # 备份node-mgr数据库到webase-node-mgr-v1.5.0/backup.sql 21 | # 从common.properties中获取两个数据库密码 22 | 23 | # 到node-mgr中检测script/upgrade目录,有匹配v143开头的,v150的结尾的,有则执行 mysql -e "source $sql_file" 24 | # 到sign...同上(当前版本不增加) 25 | 26 | # 启动新的,执行python3 deploy.py startAll 27 | ################################################ 28 | 29 | 30 | ## zip name 31 | zip_list=("webase-front" "webase-web" "webase-node-mgr") 32 | 33 | function main() { 34 | 35 | # pull 36 | if [[ ! -f "deploy.py" ]];then 37 | LOG_WARN "deploy.py not in this directory!" 38 | exit 1 39 | fi 40 | 41 | LOG_INFO "start pull zip of new webase..." 42 | 43 | # pull 44 | if [[ ! -f "${old_version}" ]];then 45 | # backup old zip 46 | mkdir "${old_version}" 47 | fi 48 | 49 | for webase_name in ${zip_list[@]}; 50 | do 51 | echo "now [${webase_name}] pull new version zip" 52 | pull_zip "$webase_name" 53 | done 54 | 55 | # stop 56 | LOG_INFO "==========now webase stop all==========" 57 | python3 deploy.py stopAll 58 | # todo 判断是否已停止 59 | 60 | # change new webase's config file, backup old webase and data 61 | for webase_name in ${zip_list[@]}; 62 | do 63 | echo "now [${webase_name}] copy old version config & backup old files & update new data" 64 | copy_webase "$webase_name" 65 | done 66 | 67 | # update version 68 | LOG_INFO "==========now update webase version in yml==========" 69 | update_webase_yml_version 70 | 71 | # restart 72 | LOG_INFO "==========now webase start all==========" 73 | python3 deploy.py startAll 74 | } 75 | 76 | 77 | function pull_zip() { 78 | local webase_name="$1" 79 | local zip="${webase_name}.zip" 80 | # delete old zip 81 | if [[ -f "$zip" ]];then 82 | LOG_INFO "move old version zip $zip to directory of [$PWD/${old_version}]" 83 | if [[ -f "${old_version}/${zip}" ]];then 84 | LOG_WARN "old version zip of ${zip} already in directory ./${old_version}" 85 | rm -rf "${PWD}/${zip}" 86 | else 87 | mv "$zip" "${old_version}/" 88 | fi 89 | fi 90 | LOG_INFO "pull zip of $zip" 91 | curl -#LO "${cdn_url_pre}/${new_version}/${zip}" 92 | if [[ "$(ls -al . | grep ${zip} | awk '{print $5}')" -lt "500000" ]];then # 1m=1048576b 93 | LOG_WARN "download ${zip} failed, exit!" 94 | exit 1 95 | fi 96 | # webase-web.zip => webase-web-v1.5.0/webase-web 97 | #注:unzip后变成了webase-web-v1.5.0/webase-web 98 | if [[ -d "${webase_name}-${new_version}" ]];then 99 | LOG_WARN "unzip destination dir already exist, now rm and re-unzip" 100 | rm -rf "${PWD}/${webase_name}-${new_version}" 101 | fi 102 | unzip -o "$zip" -d "${webase_name}-${new_version}" > /dev/null 103 | } 104 | 105 | ## copy config and cert to new unzip dir 106 | # 先复制到新目录,然后再备份旧的文件夹 107 | function copy_webase() { 108 | local webase_name="$1" 109 | case ${webase_name} in 110 | "webase-web") 111 | backup "webase-web" 112 | backup "webase-web-mobile" 113 | update_nginx_conf 114 | ;; 115 | "webase-front") 116 | copy_front 117 | backup "webase-front" 118 | ##update_front_yml 119 | ;; 120 | "webase-node-mgr") 121 | copy_node_mgr 122 | backup "webase-node-mgr" 123 | update_node_mgr_yml 124 | upgrade_mgr_sql 125 | ;; 126 | "webase-sign") 127 | copy_sign 128 | backup "webase-sign" 129 | ##update_sign_yml 130 | ##upgrade_sign_sql 131 | ;; 132 | \?) 133 | LOG_WARN "not support update this service [${webase_name}]" 134 | ;; 135 | esac 136 | 137 | } 138 | 139 | function copy_front() { 140 | LOG_INFO "copy webase-front config files" 141 | if [[ -d "${PWD}/webase-front" && -d "${PWD}/webase-front-${new_version}" ]]; then 142 | cp -f "${PWD}/webase-front/conf/application.yml" "${PWD}/webase-front-${new_version}/webase-front/conf/" 143 | cp -f "${PWD}/webase-front/conf/log4j2.xml" "${PWD}/webase-front-${new_version}/webase-front/conf/" 144 | cp -f "${PWD}/webase-front/conf/ca.crt" "${PWD}/webase-front-${new_version}/webase-front/conf/" 145 | cp -f "${PWD}/webase-front/conf/sdk.crt" "${PWD}/webase-front-${new_version}/webase-front/conf/" 146 | cp -f "${PWD}/webase-front/conf/sdk.key" "${PWD}/webase-front-${new_version}/webase-front/conf/" 147 | cp -rf "${PWD}/webase-front/conf/gm" "${PWD}/webase-front-${new_version}/webase-front/conf/" 148 | cp -f "${PWD}/webase-front/conf/libsigar-aarch64-linux.so" "${PWD}/webase-front-${new_version}/webase-front/conf/" 149 | cp -f "${PWD}/webase-front/conf/libsigar-amd64-linux.so" "${PWD}/webase-front-${new_version}/webase-front/conf/" 150 | cp -f "${PWD}/webase-front/conf/libsigar-universal64-macosx.dylib" "${PWD}/webase-front-${new_version}/webase-front/conf/" 151 | cp -f "${PWD}/webase-front/conf/libsigar-x86-linux.so" "${PWD}/webase-front-${new_version}/webase-front/conf/" 152 | if [[ -f "${PWD}/webase-front/conf/node.key" ]]; then 153 | cp -f "${PWD}/webase-front/conf/node.crt" "${PWD}/webase-front-${new_version}/webase-front/conf/" 154 | cp -f "${PWD}/webase-front/conf/node.key" "${PWD}/webase-front-${new_version}/webase-front/conf/" 155 | fi 156 | else 157 | LOG_WARN "copy directory of ${PWD}/webase-front not exist!" 158 | exit 1 159 | fi 160 | } 161 | 162 | function copy_node_mgr() { 163 | LOG_INFO "copy webase-node-mgr config files" 164 | if [[ -d "${PWD}/webase-node-mgr" && -d "${PWD}/webase-node-mgr-${new_version}" ]]; then 165 | cp -f "${PWD}/webase-node-mgr/conf/application.yml" "${PWD}/webase-node-mgr-${new_version}/webase-node-mgr/conf/" 166 | #cp -r "${PWD}/webase-node-mgr/conf/log" "${PWD}/webase-node-mgr-${new_version}/webase-node-mgr/conf/" 167 | else 168 | LOG_WARN "copy directory of webase-node-mgr not exist!" 169 | exit 1 170 | fi 171 | } 172 | 173 | function copy_sign() { 174 | LOG_INFO "copy sign config files" 175 | if [[ -d "${PWD}/webase-sign" && -d "${PWD}/webase-sign-${new_version}/webase-sign" ]]; then 176 | cp -f "${PWD}/webase-sign/conf/application.yml" "${PWD}/webase-sign-${new_version}/webase-sign/conf/" 177 | else 178 | LOG_WARN "config directory of webase-sign not exist!" 179 | exit 1 180 | fi 181 | } 182 | 183 | 184 | 185 | # backup webase package and use new version package 186 | function backup() { 187 | local webase_name="$1" 188 | LOG_INFO "now backup old data of ${webase_name}" 189 | if [[ -d "${PWD}/${webase_name}" ]]; then 190 | mv "${PWD}/${webase_name}" "${PWD}/${old_version}/" 191 | else 192 | # skip v1.5.0 web-mobile upgrade, cuz added in v1.5.0 193 | if [[ "${new_version}" == "v1.5.0" && "${webase_name}" == "webase-web-mobile" ]]; then 194 | LOG_INFO "jump over webase-web-mobile backup: ${webase_name}" 195 | else 196 | LOG_WARN "backup directory of ${PWD}/${webase_name} not exist!" 197 | exit 1 198 | fi 199 | fi 200 | mv "${PWD}/${webase_name}-${new_version}/${webase_name}" "${PWD}/${webase_name}" 201 | } 202 | 203 | 204 | config_properties="${PWD}/common.properties" 205 | # 定义一个函数从properties文件读取key 206 | function prop() { 207 | local key="${1}" 208 | if [[ -f "$config_properties" ]]; then 209 | dos2unix $config_properties 210 | grep -P "^\s*[^#]?${key}=.*$" $config_properties | cut -d'=' -f2 211 | else 212 | LOG_WARN "webase $config_properties file not found!" 213 | exit 1 214 | fi 215 | } 216 | 217 | 218 | # upgrade table of node-mgr after backup webase-node-mgr dir 219 | function upgrade_mgr_sql() { 220 | # check whether old=>new .sql shell in new webase-node-mgr/script 221 | mgr_script_name="${PWD}/webase-node-mgr/script/upgrade/v${old_version_num}_v${new_version_num}.sql" 222 | if [[ -f "${mgr_script_name}" ]];then 223 | # get sql config of mgr from common.properties 224 | local ip=$(prop "mysql.ip") 225 | local port=$(prop "mysql.port") 226 | local user=$(prop "mysql.user") 227 | local password=$(prop "mysql.password") 228 | local database=$(prop "mysql.database") 229 | LOG_INFO "get propertise user: ${user} host: ${ip} port: ${port} db: ${database} " 230 | local backup_mgr_dir="webase-node-mgr-${old_version}/backup_node_mgr_${old_version}.sql" 231 | LOG_INFO "now backup the whole database of node-mgr in $backup_mgr_dir" 232 | mysqldump --user=${user} --password=${password} --host=${ip} --port=${port} ${database} > ${backup_mgr_dir} 233 | # exec .sql by mysql -e 234 | LOG_INFO "now upgrade database of node-mgr with script $mgr_script_name" 235 | mysql --user=$user --password=$password --host=$ip --port=$port --database=$database --default-character-set=utf8 -e "source ${mgr_script_name}" 236 | else 237 | LOG_WARN "node-mgr upgrade sql file of ${mgr_script_name} not exist!" 238 | exit 1 239 | fi 240 | } 241 | 242 | 243 | # update old yml 244 | # 根据版本号执行其中一段 245 | # 空格需要转义 246 | function update_node_mgr_yml() { 247 | mgr_yml="${PWD}/webase-node-mgr/conf/application.yml" 248 | LOG_INFO "now update yml value of node-mgr in $mgr_yml" 249 | if [[ ! -f $mgr_yml ]]; then 250 | LOG_WARN "yml of node-mgr in $mgr_yml not exist!" 251 | exit 1 252 | fi 253 | if [[ "${new_version}x" == "v1.5.0x" ]]; then 254 | LOG_INFO "update update_node_mgr_yml of version ${new_version}" 255 | # v1.5.0 key config to check if already add 256 | if [[ `grep -c "appStatusCheckCycle" ${mgr_yml}` -eq '0' ]]; then 257 | # 将constant:开头替换为 258 | local old_app_config="constant:" 259 | local new_app_config="constant:\n\ \ deployedModifyEnable:\ true\n\ \ appRequestTimeOut:\ 300000\n\ \ appStatusCheckCycle:\ 3000\n\ \ statBlockRetainMax:\ 100000\n\ \ statBlockFixedDelay: 5000\n\ \ statBlockPageSize:\ 10\n\ \ enableExternalFromBlock:\ true\n" 260 | sed -i "/${old_app_config}/c${new_app_config}" ${mgr_yml} 261 | fi 262 | if [[ `grep -c "\/api\/*" ${mgr_yml}` -eq '0' ]]; then 263 | # 需要空格开头 264 | local old_url_config="permitUrlArray:\ \/account\/login" 265 | local new_url_config="\ \ permitUrlArray:\ \/account\/login,\/account\/pictureCheckCode,\/login,\/user\/privateKey\/**,\/config\/encrypt,\/config\/version,\/front\/refresh,\/api\/*" 266 | sed -i "/${old_url_config}/c${new_url_config}" ${mgr_yml} 267 | fi 268 | fi 269 | } 270 | 271 | # copy webase-web and webase-web-mobile 272 | function update_nginx_conf() { 273 | LOG_INFO "now update webase-web nginx file in ${PWD}/comm/nginx.conf" 274 | if [[ ! -f "${PWD}/comm/nginx.conf" ]]; then 275 | LOG_WARN "nginx config file not exist, cannot auto update, now jump over!" 276 | #exit 1 277 | fi 278 | local zip="webase-deploy.zip" 279 | curl -#LO "${cdn_url_pre}/${new_version}/${zip}" 280 | if [[ "$(ls -al . | grep ${zip} | awk '{print $5}')" -lt "10000" ]];then 281 | LOG_WARN "update_nginx_conf pull newer webase-deploy.zip failed, exit now" 282 | #exit 1 283 | fi 284 | unzip -o "$zip" -d "temp-deploy" > /dev/null 285 | # backup nginx conf in {old_version} 286 | mv "${PWD}/comm/nginx.conf" "${PWD}/${old_version}/" 287 | # copy new one into ./comm 288 | cp -f "${PWD}/temp-deploy/webase-deploy/comm/nginx.conf" "${PWD}/comm/" 289 | # sed new conf file 290 | web_port=$(prop "web.port") 291 | mgr_port=$(prop "mgr.port") 292 | local pid_file="${PWD}/nginx-webase-web.pid" 293 | local web_dir="${PWD}/webase-web" 294 | local web_log_dir="${web_dir}/log" 295 | local h5_web_dir="${PWD}/webase-web-mobile" 296 | # create log dir 297 | if [[ ! -d "${PWD}/${web_log_dir}" ]]; then 298 | mkdir -p "$web_log_dir" 299 | fi 300 | 301 | sed -i "s/5000/${web_port}/g" "${PWD}/comm/nginx.conf" 302 | sed -i "s/5001/${mgr_port}/g" "${PWD}/comm/nginx.conf" 303 | sed -i "s:log_path:${web_log_dir}:g" "${PWD}/comm/nginx.conf" 304 | sed -i "s:pid_file:${pid_file}:g" "${PWD}/comm/nginx.conf" 305 | # set web_page_url(root & static) globally 306 | sed -i "s:web_page_url:${web_dir}:g" "${PWD}/comm/nginx.conf" 307 | # set mobile phone phone_page_url globally 308 | sed -i "s:phone_page_url:${h5_web_dir}:g" "${PWD}/comm/nginx.conf" 309 | # remove temp dir 310 | rm -rf "${PWD}/temp-deploy" 311 | } 312 | 313 | 314 | ## sed all yml's version 315 | function update_webase_yml_version() { 316 | LOG_INFO "start update version of new webase..." 317 | for webase_name in ${zip_list[@]}; 318 | do 319 | local yml_path="${PWD}/${webase_name}/conf/application.yml" 320 | # skip v1.5.0 webase-sign upgrade 321 | if [[ "${new_version}" == "v1.5.1" && "${webase_name}" == "webase-sign" ]]; then 322 | LOG_INFO "skip upgrade to ${new_version} in webase-sign" 323 | continue 324 | fi 325 | if [[ -f $yml_path ]]; then 326 | # check new version exist 327 | if [[ `grep -c "${new_version}" ${yml_path}` -eq '0' ]]; then 328 | local old_app_config="version:" 329 | local new_app_config="version:\ ${new_version}\n" 330 | sed -i "/${old_app_config}/c${new_app_config}" ${yml_path} 331 | fi 332 | else 333 | echo "jump over webase-web(or mobile)" 334 | fi 335 | done 336 | } 337 | 338 | 339 | exit_with_tips() 340 | { 341 | local content=${1} 342 | echo -e "\033[31m[ERROR] ${content}\033[0m" 343 | echo "use webase subsystem files in ${PWD}/${old_version} to recover " 344 | exit 1 345 | } 346 | 347 | # checkDependencies 348 | # get_version_num 349 | main && LOG_INFO "upgrade script finished from ${old_version} to ${new_version}" 350 | echo "end of script" 351 | exit ${SUCCESS} 352 | -------------------------------------------------------------------------------- /deploy/upgrade/upgrade-v1.5.2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | ################################################ 6 | # 下载新的zip包,已存在则移动到{old_version}的目录中 7 | 8 | # 解压新的zip包到webase-front.zip => webase-front-v1.5.0 9 | 10 | # 停止原有的,python3 deploy.py stopAll 11 | 12 | # webase-web 直接复制全部 13 | # 复制已有front的conf/*.yml, *.key, *.crt, *.so,覆盖当前的文件 14 | # 复制已有sign的conf/*.yml 15 | # 复制已有node-mgr已有的conf的*.yml,conf/log目录 16 | # 更新旧的yml,更新版本号 17 | 18 | # mv操作,备份已有的,移动到{old_version}的目录中 19 | 20 | # 备份node-mgr数据库到webase-node-mgr-v1.5.0/backup.sql 21 | # 从common.properties中获取两个数据库密码 22 | 23 | # 到node-mgr中检测script/upgrade目录,有匹配v143开头的,v150的结尾的,有则执行 mysql -e "source $sql_file" 24 | # 到sign...同上(当前版本不增加) 25 | 26 | # 启动新的,执行python3 deploy.py startAll 27 | ################################################ 28 | 29 | 30 | ## zip name 31 | zip_list=("webase-front" "webase-web" "webase-node-mgr") 32 | 33 | function main() { 34 | 35 | # pull 36 | if [[ ! -f "deploy.py" ]];then 37 | LOG_WARN "deploy.py not in this directory!" 38 | exit 1 39 | fi 40 | 41 | LOG_INFO "start pull zip of new webase..." 42 | 43 | # pull 44 | if [[ ! -f "${old_version}" ]];then 45 | # backup old zip 46 | mkdir "${old_version}" 47 | fi 48 | 49 | for webase_name in ${zip_list[@]}; 50 | do 51 | echo "now [${webase_name}] pull new version zip" 52 | # skip v1.5.0 webase-sign upgrade 53 | # if [[ "${new_version}" == "v1.5.1" && "${webase_name}" == "webase-sign" ]]; then 54 | # LOG_INFO "skip upgrade to ${new_version} in webase-sign" 55 | # continue 56 | # fi 57 | pull_zip "$webase_name" 58 | done 59 | 60 | # stop 61 | LOG_INFO "==========now webase stop all==========" 62 | python3 deploy.py stopAll 63 | # todo 判断是否已停止 64 | 65 | # change new webase's config file, backup old webase and data 66 | for webase_name in ${zip_list[@]}; 67 | do 68 | echo "now [${webase_name}] copy old version config & backup old files & update new data" 69 | # skip v1.5.0 webase-sign upgrade 70 | # if [[ "${new_version}" == "v1.5.1" && "${webase_name}" == "webase-sign" ]]; then 71 | # LOG_INFO "skip upgrade to ${new_version} in webase-sign" 72 | # continue 73 | # fi 74 | copy_webase "$webase_name" 75 | done 76 | 77 | # update version 78 | LOG_INFO "==========now update webase version in yml==========" 79 | update_webase_yml_version 80 | 81 | # restart 82 | LOG_INFO "==========now webase start all==========" 83 | python3 deploy.py startAll 84 | } 85 | 86 | 87 | function pull_zip() { 88 | local webase_name="$1" 89 | local zip="${webase_name}.zip" 90 | # delete old zip 91 | if [[ -f "$zip" ]];then 92 | LOG_INFO "move old version zip $zip to directory of [$PWD/${old_version}]" 93 | if [[ -f "${old_version}/${zip}" ]];then 94 | LOG_WARN "old version zip of ${zip} already in directory ./${old_version}" 95 | rm -rf "${PWD}/${zip}" 96 | else 97 | mv "$zip" "${old_version}/" 98 | fi 99 | fi 100 | LOG_INFO "pull zip of $zip" 101 | curl -#LO "${cdn_url_pre}/${new_version}/${zip}" 102 | if [[ "$(ls -al . | grep ${zip} | awk '{print $5}')" -lt "500000" ]];then # 1m=1048576b 103 | LOG_WARN "download ${zip} failed, exit!" 104 | exit 1 105 | fi 106 | # webase-web.zip => webase-web-v1.5.0/webase-web 107 | #注:unzip后变成了webase-web-v1.5.0/webase-web 108 | if [[ -d "${webase_name}-${new_version}" ]];then 109 | LOG_WARN "unzip destination dir already exist, now rm and re-unzip" 110 | rm -rf "${PWD}/${webase_name}-${new_version}" 111 | fi 112 | unzip -o "$zip" -d "${webase_name}-${new_version}" > /dev/null 113 | } 114 | 115 | ## copy config and cert to new unzip dir 116 | # 先复制到新目录,然后再备份旧的文件夹 117 | function copy_webase() { 118 | local webase_name="$1" 119 | case ${webase_name} in 120 | "webase-web") 121 | backup "webase-web" 122 | backup "webase-web-mobile" 123 | update_nginx_conf 124 | ;; 125 | "webase-front") 126 | copy_front 127 | backup "webase-front" 128 | ##update_front_yml 129 | ;; 130 | "webase-node-mgr") 131 | copy_node_mgr 132 | backup "webase-node-mgr" 133 | update_node_mgr_yml 134 | upgrade_mgr_sql 135 | ;; 136 | "webase-sign") 137 | copy_sign 138 | backup "webase-sign" 139 | ##update_sign_yml 140 | ##upgrade_sign_sql 141 | ;; 142 | \?) 143 | LOG_WARN "not support update this service [${webase_name}]" 144 | ;; 145 | esac 146 | 147 | } 148 | 149 | function copy_front() { 150 | LOG_INFO "copy webase-front config files" 151 | if [[ -d "${PWD}/webase-front" && -d "${PWD}/webase-front-${new_version}" ]]; then 152 | cp -f "${PWD}/webase-front/conf/application.yml" "${PWD}/webase-front-${new_version}/webase-front/conf/" 153 | cp -f "${PWD}/webase-front/conf/log4j2.xml" "${PWD}/webase-front-${new_version}/webase-front/conf/" 154 | cp -f "${PWD}/webase-front/conf/ca.crt" "${PWD}/webase-front-${new_version}/webase-front/conf/" 155 | cp -f "${PWD}/webase-front/conf/sdk.crt" "${PWD}/webase-front-${new_version}/webase-front/conf/" 156 | cp -f "${PWD}/webase-front/conf/sdk.key" "${PWD}/webase-front-${new_version}/webase-front/conf/" 157 | cp -rf "${PWD}/webase-front/conf/gm" "${PWD}/webase-front-${new_version}/webase-front/conf/" 158 | cp -f "${PWD}/webase-front/conf/libsigar-aarch64-linux.so" "${PWD}/webase-front-${new_version}/webase-front/conf/" 159 | cp -f "${PWD}/webase-front/conf/libsigar-amd64-linux.so" "${PWD}/webase-front-${new_version}/webase-front/conf/" 160 | cp -f "${PWD}/webase-front/conf/libsigar-universal64-macosx.dylib" "${PWD}/webase-front-${new_version}/webase-front/conf/" 161 | cp -f "${PWD}/webase-front/conf/libsigar-x86-linux.so" "${PWD}/webase-front-${new_version}/webase-front/conf/" 162 | if [[ -f "${PWD}/webase-front/conf/node.key" ]]; then 163 | cp -f "${PWD}/webase-front/conf/node.crt" "${PWD}/webase-front-${new_version}/webase-front/conf/" 164 | cp -f "${PWD}/webase-front/conf/node.key" "${PWD}/webase-front-${new_version}/webase-front/conf/" 165 | fi 166 | else 167 | LOG_WARN "copy directory of ${PWD}/webase-front not exist!" 168 | exit 1 169 | fi 170 | } 171 | 172 | function copy_node_mgr() { 173 | LOG_INFO "copy webase-node-mgr config files" 174 | if [[ -d "${PWD}/webase-node-mgr" && -d "${PWD}/webase-node-mgr-${new_version}" ]]; then 175 | cp -f "${PWD}/webase-node-mgr/conf/application.yml" "${PWD}/webase-node-mgr-${new_version}/webase-node-mgr/conf/" 176 | #cp -r "${PWD}/webase-node-mgr/conf/log" "${PWD}/webase-node-mgr-${new_version}/webase-node-mgr/conf/" 177 | else 178 | LOG_WARN "copy directory of webase-node-mgr not exist!" 179 | exit 1 180 | fi 181 | } 182 | 183 | function copy_sign() { 184 | LOG_INFO "copy sign config files" 185 | if [[ -d "${PWD}/webase-sign" && -d "${PWD}/webase-sign-${new_version}/webase-sign" ]]; then 186 | cp -f "${PWD}/webase-sign/conf/application.yml" "${PWD}/webase-sign-${new_version}/webase-sign/conf/" 187 | else 188 | LOG_WARN "config directory of webase-sign not exist!" 189 | exit 1 190 | fi 191 | } 192 | 193 | 194 | 195 | # backup webase package and use new version package 196 | function backup() { 197 | local webase_name="$1" 198 | LOG_INFO "now backup old data of ${webase_name}" 199 | if [[ -d "${PWD}/${webase_name}" ]]; then 200 | mv "${PWD}/${webase_name}" "${PWD}/${old_version}/" 201 | else 202 | # skip v1.5.0 web-mobile upgrade, cuz added in v1.5.0 203 | if [[ "${new_version}" == "v1.5.0" && "${webase_name}" == "webase-web-mobile" ]]; then 204 | LOG_INFO "jump over webase-web-mobile backup: ${webase_name}" 205 | else 206 | LOG_WARN "backup directory of ${PWD}/${webase_name} not exist!" 207 | exit 1 208 | fi 209 | fi 210 | mv "${PWD}/${webase_name}-${new_version}/${webase_name}" "${PWD}/${webase_name}" 211 | } 212 | 213 | 214 | config_properties="${PWD}/common.properties" 215 | # 定义一个函数从properties文件读取key 216 | function prop() { 217 | local key="${1}" 218 | if [[ -f "$config_properties" ]]; then 219 | dos2unix $config_properties 220 | grep -P "^\s*[^#]?${key}=.*$" $config_properties | cut -d'=' -f2 221 | else 222 | LOG_WARN "webase $config_properties file not found!" 223 | exit 1 224 | fi 225 | } 226 | 227 | 228 | # upgrade table of node-mgr after backup webase-node-mgr dir 229 | function upgrade_mgr_sql() { 230 | # check whether old=>new .sql shell in new webase-node-mgr/script 231 | mgr_script_name="${PWD}/webase-node-mgr/script/upgrade/v${old_version_num}_v${new_version_num}.sql" 232 | if [[ -f "${mgr_script_name}" ]];then 233 | # get sql config of mgr from common.properties 234 | local ip=$(prop "mysql.ip") 235 | local port=$(prop "mysql.port") 236 | local user=$(prop "mysql.user") 237 | local password=$(prop "mysql.password") 238 | local database=$(prop "mysql.database") 239 | LOG_INFO "get propertise user: ${user} host: ${ip} port: ${port} db: ${database} " 240 | local backup_mgr_dir="webase-node-mgr-${old_version}/backup_node_mgr_${old_version}.sql" 241 | LOG_INFO "now backup the whole database of node-mgr in $backup_mgr_dir" 242 | mysqldump --user=${user} --password=${password} --host=${ip} --port=${port} ${database} > ${backup_mgr_dir} 243 | # exec .sql by mysql -e 244 | LOG_INFO "now upgrade database of node-mgr with script $mgr_script_name" 245 | mysql --user=$user --password=$password --host=$ip --port=$port --database=$database --default-character-set=utf8 -e "source ${mgr_script_name}" 246 | else 247 | LOG_WARN "node-mgr upgrade sql file of ${mgr_script_name} not exist!" 248 | exit 1 249 | fi 250 | } 251 | 252 | 253 | # update old yml 254 | # 根据版本号执行其中一段 255 | # 空格需要转义 256 | function update_node_mgr_yml() { 257 | mgr_yml="${PWD}/webase-node-mgr/conf/application.yml" 258 | LOG_INFO "now update yml value of node-mgr in $mgr_yml" 259 | if [[ ! -f $mgr_yml ]]; then 260 | LOG_WARN "yml of node-mgr in $mgr_yml not exist!" 261 | exit 1 262 | fi 263 | if [[ "${new_version}x" == "v1.5.0x" ]]; then 264 | LOG_INFO "update update_node_mgr_yml of version ${new_version}" 265 | # v1.5.0 key config to check if already add 266 | if [[ `grep -c "appStatusCheckCycle" ${mgr_yml}` -eq '0' ]]; then 267 | # 将constant:开头替换为 268 | local old_app_config="constant:" 269 | local new_app_config="constant:\n\ \ deployedModifyEnable:\ true\n\ \ appRequestTimeOut:\ 300000\n\ \ appStatusCheckCycle:\ 3000\n\ \ statBlockRetainMax:\ 100000\n\ \ statBlockFixedDelay: 5000\n\ \ statBlockPageSize:\ 10\n\ \ enableExternalFromBlock:\ true\n" 270 | sed -i "/${old_app_config}/c${new_app_config}" ${mgr_yml} 271 | fi 272 | if [[ `grep -c "\/api\/*" ${mgr_yml}` -eq '0' ]]; then 273 | # 需要空格开头 274 | local old_url_config="permitUrlArray:\ \/account\/login" 275 | local new_url_config="\ \ permitUrlArray:\ \/account\/login,\/account\/pictureCheckCode,\/login,\/user\/privateKey\/**,\/config\/encrypt,\/config\/version,\/front\/refresh,\/api\/*" 276 | sed -i "/${old_url_config}/c${new_url_config}" ${mgr_yml} 277 | fi 278 | fi 279 | } 280 | 281 | # copy webase-web and webase-web-mobile 282 | function update_nginx_conf() { 283 | LOG_INFO "now update webase-web nginx file in ${PWD}/comm/nginx.conf" 284 | if [[ ! -f "${PWD}/comm/nginx.conf" ]]; then 285 | LOG_WARN "nginx config file not exist, cannot auto update, now jump over!" 286 | #exit 1 287 | fi 288 | local zip="webase-deploy.zip" 289 | curl -#LO "${cdn_url_pre}/${new_version}/${zip}" 290 | if [[ "$(ls -al . | grep ${zip} | awk '{print $5}')" -lt "10000" ]];then 291 | LOG_WARN "update_nginx_conf pull newer webase-deploy.zip failed, exit now" 292 | #exit 1 293 | fi 294 | unzip -o "$zip" -d "temp-deploy" > /dev/null 295 | # backup nginx conf in {old_version} 296 | mv "${PWD}/comm/nginx.conf" "${PWD}/${old_version}/" 297 | # copy new one into ./comm 298 | cp -f "${PWD}/temp-deploy/webase-deploy/comm/nginx.conf" "${PWD}/comm/" 299 | # sed new conf file 300 | web_port=$(prop "web.port") 301 | mgr_port=$(prop "mgr.port") 302 | local pid_file="${PWD}/nginx-webase-web.pid" 303 | local web_dir="${PWD}/webase-web" 304 | local web_log_dir="${web_dir}/log" 305 | local h5_web_dir="${PWD}/webase-web-mobile" 306 | # create log dir 307 | if [[ ! -d "${PWD}/${web_log_dir}" ]]; then 308 | mkdir -p "$web_log_dir" 309 | fi 310 | 311 | sed -i "s/5000/${web_port}/g" "${PWD}/comm/nginx.conf" 312 | sed -i "s/5001/${mgr_port}/g" "${PWD}/comm/nginx.conf" 313 | sed -i "s:log_path:${web_log_dir}:g" "${PWD}/comm/nginx.conf" 314 | sed -i "s:pid_file:${pid_file}:g" "${PWD}/comm/nginx.conf" 315 | # set web_page_url(root & static) globally 316 | sed -i "s:web_page_url:${web_dir}:g" "${PWD}/comm/nginx.conf" 317 | # set mobile phone phone_page_url globally 318 | sed -i "s:phone_page_url:${h5_web_dir}:g" "${PWD}/comm/nginx.conf" 319 | # remove temp dir 320 | rm -rf "${PWD}/temp-deploy" 321 | } 322 | 323 | 324 | ## sed all yml's version 325 | function update_webase_yml_version() { 326 | LOG_INFO "start update version of new webase..." 327 | for webase_name in ${zip_list[@]}; 328 | do 329 | local yml_path="${PWD}/${webase_name}/conf/application.yml" 330 | # skip v1.5.0 webase-sign upgrade 331 | if [[ "${new_version}" == "v1.5.1" && "${webase_name}" == "webase-sign" ]]; then 332 | LOG_INFO "skip upgrade to ${new_version} in webase-sign" 333 | continue 334 | fi 335 | if [[ -f $yml_path ]]; then 336 | # check new version exist 337 | if [[ `grep -c "${new_version}" ${yml_path}` -eq '0' ]]; then 338 | local old_app_config="version:" 339 | local new_app_config="version:\ ${new_version}\n" 340 | sed -i "/${old_app_config}/c${new_app_config}" ${yml_path} 341 | fi 342 | else 343 | echo "jump over webase-web(or mobile)" 344 | fi 345 | done 346 | } 347 | 348 | 349 | exit_with_tips() 350 | { 351 | local content=${1} 352 | echo -e "\033[31m[ERROR] ${content}\033[0m" 353 | echo "use webase subsystem files in ${PWD}/${old_version} to recover " 354 | exit 1 355 | } 356 | 357 | # checkDependencies 358 | # get_version_num 359 | main && LOG_INFO "upgrade script finished from ${old_version} to ${new_version}" 360 | echo "end of script" 361 | exit ${SUCCESS} 362 | -------------------------------------------------------------------------------- /deploy/upgrade/upgrade-v1.5.3.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | ################################################ 6 | # 下载新的zip包,已存在则移动到{old_version}的目录中 7 | 8 | # 解压新的zip包到webase-front.zip => webase-front-v1.5.0 9 | 10 | # 停止原有的,python3 deploy.py stopAll 11 | 12 | # webase-web 直接复制全部 13 | # 复制已有front的conf/*.yml, *.key, *.crt, *.so,覆盖当前的文件 14 | # 复制已有sign的conf/*.yml 15 | # 复制已有node-mgr已有的conf的*.yml,conf/log目录 16 | # 更新旧的yml,更新版本号 17 | 18 | # mv操作,备份已有的,移动到{old_version}的目录中 19 | 20 | # 备份node-mgr数据库到webase-node-mgr-v1.5.0/backup.sql 21 | # 从common.properties中获取两个数据库密码 22 | 23 | # 到node-mgr中检测script/upgrade目录,有匹配v143开头的,v150的结尾的,有则执行 mysql -e "source $sql_file" 24 | # 到sign...同上(当前版本不增加) 25 | 26 | # 启动新的,执行python3 deploy.py startAll 27 | ################################################ 28 | 29 | 30 | ## zip name 31 | zip_list=("webase-front" "webase-web" "webase-node-mgr") 32 | 33 | function main() { 34 | 35 | # pull 36 | if [[ ! -f "deploy.py" ]];then 37 | LOG_WARN "deploy.py not in this directory!" 38 | exit 1 39 | fi 40 | 41 | LOG_INFO "start pull zip of new webase..." 42 | 43 | # pull 44 | if [[ ! -f "${old_version}" ]];then 45 | # backup old zip 46 | mkdir "${old_version}" 47 | fi 48 | 49 | for webase_name in ${zip_list[@]}; 50 | do 51 | echo "now [${webase_name}] pull new version zip" 52 | # skip v1.5.0 webase-sign upgrade 53 | # if [[ "${new_version}" == "v1.5.1" && "${webase_name}" == "webase-sign" ]]; then 54 | # LOG_INFO "skip upgrade to ${new_version} in webase-sign" 55 | # continue 56 | # fi 57 | pull_zip "$webase_name" 58 | done 59 | 60 | # stop 61 | LOG_INFO "==========now webase stop all==========" 62 | python3 deploy.py stopAll 63 | # todo 判断是否已停止 64 | 65 | # change new webase's config file, backup old webase and data 66 | for webase_name in ${zip_list[@]}; 67 | do 68 | echo "now [${webase_name}] copy old version config & backup old files & update new data" 69 | # skip v1.5.0 webase-sign upgrade 70 | # if [[ "${new_version}" == "v1.5.1" && "${webase_name}" == "webase-sign" ]]; then 71 | # LOG_INFO "skip upgrade to ${new_version} in webase-sign" 72 | # continue 73 | # fi 74 | copy_webase "$webase_name" 75 | done 76 | 77 | # update version 78 | LOG_INFO "==========now update webase version in yml==========" 79 | update_webase_yml_version 80 | 81 | # restart 82 | LOG_INFO "==========now webase start all==========" 83 | python3 deploy.py startAll 84 | } 85 | 86 | 87 | function pull_zip() { 88 | local webase_name="$1" 89 | local zip="${webase_name}.zip" 90 | # delete old zip 91 | if [[ -f "$zip" ]];then 92 | LOG_INFO "move old version zip $zip to directory of [$PWD/${old_version}]" 93 | if [[ -f "${old_version}/${zip}" ]];then 94 | LOG_WARN "old version zip of ${zip} already in directory ./${old_version}" 95 | rm -rf "${PWD}/${zip}" 96 | else 97 | mv "$zip" "${old_version}/" 98 | fi 99 | fi 100 | LOG_INFO "pull zip of $zip" 101 | curl -#LO "${cdn_url_pre}/${new_version}/${zip}" 102 | if [[ "$(ls -al . | grep ${zip} | awk '{print $5}')" -lt "500000" ]];then # 1m=1048576b 103 | LOG_WARN "download ${zip} failed, exit!" 104 | exit 1 105 | fi 106 | # webase-web.zip => webase-web-v1.5.0/webase-web 107 | #注:unzip后变成了webase-web-v1.5.0/webase-web 108 | if [[ -d "${webase_name}-${new_version}" ]];then 109 | LOG_WARN "unzip destination dir already exist, now rm and re-unzip" 110 | rm -rf "${PWD}/${webase_name}-${new_version}" 111 | fi 112 | unzip -o "$zip" -d "${webase_name}-${new_version}" > /dev/null 113 | } 114 | 115 | ## copy config and cert to new unzip dir 116 | # 先复制到新目录,然后再备份旧的文件夹 117 | function copy_webase() { 118 | local webase_name="$1" 119 | case ${webase_name} in 120 | "webase-web") 121 | backup "webase-web" 122 | backup "webase-web-mobile" 123 | update_nginx_conf 124 | ;; 125 | "webase-front") 126 | copy_front 127 | backup "webase-front" 128 | ##update_front_yml 129 | ;; 130 | "webase-node-mgr") 131 | copy_node_mgr 132 | backup "webase-node-mgr" 133 | update_node_mgr_yml 134 | upgrade_mgr_sql 135 | ;; 136 | "webase-sign") 137 | copy_sign 138 | backup "webase-sign" 139 | ##update_sign_yml 140 | ##upgrade_sign_sql 141 | ;; 142 | \?) 143 | LOG_WARN "not support update this service [${webase_name}]" 144 | ;; 145 | esac 146 | 147 | } 148 | 149 | function copy_front() { 150 | LOG_INFO "copy webase-front config files" 151 | if [[ -d "${PWD}/webase-front" && -d "${PWD}/webase-front-${new_version}" ]]; then 152 | cp -f "${PWD}/webase-front/conf/application.yml" "${PWD}/webase-front-${new_version}/webase-front/conf/" 153 | cp -f "${PWD}/webase-front/conf/log4j2.xml" "${PWD}/webase-front-${new_version}/webase-front/conf/" 154 | cp -f "${PWD}/webase-front/conf/ca.crt" "${PWD}/webase-front-${new_version}/webase-front/conf/" 155 | cp -f "${PWD}/webase-front/conf/sdk.crt" "${PWD}/webase-front-${new_version}/webase-front/conf/" 156 | cp -f "${PWD}/webase-front/conf/sdk.key" "${PWD}/webase-front-${new_version}/webase-front/conf/" 157 | cp -rf "${PWD}/webase-front/conf/gm" "${PWD}/webase-front-${new_version}/webase-front/conf/" 158 | cp -f "${PWD}/webase-front/conf/libsigar-aarch64-linux.so" "${PWD}/webase-front-${new_version}/webase-front/conf/" 159 | cp -f "${PWD}/webase-front/conf/libsigar-amd64-linux.so" "${PWD}/webase-front-${new_version}/webase-front/conf/" 160 | cp -f "${PWD}/webase-front/conf/libsigar-universal64-macosx.dylib" "${PWD}/webase-front-${new_version}/webase-front/conf/" 161 | cp -f "${PWD}/webase-front/conf/libsigar-x86-linux.so" "${PWD}/webase-front-${new_version}/webase-front/conf/" 162 | if [[ -f "${PWD}/webase-front/conf/node.key" ]]; then 163 | cp -f "${PWD}/webase-front/conf/node.crt" "${PWD}/webase-front-${new_version}/webase-front/conf/" 164 | cp -f "${PWD}/webase-front/conf/node.key" "${PWD}/webase-front-${new_version}/webase-front/conf/" 165 | fi 166 | else 167 | LOG_WARN "copy directory of ${PWD}/webase-front not exist!" 168 | exit 1 169 | fi 170 | } 171 | 172 | function copy_node_mgr() { 173 | LOG_INFO "copy webase-node-mgr config files" 174 | if [[ -d "${PWD}/webase-node-mgr" && -d "${PWD}/webase-node-mgr-${new_version}" ]]; then 175 | cp -f "${PWD}/webase-node-mgr/conf/application.yml" "${PWD}/webase-node-mgr-${new_version}/webase-node-mgr/conf/" 176 | #cp -r "${PWD}/webase-node-mgr/conf/log" "${PWD}/webase-node-mgr-${new_version}/webase-node-mgr/conf/" 177 | else 178 | LOG_WARN "copy directory of webase-node-mgr not exist!" 179 | exit 1 180 | fi 181 | } 182 | 183 | function copy_sign() { 184 | LOG_INFO "copy sign config files" 185 | if [[ -d "${PWD}/webase-sign" && -d "${PWD}/webase-sign-${new_version}/webase-sign" ]]; then 186 | cp -f "${PWD}/webase-sign/conf/application.yml" "${PWD}/webase-sign-${new_version}/webase-sign/conf/" 187 | else 188 | LOG_WARN "config directory of webase-sign not exist!" 189 | exit 1 190 | fi 191 | } 192 | 193 | 194 | 195 | # backup webase package and use new version package 196 | function backup() { 197 | local webase_name="$1" 198 | LOG_INFO "now backup old data of ${webase_name}" 199 | if [[ -d "${PWD}/${webase_name}" ]]; then 200 | mv "${PWD}/${webase_name}" "${PWD}/${old_version}/" 201 | else 202 | # skip v1.5.0 web-mobile upgrade, cuz added in v1.5.0 203 | if [[ "${new_version}" == "v1.5.0" && "${webase_name}" == "webase-web-mobile" ]]; then 204 | LOG_INFO "jump over webase-web-mobile backup: ${webase_name}" 205 | else 206 | LOG_WARN "backup directory of ${PWD}/${webase_name} not exist!" 207 | exit 1 208 | fi 209 | fi 210 | mv "${PWD}/${webase_name}-${new_version}/${webase_name}" "${PWD}/${webase_name}" 211 | } 212 | 213 | 214 | config_properties="${PWD}/common.properties" 215 | # 定义一个函数从properties文件读取key 216 | function prop() { 217 | local key="${1}" 218 | if [[ -f "$config_properties" ]]; then 219 | dos2unix $config_properties 220 | grep -P "^\s*[^#]?${key}=.*$" $config_properties | cut -d'=' -f2 221 | else 222 | LOG_WARN "webase $config_properties file not found!" 223 | exit 1 224 | fi 225 | } 226 | 227 | 228 | # upgrade table of node-mgr after backup webase-node-mgr dir 229 | function upgrade_mgr_sql() { 230 | # check whether old=>new .sql shell in new webase-node-mgr/script 231 | mgr_script_name="${PWD}/webase-node-mgr/script/upgrade/v${old_version_num}_v${new_version_num}.sql" 232 | if [[ -f "${mgr_script_name}" ]];then 233 | # get sql config of mgr from common.properties 234 | local ip=$(prop "mysql.ip") 235 | local port=$(prop "mysql.port") 236 | local user=$(prop "mysql.user") 237 | local password=$(prop "mysql.password") 238 | local database=$(prop "mysql.database") 239 | LOG_INFO "get propertise user: ${user} host: ${ip} port: ${port} db: ${database} " 240 | local backup_mgr_dir="webase-node-mgr-${old_version}/backup_node_mgr_${old_version}.sql" 241 | LOG_INFO "now backup the whole database of node-mgr in $backup_mgr_dir" 242 | mysqldump --user=${user} --password=${password} --host=${ip} --port=${port} ${database} > ${backup_mgr_dir} 243 | # exec .sql by mysql -e 244 | LOG_INFO "now upgrade database of node-mgr with script $mgr_script_name" 245 | mysql --user=$user --password=$password --host=$ip --port=$port --database=$database --default-character-set=utf8 -e "source ${mgr_script_name}" 246 | else 247 | LOG_WARN "node-mgr upgrade sql file of ${mgr_script_name} not exist!" 248 | exit 1 249 | fi 250 | } 251 | 252 | 253 | # update old yml 254 | # 根据版本号执行其中一段 255 | # 空格需要转义 256 | function update_node_mgr_yml() { 257 | mgr_yml="${PWD}/webase-node-mgr/conf/application.yml" 258 | LOG_INFO "now update yml value of node-mgr in $mgr_yml" 259 | if [[ ! -f $mgr_yml ]]; then 260 | LOG_WARN "yml of node-mgr in $mgr_yml not exist!" 261 | exit 1 262 | fi 263 | if [[ "${new_version}x" == "v1.5.0x" ]]; then 264 | LOG_INFO "update update_node_mgr_yml of version ${new_version}" 265 | # v1.5.0 key config to check if already add 266 | if [[ `grep -c "appStatusCheckCycle" ${mgr_yml}` -eq '0' ]]; then 267 | # 将constant:开头替换为 268 | local old_app_config="constant:" 269 | local new_app_config="constant:\n\ \ deployedModifyEnable:\ true\n\ \ appRequestTimeOut:\ 300000\n\ \ appStatusCheckCycle:\ 3000\n\ \ statBlockRetainMax:\ 100000\n\ \ statBlockFixedDelay: 5000\n\ \ statBlockPageSize:\ 10\n\ \ enableExternalFromBlock:\ true\n" 270 | sed -i "/${old_app_config}/c${new_app_config}" ${mgr_yml} 271 | fi 272 | if [[ `grep -c "\/api\/*" ${mgr_yml}` -eq '0' ]]; then 273 | # 需要空格开头 274 | local old_url_config="permitUrlArray:\ \/account\/login" 275 | local new_url_config="\ \ permitUrlArray:\ \/account\/login,\/account\/pictureCheckCode,\/login,\/user\/privateKey\/**,\/config\/encrypt,\/config\/version,\/front\/refresh,\/api\/*" 276 | sed -i "/${old_url_config}/c${new_url_config}" ${mgr_yml} 277 | fi 278 | fi 279 | } 280 | 281 | # copy webase-web and webase-web-mobile 282 | function update_nginx_conf() { 283 | LOG_INFO "now update webase-web nginx file in ${PWD}/comm/nginx.conf" 284 | if [[ ! -f "${PWD}/comm/nginx.conf" ]]; then 285 | LOG_WARN "nginx config file not exist, cannot auto update, now jump over!" 286 | #exit 1 287 | fi 288 | local zip="webase-deploy.zip" 289 | curl -#LO "${cdn_url_pre}/${new_version}/${zip}" 290 | if [[ "$(ls -al . | grep ${zip} | awk '{print $5}')" -lt "10000" ]];then 291 | LOG_WARN "update_nginx_conf pull newer webase-deploy.zip failed, exit now" 292 | #exit 1 293 | fi 294 | unzip -o "$zip" -d "temp-deploy" > /dev/null 295 | # backup nginx conf in {old_version} 296 | mv "${PWD}/comm/nginx.conf" "${PWD}/${old_version}/" 297 | # copy new one into ./comm 298 | cp -f "${PWD}/temp-deploy/webase-deploy/comm/nginx.conf" "${PWD}/comm/" 299 | # sed new conf file 300 | web_port=$(prop "web.port") 301 | mgr_port=$(prop "mgr.port") 302 | local pid_file="${PWD}/nginx-webase-web.pid" 303 | local web_dir="${PWD}/webase-web" 304 | local web_log_dir="${web_dir}/log" 305 | local h5_web_dir="${PWD}/webase-web-mobile" 306 | # create log dir 307 | if [[ ! -d "${PWD}/${web_log_dir}" ]]; then 308 | mkdir -p "$web_log_dir" 309 | fi 310 | 311 | sed -i "s/5000/${web_port}/g" "${PWD}/comm/nginx.conf" 312 | sed -i "s/5001/${mgr_port}/g" "${PWD}/comm/nginx.conf" 313 | sed -i "s:log_path:${web_log_dir}:g" "${PWD}/comm/nginx.conf" 314 | sed -i "s:pid_file:${pid_file}:g" "${PWD}/comm/nginx.conf" 315 | # set web_page_url(root & static) globally 316 | sed -i "s:web_page_url:${web_dir}:g" "${PWD}/comm/nginx.conf" 317 | # set mobile phone phone_page_url globally 318 | sed -i "s:phone_page_url:${h5_web_dir}:g" "${PWD}/comm/nginx.conf" 319 | # remove temp dir 320 | rm -rf "${PWD}/temp-deploy" 321 | } 322 | 323 | 324 | ## sed all yml's version 325 | function update_webase_yml_version() { 326 | LOG_INFO "start update version of new webase..." 327 | for webase_name in ${zip_list[@]}; 328 | do 329 | local yml_path="${PWD}/${webase_name}/conf/application.yml" 330 | # skip v1.5.0 webase-sign upgrade 331 | if [[ "${new_version}" == "v1.5.1" && "${webase_name}" == "webase-sign" ]]; then 332 | LOG_INFO "skip upgrade to ${new_version} in webase-sign" 333 | continue 334 | fi 335 | if [[ -f $yml_path ]]; then 336 | # check new version exist 337 | if [[ `grep -c "${new_version}" ${yml_path}` -eq '0' ]]; then 338 | local old_app_config="version:" 339 | local new_app_config="version:\ ${new_version}\n" 340 | sed -i "/${old_app_config}/c${new_app_config}" ${yml_path} 341 | fi 342 | else 343 | echo "jump over webase-web(or mobile)" 344 | fi 345 | done 346 | } 347 | 348 | 349 | exit_with_tips() 350 | { 351 | local content=${1} 352 | echo -e "\033[31m[ERROR] ${content}\033[0m" 353 | echo "use webase subsystem files in ${PWD}/${old_version} to recover " 354 | exit 1 355 | } 356 | 357 | # checkDependencies 358 | # get_version_num 359 | main && LOG_INFO "upgrade script finished from ${old_version} to ${new_version}" 360 | echo "end of script" 361 | exit ${SUCCESS} 362 | -------------------------------------------------------------------------------- /deploy/upgrade/upgrade-v1.5.4.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | ################################################ 6 | # 下载新的zip包,已存在则移动到{old_version}的目录中 7 | 8 | # 解压新的zip包到webase-front.zip => webase-front-v1.5.0 9 | 10 | # 停止原有的,python3 deploy.py stopAll 11 | 12 | # webase-web 直接复制全部 13 | # 复制已有front的conf/*.yml, *.key, *.crt, *.so,覆盖当前的文件 14 | # 复制已有sign的conf/*.yml 15 | # 复制已有node-mgr已有的conf的*.yml,conf/log目录 16 | # 更新旧的yml,更新版本号 17 | 18 | # mv操作,备份已有的,移动到{old_version}的目录中 19 | 20 | # 备份node-mgr数据库到webase-node-mgr-v1.5.0/backup.sql 21 | # 从common.properties中获取两个数据库密码 22 | 23 | # 到node-mgr中检测script/upgrade目录,有匹配v143开头的,v150的结尾的,有则执行 mysql -e "source $sql_file" 24 | # 到sign...同上(当前版本不增加) 25 | 26 | # 启动新的,执行python3 deploy.py startAll 27 | ################################################ 28 | 29 | 30 | ## zip name 31 | zip_list=("webase-front" "webase-web" "webase-node-mgr") 32 | 33 | function main() { 34 | 35 | # pull 36 | if [[ ! -f "deploy.py" ]];then 37 | LOG_WARN "deploy.py not in this directory!" 38 | exit 1 39 | fi 40 | 41 | LOG_INFO "start pull zip of new webase..." 42 | 43 | # pull 44 | if [[ ! -f "${old_version}" ]];then 45 | # backup old zip 46 | mkdir "${old_version}" 47 | fi 48 | 49 | for webase_name in ${zip_list[@]}; 50 | do 51 | echo "now [${webase_name}] pull new version zip" 52 | # skip v1.5.0 webase-sign upgrade 53 | # if [[ "${new_version}" == "v1.5.1" && "${webase_name}" == "webase-sign" ]]; then 54 | # LOG_INFO "skip upgrade to ${new_version} in webase-sign" 55 | # continue 56 | # fi 57 | pull_zip "$webase_name" 58 | done 59 | 60 | # stop 61 | LOG_INFO "==========now webase stop all==========" 62 | python3 deploy.py stopAll 63 | # todo 判断是否已停止 64 | 65 | # change new webase's config file, backup old webase and data 66 | for webase_name in ${zip_list[@]}; 67 | do 68 | echo "now [${webase_name}] copy old version config & backup old files & update new data" 69 | # skip v1.5.0 webase-sign upgrade 70 | # if [[ "${new_version}" == "v1.5.1" && "${webase_name}" == "webase-sign" ]]; then 71 | # LOG_INFO "skip upgrade to ${new_version} in webase-sign" 72 | # continue 73 | # fi 74 | copy_webase "$webase_name" 75 | done 76 | 77 | # update version 78 | LOG_INFO "==========now update webase version in yml==========" 79 | update_webase_yml_version 80 | 81 | # restart 82 | LOG_INFO "==========now webase start all==========" 83 | python3 deploy.py startAll 84 | } 85 | 86 | 87 | function pull_zip() { 88 | local webase_name="$1" 89 | local zip="${webase_name}.zip" 90 | # delete old zip 91 | if [[ -f "$zip" ]];then 92 | LOG_INFO "move old version zip $zip to directory of [$PWD/${old_version}]" 93 | if [[ -f "${old_version}/${zip}" ]];then 94 | LOG_WARN "old version zip of ${zip} already in directory ./${old_version}" 95 | rm -rf "${PWD}/${zip}" 96 | else 97 | mv "$zip" "${old_version}/" 98 | fi 99 | fi 100 | LOG_INFO "pull zip of $zip" 101 | curl -#LO "${cdn_url_pre}/${new_version}/${zip}" 102 | if [[ "$(ls -al . | grep ${zip} | awk '{print $5}')" -lt "500000" ]];then # 1m=1048576b 103 | LOG_WARN "download ${zip} failed, exit!" 104 | exit 1 105 | fi 106 | # webase-web.zip => webase-web-v1.5.0/webase-web 107 | #注:unzip后变成了webase-web-v1.5.0/webase-web 108 | if [[ -d "${webase_name}-${new_version}" ]];then 109 | LOG_WARN "unzip destination dir already exist, now rm and re-unzip" 110 | rm -rf "${PWD}/${webase_name}-${new_version}" 111 | fi 112 | unzip -o "$zip" -d "${webase_name}-${new_version}" > /dev/null 113 | } 114 | 115 | ## copy config and cert to new unzip dir 116 | # 先复制到新目录,然后再备份旧的文件夹 117 | function copy_webase() { 118 | local webase_name="$1" 119 | case ${webase_name} in 120 | "webase-web") 121 | backup "webase-web" 122 | backup "webase-web-mobile" 123 | update_nginx_conf 124 | ;; 125 | "webase-front") 126 | copy_front 127 | backup "webase-front" 128 | ##update_front_yml 129 | ;; 130 | "webase-node-mgr") 131 | copy_node_mgr 132 | backup "webase-node-mgr" 133 | update_node_mgr_yml 134 | upgrade_mgr_sql 135 | ;; 136 | "webase-sign") 137 | copy_sign 138 | backup "webase-sign" 139 | ##update_sign_yml 140 | ##upgrade_sign_sql 141 | ;; 142 | \?) 143 | LOG_WARN "not support update this service [${webase_name}]" 144 | ;; 145 | esac 146 | 147 | } 148 | 149 | function copy_front() { 150 | LOG_INFO "copy webase-front config files" 151 | if [[ -d "${PWD}/webase-front" && -d "${PWD}/webase-front-${new_version}" ]]; then 152 | cp -f "${PWD}/webase-front/conf/application.yml" "${PWD}/webase-front-${new_version}/webase-front/conf/" 153 | cp -f "${PWD}/webase-front/conf/log4j2.xml" "${PWD}/webase-front-${new_version}/webase-front/conf/" 154 | cp -f "${PWD}/webase-front/conf/ca.crt" "${PWD}/webase-front-${new_version}/webase-front/conf/" 155 | cp -f "${PWD}/webase-front/conf/sdk.crt" "${PWD}/webase-front-${new_version}/webase-front/conf/" 156 | cp -f "${PWD}/webase-front/conf/sdk.key" "${PWD}/webase-front-${new_version}/webase-front/conf/" 157 | cp -rf "${PWD}/webase-front/conf/gm" "${PWD}/webase-front-${new_version}/webase-front/conf/" 158 | cp -f "${PWD}/webase-front/conf/libsigar-aarch64-linux.so" "${PWD}/webase-front-${new_version}/webase-front/conf/" 159 | cp -f "${PWD}/webase-front/conf/libsigar-amd64-linux.so" "${PWD}/webase-front-${new_version}/webase-front/conf/" 160 | cp -f "${PWD}/webase-front/conf/libsigar-universal64-macosx.dylib" "${PWD}/webase-front-${new_version}/webase-front/conf/" 161 | cp -f "${PWD}/webase-front/conf/libsigar-x86-linux.so" "${PWD}/webase-front-${new_version}/webase-front/conf/" 162 | if [[ -f "${PWD}/webase-front/conf/node.key" ]]; then 163 | cp -f "${PWD}/webase-front/conf/node.crt" "${PWD}/webase-front-${new_version}/webase-front/conf/" 164 | cp -f "${PWD}/webase-front/conf/node.key" "${PWD}/webase-front-${new_version}/webase-front/conf/" 165 | fi 166 | else 167 | LOG_WARN "copy directory of ${PWD}/webase-front not exist!" 168 | exit 1 169 | fi 170 | } 171 | 172 | function copy_node_mgr() { 173 | LOG_INFO "copy webase-node-mgr config files" 174 | if [[ -d "${PWD}/webase-node-mgr" && -d "${PWD}/webase-node-mgr-${new_version}" ]]; then 175 | cp -f "${PWD}/webase-node-mgr/conf/application.yml" "${PWD}/webase-node-mgr-${new_version}/webase-node-mgr/conf/" 176 | #cp -r "${PWD}/webase-node-mgr/conf/log" "${PWD}/webase-node-mgr-${new_version}/webase-node-mgr/conf/" 177 | else 178 | LOG_WARN "copy directory of webase-node-mgr not exist!" 179 | exit 1 180 | fi 181 | } 182 | 183 | function copy_sign() { 184 | LOG_INFO "copy sign config files" 185 | if [[ -d "${PWD}/webase-sign" && -d "${PWD}/webase-sign-${new_version}/webase-sign" ]]; then 186 | cp -f "${PWD}/webase-sign/conf/application.yml" "${PWD}/webase-sign-${new_version}/webase-sign/conf/" 187 | else 188 | LOG_WARN "config directory of webase-sign not exist!" 189 | exit 1 190 | fi 191 | } 192 | 193 | 194 | 195 | # backup webase package and use new version package 196 | function backup() { 197 | local webase_name="$1" 198 | LOG_INFO "now backup old data of ${webase_name}" 199 | if [[ -d "${PWD}/${webase_name}" ]]; then 200 | mv "${PWD}/${webase_name}" "${PWD}/${old_version}/" 201 | else 202 | # skip v1.5.0 web-mobile upgrade, cuz added in v1.5.0 203 | if [[ "${new_version}" == "v1.5.0" && "${webase_name}" == "webase-web-mobile" ]]; then 204 | LOG_INFO "jump over webase-web-mobile backup: ${webase_name}" 205 | else 206 | LOG_WARN "backup directory of ${PWD}/${webase_name} not exist!" 207 | exit 1 208 | fi 209 | fi 210 | mv "${PWD}/${webase_name}-${new_version}/${webase_name}" "${PWD}/${webase_name}" 211 | } 212 | 213 | 214 | config_properties="${PWD}/common.properties" 215 | # 定义一个函数从properties文件读取key 216 | function prop() { 217 | local key="${1}" 218 | if [[ -f "$config_properties" ]]; then 219 | dos2unix $config_properties 220 | grep -P "^\s*[^#]?${key}=.*$" $config_properties | cut -d'=' -f2 221 | else 222 | LOG_WARN "webase $config_properties file not found!" 223 | exit 1 224 | fi 225 | } 226 | 227 | 228 | # upgrade table of node-mgr after backup webase-node-mgr dir 229 | function upgrade_mgr_sql() { 230 | # check whether old=>new .sql shell in new webase-node-mgr/script 231 | mgr_script_name="${PWD}/webase-node-mgr/script/upgrade/v${old_version_num}_v${new_version_num}.sql" 232 | if [[ -f "${mgr_script_name}" ]];then 233 | # get sql config of mgr from common.properties 234 | local ip=$(prop "mysql.ip") 235 | local port=$(prop "mysql.port") 236 | local user=$(prop "mysql.user") 237 | local password=$(prop "mysql.password") 238 | local database=$(prop "mysql.database") 239 | LOG_INFO "get propertise user: ${user} host: ${ip} port: ${port} db: ${database} " 240 | local backup_mgr_dir="webase-node-mgr-${old_version}/backup_node_mgr_${old_version}.sql" 241 | LOG_INFO "now backup the whole database of node-mgr in $backup_mgr_dir" 242 | mysqldump --user=${user} --password=${password} --host=${ip} --port=${port} ${database} > ${backup_mgr_dir} 243 | # exec .sql by mysql -e 244 | LOG_INFO "now upgrade database of node-mgr with script $mgr_script_name" 245 | mysql --user=$user --password=$password --host=$ip --port=$port --database=$database --default-character-set=utf8 -e "source ${mgr_script_name}" 246 | else 247 | LOG_WARN "node-mgr upgrade sql file of ${mgr_script_name} not exist!" 248 | # 不存在意味着版本没更新表结构 249 | # exit 1 250 | fi 251 | } 252 | 253 | 254 | # update old yml 255 | # 根据版本号执行其中一段 256 | # 空格需要转义 257 | function update_node_mgr_yml() { 258 | mgr_yml="${PWD}/webase-node-mgr/conf/application.yml" 259 | LOG_INFO "now update yml value of node-mgr in $mgr_yml" 260 | if [[ ! -f $mgr_yml ]]; then 261 | LOG_WARN "yml of node-mgr in $mgr_yml not exist!" 262 | exit 1 263 | fi 264 | if [[ "${new_version}x" == "v1.5.0x" ]]; then 265 | LOG_INFO "update update_node_mgr_yml of version ${new_version}" 266 | # v1.5.0 key config to check if already add 267 | if [[ `grep -c "appStatusCheckCycle" ${mgr_yml}` -eq '0' ]]; then 268 | # 将constant:开头替换为 269 | local old_app_config="constant:" 270 | local new_app_config="constant:\n\ \ deployedModifyEnable:\ true\n\ \ appRequestTimeOut:\ 300000\n\ \ appStatusCheckCycle:\ 3000\n\ \ statBlockRetainMax:\ 100000\n\ \ statBlockFixedDelay: 5000\n\ \ statBlockPageSize:\ 10\n\ \ enableExternalFromBlock:\ true\n" 271 | sed -i "/${old_app_config}/c${new_app_config}" ${mgr_yml} 272 | fi 273 | if [[ `grep -c "\/api\/*" ${mgr_yml}` -eq '0' ]]; then 274 | # 需要空格开头 275 | local old_url_config="permitUrlArray:\ \/account\/login" 276 | local new_url_config="\ \ permitUrlArray:\ \/account\/login,\/account\/pictureCheckCode,\/login,\/user\/privateKey\/**,\/config\/encrypt,\/config\/version,\/front\/refresh,\/api\/*" 277 | sed -i "/${old_url_config}/c${new_url_config}" ${mgr_yml} 278 | fi 279 | fi 280 | } 281 | 282 | # copy webase-web and webase-web-mobile 283 | function update_nginx_conf() { 284 | LOG_INFO "now update webase-web nginx file in ${PWD}/comm/nginx.conf" 285 | if [[ ! -f "${PWD}/comm/nginx.conf" ]]; then 286 | LOG_WARN "nginx config file not exist, cannot auto update, now jump over!" 287 | #exit 1 288 | fi 289 | local zip="webase-deploy.zip" 290 | curl -#LO "${cdn_url_pre}/${new_version}/${zip}" 291 | if [[ "$(ls -al . | grep ${zip} | awk '{print $5}')" -lt "10000" ]];then 292 | LOG_WARN "update_nginx_conf pull newer webase-deploy.zip failed, exit now" 293 | #exit 1 294 | fi 295 | unzip -o "$zip" -d "temp-deploy" > /dev/null 296 | # backup nginx conf in {old_version} 297 | mv "${PWD}/comm/nginx.conf" "${PWD}/${old_version}/" 298 | # copy new one into ./comm 299 | cp -f "${PWD}/temp-deploy/webase-deploy/comm/nginx.conf" "${PWD}/comm/" 300 | # sed new conf file 301 | web_port=$(prop "web.port") 302 | mgr_port=$(prop "mgr.port") 303 | local pid_file="${PWD}/nginx-webase-web.pid" 304 | local web_dir="${PWD}/webase-web" 305 | local web_log_dir="${web_dir}/log" 306 | local h5_web_dir="${PWD}/webase-web-mobile" 307 | # create log dir 308 | if [[ ! -d "${PWD}/${web_log_dir}" ]]; then 309 | mkdir -p "$web_log_dir" 310 | fi 311 | 312 | sed -i "s/5000/${web_port}/g" "${PWD}/comm/nginx.conf" 313 | sed -i "s/5001/${mgr_port}/g" "${PWD}/comm/nginx.conf" 314 | sed -i "s:log_path:${web_log_dir}:g" "${PWD}/comm/nginx.conf" 315 | sed -i "s:pid_file:${pid_file}:g" "${PWD}/comm/nginx.conf" 316 | # set web_page_url(root & static) globally 317 | sed -i "s:web_page_url:${web_dir}:g" "${PWD}/comm/nginx.conf" 318 | # set mobile phone phone_page_url globally 319 | sed -i "s:phone_page_url:${h5_web_dir}:g" "${PWD}/comm/nginx.conf" 320 | # remove temp dir 321 | rm -rf "${PWD}/temp-deploy" 322 | } 323 | 324 | 325 | ## sed all yml's version 326 | function update_webase_yml_version() { 327 | LOG_INFO "start update version of new webase..." 328 | for webase_name in ${zip_list[@]}; 329 | do 330 | local yml_path="${PWD}/${webase_name}/conf/application.yml" 331 | # skip v1.5.0 webase-sign upgrade 332 | if [[ "${new_version}" == "v1.5.1" && "${webase_name}" == "webase-sign" ]]; then 333 | LOG_INFO "skip upgrade to ${new_version} in webase-sign" 334 | continue 335 | fi 336 | if [[ -f $yml_path ]]; then 337 | # check new version exist 338 | if [[ `grep -c "${new_version}" ${yml_path}` -eq '0' ]]; then 339 | local old_app_config="version:" 340 | local new_app_config="version:\ ${new_version}\n" 341 | sed -i "/${old_app_config}/c${new_app_config}" ${yml_path} 342 | fi 343 | else 344 | echo "jump over webase-web(or mobile)" 345 | fi 346 | done 347 | } 348 | 349 | 350 | exit_with_tips() 351 | { 352 | local content=${1} 353 | echo -e "\033[31m[ERROR] ${content}\033[0m" 354 | echo "use webase subsystem files in ${PWD}/${old_version} to recover " 355 | exit 1 356 | } 357 | 358 | # checkDependencies 359 | # get_version_num 360 | main && LOG_INFO "upgrade script finished from ${old_version} to ${new_version}" 361 | echo "end of script" 362 | exit ${SUCCESS} 363 | -------------------------------------------------------------------------------- /deploy/comm/mysql.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # encoding: utf-8 3 | 4 | from . import log as deployLog 5 | import sys 6 | import MySQLdb as mdb 7 | from .utils import * 8 | from urllib import parse 9 | import re 10 | 11 | log = deployLog.getLocalLogger() 12 | 13 | def addFrontToDb(): 14 | # get properties 15 | mysql_ip = getCommProperties("mysql.ip") 16 | mysql_port = int(getCommProperties("mysql.port")) 17 | mysql_user = getCommProperties("mysql.user") 18 | mysql_password_raw = getCommProperties("mysql.password") 19 | mysql_password = parse.unquote_plus(mysql_password_raw) 20 | mysql_database = getCommProperties("mysql.database") 21 | front_org = getCommProperties("front.org") 22 | front_port = getCommProperties("front.port") 23 | fisco_version = getCommProperties("fisco.version") 24 | 25 | try: 26 | # connect 27 | conn = mdb.connect(host=mysql_ip, port=mysql_port, user=mysql_user, passwd=mysql_password, database=mysql_database, charset='utf8') 28 | conn.autocommit(1) 29 | cursor = conn.cursor() 30 | 31 | # add db 32 | add_db = "INSERT INTO tb_front (node_id,front_ip,front_port,agency,client_version, create_time, modify_time) \ 33 | VALUES ('init','127.0.0.1',%s,\'%s\',\'%s\', NOW(),NOW())" % \ 34 | (front_port, front_org, fisco_version) 35 | log.info(add_db) 36 | cursor.execute(add_db) 37 | conn.commit() 38 | cursor.close() 39 | conn.close() 40 | except: 41 | import traceback 42 | log.info(" mysql except {}".format(traceback.format_exc())) 43 | traceback.print_exc() 44 | sys.exit(0) 45 | 46 | def mgrDbInit(): 47 | # return whether to init tables 48 | whether_init = True 49 | # get properties 50 | mysql_ip = getCommProperties("mysql.ip") 51 | mysql_port = int(getCommProperties("mysql.port")) 52 | mysql_user = getCommProperties("mysql.user") 53 | mysql_password_raw = getCommProperties("mysql.password") 54 | mysql_password = parse.unquote_plus(mysql_password_raw) 55 | mysql_database = getCommProperties("mysql.database") 56 | 57 | try: 58 | # connect 59 | conn = mdb.connect(host=mysql_ip, port=mysql_port, user=mysql_user, passwd=mysql_password, charset='utf8') 60 | conn.autocommit(1) 61 | cursor = conn.cursor() 62 | 63 | # check db 64 | result = cursor.execute('show databases like "%s"' %mysql_database) 65 | drop_db = 'DROP DATABASE IF EXISTS {}'.format(mysql_database) 66 | create_db = 'CREATE DATABASE IF NOT EXISTS {} default character set utf8'.format(mysql_database) 67 | if result == 1: 68 | info = "n" 69 | if sys.version_info.major == 2: 70 | info = raw_input("WeBASE-Node-Manager database {} already exists. Do you want drop and re-initialize it?[y/n]:".format(mysql_database)) 71 | else: 72 | info = input("WeBASE-Node-Manager database {} already exists. Do you want drop and re-initialize it?[y/n]:".format(mysql_database)) 73 | if info == "y" or info == "Y": 74 | log.info(drop_db) 75 | cursor.execute(drop_db) 76 | log.info(create_db) 77 | cursor.execute(create_db) 78 | # if not rebuild database, no need to re-init tables of database 79 | else: 80 | whether_init = False 81 | else: 82 | log.info(create_db) 83 | cursor.execute(create_db) 84 | cursor.close() 85 | conn.close() 86 | return whether_init 87 | except: 88 | import traceback 89 | log.info(" mysql except {}".format(traceback.format_exc())) 90 | traceback.print_exc() 91 | sys.exit(0) 92 | 93 | def signDbInit(): 94 | # get properties 95 | mysql_ip = getCommProperties("sign.mysql.ip") 96 | mysql_port = int(getCommProperties("sign.mysql.port")) 97 | mysql_user = getCommProperties("sign.mysql.user") 98 | mysql_password_raw = getCommProperties("sign.mysql.password") 99 | mysql_password = parse.unquote_plus(mysql_password_raw) 100 | mysql_database = getCommProperties("sign.mysql.database") 101 | try: 102 | # connect 103 | conn = mdb.connect(host=mysql_ip, port=mysql_port, user=mysql_user, passwd=mysql_password, charset='utf8') 104 | conn.autocommit(1) 105 | cursor = conn.cursor() 106 | 107 | # check db 108 | result = cursor.execute('show databases like "%s"' %mysql_database) 109 | drop_db = 'DROP DATABASE IF EXISTS {}'.format(mysql_database) 110 | create_db = 'CREATE DATABASE IF NOT EXISTS {} default character set utf8'.format(mysql_database) 111 | if result == 1: 112 | info = "n" 113 | if sys.version_info.major == 2: 114 | info = raw_input("WeBASE-Sign database {} already exists. Do you want drop and recreate it?[y/n]:".format(mysql_database)) 115 | else: 116 | info = input("WeBASE-Sign database {} already exists. Do you want drop and recreate it?[y/n]:".format(mysql_database)) 117 | if info == "y" or info == "Y": 118 | log.info(drop_db) 119 | cursor.execute(drop_db) 120 | log.info(create_db) 121 | cursor.execute(create_db) 122 | else: 123 | log.info(create_db) 124 | cursor.execute(create_db) 125 | cursor.close() 126 | conn.close() 127 | except: 128 | import traceback 129 | log.info(" mysql except {}".format(traceback.format_exc())) 130 | traceback.print_exc() 131 | sys.exit(0) 132 | 133 | 134 | def checkMgrDbAuthorized(): 135 | print ("check mgr database user/password...") 136 | # get properties 137 | mysql_ip = getCommProperties("mysql.ip") 138 | mysql_port = int(getCommProperties("mysql.port")) 139 | mysql_user = getCommProperties("mysql.user") 140 | mysql_password_raw = getCommProperties("mysql.password") 141 | mysql_password = parse.unquote_plus(mysql_password_raw) 142 | try: 143 | # connect 144 | conn = mdb.connect(host=mysql_ip, port=mysql_port, user=mysql_user, passwd=mysql_password) 145 | conn.close() 146 | print("check finished sucessfully.") 147 | log.info("check mgr db user/password correct!") 148 | except: 149 | import traceback 150 | print("======[Error]node-mgr's mysql user/password error!======") 151 | log.info("mgr mysql user/password error {}".format(traceback.format_exc())) 152 | traceback.print_exc() 153 | sys.exit(0) 154 | 155 | 156 | def checkSignDbAuthorized(): 157 | print ("check sign database user/password...") 158 | # get properties 159 | mysql_ip = getCommProperties("sign.mysql.ip") 160 | mysql_port = int(getCommProperties("sign.mysql.port")) 161 | mysql_user = getCommProperties("sign.mysql.user") 162 | mysql_password_raw = getCommProperties("sign.mysql.password") 163 | mysql_password = parse.unquote_plus(mysql_password_raw) 164 | try: 165 | # connect 166 | conn = mdb.connect(host=mysql_ip, port=mysql_port, user=mysql_user, passwd=mysql_password) 167 | conn.close() 168 | print("check finished sucessfully.") 169 | log.info("check sign db user/password correct!") 170 | except: 171 | import traceback 172 | print("======[Error]sign's mysql user/password error!======") 173 | log.info("sign mysql user/password error {}".format(traceback.format_exc())) 174 | traceback.print_exc() 175 | sys.exit(0) 176 | 177 | 178 | def checkMgrDbVersion(): 179 | print ("check mgr mysql version...") 180 | # get properties 181 | mysql_ip = getCommProperties("mysql.ip") 182 | mysql_port = int(getCommProperties("mysql.port")) 183 | mysql_user = getCommProperties("mysql.user") 184 | mysql_password_raw = getCommProperties("mysql.password") 185 | mysql_password = parse.unquote_plus(mysql_password_raw) 186 | try: 187 | # connect 188 | conn = mdb.connect(host=mysql_ip, port=mysql_port, user=mysql_user, passwd=mysql_password) 189 | # start check mysql version 190 | cursor = conn.cursor(cursor=mdb.cursors.DictCursor) 191 | log.info("checking node-mgr's mysql version") 192 | cursor.execute("select version();") 193 | # 5.6.xx-XX 194 | mysqlVersion = cursor.fetchall()[0].get("version()", "cannot_get_version") 195 | print("node-mgr's mysql version is [{}]".format(mysqlVersion)) 196 | match = re.search("\d+(.\d+){0,2}", mysqlVersion) 197 | log.info("version match is:[{}]".format(match)) 198 | # match不为空 199 | if match != "" and match != None: 200 | version = match.group() 201 | # 提取version第一位 202 | firstInt = int(version.split(".")[0]) 203 | if firstInt == 5: 204 | # 提取version第二位 205 | secondInt = int(version.split(".")[1]) 206 | # 5.6+ 207 | if secondInt < 5: 208 | sys.exit(0) 209 | elif secondInt == 5: 210 | print("[WARN]webase-node-mgr recommend mysql 5.6 or above") 211 | cursor.close() 212 | conn.close() 213 | print("check finished sucessfully.") 214 | log.info("check mgr db version correct!") 215 | except: 216 | import traceback 217 | print("======[Error]webase-node-mgr require mysql 5.6 or above======") 218 | log.info("mgr mysql require 5.6 or above error {}".format(traceback.format_exc())) 219 | traceback.print_exc() 220 | sys.exit(0) 221 | 222 | 223 | def checkSignDbVersion(): 224 | print ("check sign mysql version...") 225 | # get properties 226 | mysql_ip = getCommProperties("sign.mysql.ip") 227 | mysql_port = int(getCommProperties("sign.mysql.port")) 228 | mysql_user = getCommProperties("sign.mysql.user") 229 | mysql_password_raw = getCommProperties("sign.mysql.password") 230 | mysql_password = parse.unquote_plus(mysql_password_raw) 231 | try: 232 | # connect 233 | conn = mdb.connect(host=mysql_ip, port=mysql_port, user=mysql_user, passwd=mysql_password) 234 | # start check mysql version 235 | cursor = conn.cursor(cursor=mdb.cursors.DictCursor) 236 | log.info("checking sign's mysql version") 237 | cursor.execute("select version();") 238 | # 5.6.xx-XX 239 | mysqlVersion = cursor.fetchall()[0].get("version()", "cannot_get_version") 240 | print("sign's mysql version is [{}]".format(mysqlVersion)) 241 | match = re.search("\d+(.\d+){0,2}", mysqlVersion) 242 | log.info("version match is:[{}]".format(match)) 243 | # match不为空 244 | if match != "" and match != None: 245 | version = match.group() 246 | # 提取version第一位 247 | firstInt = int(version.split(".")[0]) 248 | if firstInt == 5: 249 | # 提取version第二位 250 | secondInt = int(version.split(".")[1]) 251 | # 5.6+ 252 | if secondInt < 5: 253 | sys.exit(0) 254 | elif secondInt == 5: 255 | print("[WARN]webase-sign recommend mysql 5.6 or above") 256 | cursor.close() 257 | conn.close() 258 | print("check finished sucessfully.") 259 | log.info("check sign db version correct!") 260 | except: 261 | import traceback 262 | print("======[Error]webase-sign require mysql 5.6 or above!======") 263 | log.info("sign mysql require 5.6 or above error {}".format(traceback.format_exc())) 264 | traceback.print_exc() 265 | sys.exit(0) 266 | 267 | # tool function: 268 | # init table and table's default data of nodemgr 269 | def initNodeMgrTable(script_dir): 270 | print ("init mgr database tables...") 271 | # get properties 272 | mysql_ip = getCommProperties("mysql.ip") 273 | mysql_port = int(getCommProperties("mysql.port")) 274 | mysql_user = getCommProperties("mysql.user") 275 | mysql_password_raw = getCommProperties("mysql.password") 276 | mysql_password = parse.unquote_plus(mysql_password_raw) 277 | mysql_database = getCommProperties("mysql.database") 278 | 279 | # read .sql content 280 | create_sql_path = script_dir + "/webase-ddl.sql" 281 | init_sql_path = script_dir + "/webase-dml.sql" 282 | # create table 283 | create_sql_list=readSqlContent(create_sql_path,1) 284 | # init table data 285 | init_sql_list=readSqlContent(init_sql_path,2) 286 | 287 | try: 288 | # connect 289 | conn = mdb.connect(host=mysql_ip, port=mysql_port, user=mysql_user, passwd=mysql_password, database=mysql_database, charset='utf8') 290 | conn.autocommit(1) 291 | cursor = conn.cursor() 292 | 293 | log.info("start create tables...") 294 | for sql_item in create_sql_list: 295 | #log.info("create sql:{}".format(sql_item)) 296 | cursor.execute(sql_item) 297 | 298 | log.info("start init default data of tables...") 299 | for sql_item in init_sql_list: 300 | #log.info("init sql:{}".format(sql_item)) 301 | cursor.execute(sql_item) 302 | 303 | print ("============== mgr db script init success! ==============") 304 | log.info("init mgr tables success!") 305 | cursor.close() 306 | conn.close() 307 | except: 308 | import traceback 309 | print ("============== script init fail! Please view log file (default path:./log/). ==============") 310 | log.info("init mgr database tables error {}".format(traceback.format_exc())) 311 | traceback.print_exc() 312 | sys.exit(0) 313 | 314 | # tool function: 315 | # sql_type: 1-create, 2-insert 316 | def readSqlContent(sql_path,sql_type): 317 | log.info("reading node manager table sql file {}".format(sql_path)) 318 | # read .sql file in webase-node-mgr/script 319 | with open(sql_path,encoding="utf-8",mode="r") as f: 320 | data = f.read() 321 | lines = data.splitlines() 322 | sql_data = '' 323 | # remove -- comment 324 | for line in lines: 325 | if len(line) == 0: 326 | continue 327 | elif line.startswith("--"): 328 | continue 329 | else: 330 | sql_data += line 331 | # create 332 | if sql_type == 1: 333 | final_sql_list = sql_data.split(';')[:-1] 334 | final_sql_list = [x.replace('\n', ' ') if '\n' in x else x for x in final_sql_list] 335 | return final_sql_list 336 | else: 337 | sql_list = sql_data.split(');')[:-1] 338 | final_sql_list = [] 339 | for sql_splited in sql_list: 340 | sql_splited = sql_splited + ");" 341 | #log.info("after sql sql_splited:{}".format(sql_splited)) 342 | final_sql_list.append(sql_splited) 343 | final_sql_list = [x.replace('\n', ' ') if '\n' in x else x for x in final_sql_list] 344 | return final_sql_list 345 | 346 | if __name__ == '__main__': 347 | pass 348 | -------------------------------------------------------------------------------- /deploy/comm/check.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # encoding: utf-8 3 | 4 | from . import log as deployLog 5 | import os 6 | import sys 7 | from .utils import * 8 | from .mysql import * 9 | import re 10 | #import psutil 11 | 12 | log = deployLog.getLocalLogger() 13 | checkDependent = ["git","openssl","curl","wget","dos2unix"] 14 | # memery(B) and cpu(core counts logical) 15 | # mem=psutil.virtual_memory() 16 | # cpuCore=psutil.cpu_count() 17 | 18 | def do(): 19 | print ("============================================================"), 20 | webaseMsg = ''' 21 | _ _ ______ ___ _____ _____ 22 | | | | | | ___ \/ _ \/ ___| ___| 23 | | | | | ___| |_/ / /_\ \ `--.| |__ 24 | | |/\| |/ _ | ___ | _ |`--. | __| 25 | \ /\ | __| |_/ | | | /\__/ | |___ 26 | \/ \/ \___\____/\_| |_\____/\____/ 27 | ''' 28 | print (webaseMsg) 29 | print ("============================================================") 30 | print ("============== checking envrionment ==============") 31 | installRequirements() 32 | checkConfigVersion() 33 | checkMemAndCpu() 34 | checkNginx() 35 | checkJava() 36 | checkNodePort() 37 | checkWebPort() 38 | checkMgrPort() 39 | checkSignPort() 40 | checkFrontPort() 41 | checkMgrDbConnect() 42 | checkSignDbConnect() 43 | checkMgrDbAuthorized() 44 | checkSignDbAuthorized() 45 | checkMgrDbVersion() 46 | checkSignDbVersion() 47 | checkExitedChainInfo() 48 | print ("============== envrionment available ==============") 49 | print ("============================================================") 50 | 51 | def visual_do(): 52 | print ("============================================================"), 53 | webaseMsg = ''' 54 | _ _ ______ ___ _____ _____ 55 | | | | | | ___ \/ _ \/ ___| ___| 56 | | | | | ___| |_/ / /_\ \ `--.| |__ 57 | | |/\| |/ _ | ___ | _ |`--. | __| 58 | \ /\ | __| |_/ | | | /\__/ | |___ 59 | \/ \/ \___\____/\_| |_\____/\____/ 60 | ''' 61 | print (webaseMsg) 62 | print ("============================================================") 63 | print ("============== checking envrionment ==============") 64 | installRequirements() 65 | checkDocker() 66 | checkNginx() 67 | checkJava() 68 | checkWebPort() 69 | checkMgrPort() 70 | checkSignIp() 71 | checkSignPort() 72 | checkSignDbConnect() 73 | checkMgrDbConnect() 74 | checkMgrDbAuthorized() 75 | checkSignDbAuthorized() 76 | checkMgrDbVersion() 77 | checkSignDbVersion() 78 | print ("============== envrionment available ==============") 79 | print ("============================================================") 80 | 81 | def docker_do(): 82 | print ("============================================================"), 83 | webaseMsg = ''' 84 | _ _ ______ ___ _____ _____ 85 | | | | | | ___ \/ _ \/ ___| ___| 86 | | | | | ___| |_/ / /_\ \ `--.| |__ 87 | | |/\| |/ _ | ___ | _ |`--. | __| 88 | \ /\ | __| |_/ | | | /\__/ | |___ 89 | \/ \/ \___\____/\_| |_\____/\____/ 90 | ''' 91 | print (webaseMsg) 92 | print ("============================================================") 93 | print ("============== checking envrionment ==============") 94 | installRequirements() 95 | checkDocker() 96 | checkDockerCompose() 97 | checkConfigVersion() 98 | checkMemAndCpu() 99 | checkNodePort() 100 | checkWebPort() 101 | checkMgrPort() 102 | checkSignPort() 103 | checkFrontPort() 104 | # if not docker mysql, check connect, auth, version 105 | dockerCheckDb() 106 | checkExitedChainInfo() 107 | print ("============== envrionment available ==============") 108 | print ("============================================================") 109 | 110 | 111 | def checkPort(): 112 | print ("============== checking port ==============") 113 | checkWebPort() 114 | checkMgrPort() 115 | checkSignPort() 116 | checkFrontPort() 117 | print ("============== port available ==============") 118 | 119 | def visualCheckPort(): 120 | print ("============== checking port ==============") 121 | checkWebPort() 122 | checkMgrPort() 123 | checkSignPort() 124 | print ("============== port available ==============") 125 | 126 | def installRequirements(): 127 | for require in checkDependent: 128 | print ("check {}...".format(require)) 129 | hasInstall = hasInstallServer(require) 130 | if not hasInstall: 131 | installByYum(require) 132 | print ("check finished sucessfully.") 133 | 134 | def checkNginx(): 135 | print ("check nginx...") 136 | require = "nginx" 137 | hasInstall = hasInstallServer(require) 138 | if not hasInstall: 139 | installByYum(require) 140 | print ("check finished sucessfully.") 141 | 142 | def checkDocker(): 143 | print ("check Docker...") 144 | require = "docker" 145 | hasInstall = hasInstallServer(require) 146 | if not hasInstall: 147 | doCmd("curl -s -L get.docker.com | bash") 148 | 149 | print("Try to start Docker...") 150 | doCmd("sudo systemctl start docker") 151 | print ("check finished sucessfully.") 152 | 153 | def checkDockerCompose(): 154 | print ("check docker-compose...") 155 | require = "docker-compose" 156 | hasInstall = hasInstallServer(require) 157 | if not hasInstall: 158 | print (" error! [{}] has not been installed or configured!".format(require)) 159 | sys.exit(0) 160 | print ("check finished sucessfully.") 161 | 162 | def checkJava(): 163 | print ("check java...") 164 | res_check = doCmdIgnoreException("java -version") 165 | if res_check["status"] != 0: 166 | print (" error! java has not been installed or configured!") 167 | sys.exit(0) 168 | res_home = doCmd("echo $JAVA_HOME") 169 | if res_home["output"].strip() == "": 170 | print (" error! JAVA_HOME has not been configured!") 171 | sys.exit(0) 172 | print ("check finished sucessfully.") 173 | return 174 | 175 | def checkNodePort(): 176 | if_exist_fisco = getCommProperties("if.exist.fisco") 177 | if if_exist_fisco == "yes": 178 | # checkExistedNodePort() 179 | return 180 | elif if_exist_fisco == "no": 181 | print ("check FISCO-BCOS node port...") 182 | checkNewNodePort() 183 | print ("check finished sucessfully.") 184 | else: 185 | print (" error! param if.exist.fisco must be yes or no, current is {}. please check.".format(if_exist_fisco)) 186 | sys.exit(0) 187 | 188 | def checkExistedNodePort(): 189 | listen_ip = getCommProperties("node.listenIp") 190 | node_rpcPort = int(getCommProperties("node.rpcPort")) 191 | node_p2pPort = int(getCommProperties("node.p2pPort")) 192 | node_channelPort = int(getCommProperties("node.channelPort")) 193 | res_rpcPort = net_if_used_no_msg(listen_ip,node_rpcPort) 194 | if not res_rpcPort: 195 | print (" error! rpc port {} is not alive. please check.".format(node_rpcPort)) 196 | sys.exit(0) 197 | res_p2pPort = net_if_used_no_msg(listen_ip,node_p2pPort) 198 | if not res_p2pPort: 199 | print (" error! p2p port {} is not alive. please check.".format(node_p2pPort)) 200 | sys.exit(0) 201 | res_channelPort = net_if_used_no_msg(listen_ip,node_channelPort) 202 | if not res_channelPort: 203 | print (" error! channel port {} is not alive. please check.".format(node_channelPort)) 204 | sys.exit(0) 205 | return 206 | 207 | def checkNewNodePort(): 208 | listen_ip = getCommProperties("node.listenIp") 209 | nodes = getCommProperties("node.counts") 210 | node_counts = 2 211 | if nodes != "nodeCounts": 212 | node_counts = int(nodes) 213 | node_rpcPort = int(getCommProperties("node.rpcPort")) 214 | node_p2pPort = int(getCommProperties("node.p2pPort")) 215 | node_channelPort = int(getCommProperties("node.channelPort")) 216 | for i in range(node_counts): 217 | res_rpcPort = net_if_used(listen_ip,node_rpcPort+i) 218 | if res_rpcPort: 219 | sys.exit(0) 220 | res_p2pPort = net_if_used(listen_ip,node_p2pPort+i) 221 | if res_p2pPort: 222 | sys.exit(0) 223 | res_channelPort = net_if_used(listen_ip,node_channelPort+i) 224 | if res_channelPort: 225 | sys.exit(0) 226 | return 227 | 228 | def checkWebPort(): 229 | print ("check WeBASE-Web port...") 230 | deploy_ip = "127.0.0.1" 231 | web_port = getCommProperties("web.port") 232 | res_web = net_if_used(deploy_ip,web_port) 233 | if res_web: 234 | sys.exit(0) 235 | print ("check finished sucessfully.") 236 | return 237 | 238 | def checkMgrPort(): 239 | print ("check WeBASE-Node-Manager port...") 240 | deploy_ip = "127.0.0.1" 241 | mgr_port = getCommProperties("mgr.port") 242 | res_mgr = net_if_used(deploy_ip,mgr_port) 243 | if res_mgr: 244 | sys.exit(0) 245 | print ("check finished sucessfully.") 246 | return 247 | 248 | def checkFrontPort(): 249 | print ("check WeBASE-Front port...") 250 | deploy_ip = "127.0.0.1" 251 | front_port = getCommProperties("front.port") 252 | 253 | if front_port is None: 254 | print ("======= WeBASE-Front is not deploy. return! =======") 255 | return 256 | 257 | res_front = net_if_used(deploy_ip,front_port) 258 | if res_front: 259 | sys.exit(0) 260 | print ("check finished sucessfully.") 261 | return 262 | 263 | def checkSignPort(): 264 | print ("check WeBASE-Sign port...") 265 | deploy_ip = "127.0.0.1" 266 | sign_port = getCommProperties("sign.port") 267 | res_sign = net_if_used(deploy_ip,sign_port) 268 | if res_sign: 269 | sys.exit(0) 270 | print ("check finished sucessfully.") 271 | return 272 | 273 | def checkSignIp(): 274 | print ("check WeBASE-Sign IP for visual deploy...") 275 | sign_ip = getCommProperties("sign.ip") 276 | if isBlank(sign_ip) or sign_ip == "127.0.0.1": 277 | print ("When using visual deploy, sign IP should be the external IP of this host, not 127.0.0.1.") 278 | sys.exit(0) 279 | print ("check finished sucessfully.") 280 | return 281 | 282 | def isBlank (str): 283 | return not (str and str.strip()) 284 | 285 | def checkMgrDbConnect(): 286 | print ("check database connection...") 287 | mysql_ip = getCommProperties("mysql.ip") 288 | mysql_port = getCommProperties("mysql.port") 289 | ifLink = do_telnet(mysql_ip,mysql_port) 290 | if not ifLink: 291 | print ('Mgr database ip:{} port:{} is disconnected, please confirm.'.format(mysql_ip, mysql_port)) 292 | sys.exit(0) 293 | print ("check finished sucessfully.") 294 | return 295 | 296 | def checkSignDbConnect(): 297 | print ("check database connection...") 298 | mysql_ip = getCommProperties("sign.mysql.ip") 299 | mysql_port = getCommProperties("sign.mysql.port") 300 | ifLink = do_telnet(mysql_ip,mysql_port) 301 | if not ifLink: 302 | print ('Sign database ip:{} port:{} is disconnected, please confirm.'.format(mysql_ip, mysql_port)) 303 | sys.exit(0) 304 | print ("check finished sucessfully.") 305 | return 306 | 307 | def hasInstallServer(server): 308 | result = doCmdIgnoreException("which {}".format(server)) 309 | if result["status"] == 0: 310 | return True 311 | else: 312 | return False 313 | 314 | def installByYum(server): 315 | if isCentos(): 316 | result = doCmdIgnoreException("sudo yum -y install {}".format(server)) 317 | if result["status"] != 0: 318 | os.system("sudo yum -y install epel-release") 319 | os.system("sudo yum -y install python-pip") 320 | os.system("pip install requests") 321 | result = doCmd("sudo yum -y install {}".format(server)) 322 | elif isSuse(): 323 | os.system("sudo zypper install -y {}".format(server)) 324 | elif isUbuntu(): 325 | os.system("sudo apt-get install -y {}".format(server)) 326 | else: 327 | print ("============================================================") 328 | print ('current system platform is not in target list(centos/redhat, ubuntu, suse') 329 | print ('===== please install dependency of [{}] on your own ====='.format(server)) 330 | info = "n" 331 | if sys.version_info.major == 2: 332 | info = raw_input("Please check whether dependency of [{}] already installed, yes or not?[y/n]:".format(server)) 333 | else: 334 | info = input("Please check whether dependency of [{}] already installed, yes or not?[y/n]:".format(server)) 335 | if info == "y" or info == "Y": 336 | return 337 | else: 338 | raise Exception("error, not support this platform, only support centos/redhat, suse, ubuntu.") 339 | return 340 | 341 | # update every version 342 | # check fisco version and webase-front version 343 | def checkConfigVersion(): 344 | existChain = getCommProperties("if.exist.fisco") 345 | if (existChain == 'no'): 346 | fisco_ver_str = getCommProperties("fisco.version") 347 | webase_front_ver_str = getCommProperties("webase.front.version") 348 | print ("check config webase {} and fisco version {}...".format(webase_front_ver_str, fisco_ver_str)) 349 | # check from common.properties 350 | checkVersionUtil(fisco_ver_str,webase_front_ver_str) 351 | print ('check finished sucessfully.') 352 | 353 | def checkVersionUtil(fisco_ver_str,webase_front_ver_str): 354 | log.info("checkVersionUtil webase: {} and fisco version: {}".format(webase_front_ver_str, fisco_ver_str)) 355 | fisco_version_int = int(re.findall("\d+", fisco_ver_str)[0]) * 100 + int(re.findall("\d+", fisco_ver_str)[1]) * 10 + int(re.findall("\d+", fisco_ver_str)[2]) * 1 356 | # webase-front version greater or equal with other webase version 357 | webase_front_version_int = int(re.findall("\d+", webase_front_ver_str)[0]) * 100 + int(re.findall("\d+", webase_front_ver_str)[1]) * 10 + int(re.findall("\d+", webase_front_ver_str)[2]) * 1 358 | log.info("checkVersionUtil int webase: {} and fisco version: {}".format(webase_front_version_int, fisco_version_int)) 359 | flag=False 360 | # require if webase <= 1.3.2, fisco < 2.5.0 361 | if ( webase_front_version_int <= 132 and fisco_version_int >= 250 ): 362 | flag=True 363 | # require if webase >= 1.3.1(dynamic group), fisco >= 2.4.1 364 | if ( webase_front_version_int >= 131 and fisco_version_int < 241 ): 365 | flag=True 366 | 367 | # if version conflicts, exit 368 | if (flag): 369 | raise Exception ('[ERROR]WeBASE of version {} not support FISCO of version {}, please check WeBASE version description or ChangeLog for detail!'.format(webase_front_ver_str, fisco_ver_str)) 370 | else: 371 | return 372 | 373 | def checkMemAndCpu(): 374 | print ("check host free memory and cpu core...") 375 | # result format: {'status': 0, 'output': '151.895'} 376 | # get free memory(M) 377 | memFree=doCmd("awk '($1 == \"MemFree:\"){print $2/1024}' /proc/meminfo 2>&1") 378 | # get cpu core num 379 | # cpuCore=doCmd("cat /proc/cpuinfo | grep processor | wc -l 2>&1") 380 | if (int(memFree.get("status")) != 0): 381 | raise Exception('Get memory or cpu core fail memFree:{}'.format(memFree)) 382 | memFreeStr=memFree.get("output").split(".", 1)[0] 383 | memFreeInt=int(memFreeStr) 384 | 385 | existed_chain = getCommProperties("if.exist.fisco") 386 | # if existed chain, only need memory for webase 387 | if (existed_chain == 'yes'): 388 | if (memFreeInt <= 2047): 389 | print ('[WARN]Free memory {}(M) may be NOT ENOUGH for webase'.format(memFreeInt)) 390 | print ("[WARN]Recommend webase with 2G memory at least. ") 391 | else: 392 | print ('check finished sucessfully.') 393 | return 394 | # else not existed chain 395 | fisco_count_str = getCommProperties("node.counts") 396 | fisco_count = 2 397 | if (fisco_count_str != 'nodeCounts'): 398 | fisco_count = int(fisco_count_str) 399 | # check 2 nodes, 4 nodes, more nodes memory free rate/cpu require 400 | flag=False 401 | if (fisco_count <= 2): 402 | if (memFreeInt <= 2047): 403 | flag=True 404 | if (fisco_count >= 4): 405 | if (memFreeInt <= 4095): 406 | flag=True 407 | if (flag): 408 | print ('[WARN]Free memory {}(M) may be NOT ENOUGH for node count [{}] and webase'.format(memFreeInt, fisco_count)) 409 | print ("[WARN]Recommend webase with 2G memory at least, and one node equipped with one core of CPU and 1G memory(linear increase with node count). ") 410 | else: 411 | print ('check finished sucessfully.') 412 | return 413 | 414 | def checkExitedChainInfo(): 415 | existChain = getCommProperties("if.exist.fisco") 416 | if (existChain == 'yes'): 417 | print ("check exited chain info...") 418 | 419 | listenIp = getCommProperties("node.listenIp") 420 | rpcPort = getCommProperties("node.rpcPort") 421 | chainRpcUrl = "http://{}:{}".format(listenIp,rpcPort) 422 | 423 | # check chain connect 424 | checkExistChainConnect() 425 | # request chain 426 | clientVersion=rest_getClientVersion(chainRpcUrl) 427 | # handle result 428 | fiscoVersion=clientVersion['FISCO-BCOS Version'] 429 | log.info("fiscoVersion: {}".format(fiscoVersion)) 430 | # check encrypt type 431 | checkEncryptType(fiscoVersion) 432 | # check version 433 | checkExitedChainVersion(fiscoVersion) 434 | 435 | print ('check exited chain info sucessfully.') 436 | else: 437 | return 438 | 439 | def checkEncryptType(fiscoVersion): 440 | print ("check encrypt type...") 441 | encryptType = getCommProperties("encrypt.type") 442 | isGuomi="gm" in fiscoVersion 443 | if (isGuomi and encryptType != '1'): 444 | raise Exception("config's encryptType CONFLICTS with existed [guomi] chain") 445 | elif ((isGuomi == False) and encryptType == '1'): 446 | raise Exception("config's encryptType CONFLICTS with existed [ecdsa] chain") 447 | else: 448 | print ('check encrypt type finished.') 449 | return 450 | print ('check encrypt type finished.') 451 | 452 | def checkExitedChainVersion(fisco_ver_str): 453 | print ("check version...") 454 | webase_front_ver_str = getCommProperties("webase.front.version") 455 | checkVersionUtil(fisco_ver_str,webase_front_ver_str) 456 | print ("check version finished.") 457 | 458 | def checkExistChainConnect(): 459 | print ("check connection...") 460 | listenIp = getCommProperties("node.listenIp") 461 | rpcPort = getCommProperties("node.rpcPort") 462 | ifLink = do_telnet(listenIp,rpcPort) 463 | if not ifLink: 464 | print ('Exist chain listen ip:{} port:{} is disconnected, please confirm.'.format(listenIp, rpcPort)) 465 | sys.exit(0) 466 | print ("check connection finished.") 467 | return 468 | 469 | def dockerCheckDb(): 470 | print ("============== checking mysql ==============") 471 | docker_mysql = int(getCommProperties("docker.mysql")) 472 | # use docker and also use docker mysql 473 | if docker_mysql == 0: 474 | checkMgrDbConnect() 475 | checkSignDbConnect() 476 | checkMgrDbAuthorized() 477 | checkSignDbAuthorized() 478 | checkMgrDbVersion() 479 | checkSignDbVersion() 480 | else: 481 | print ("use [mysql in docker], skip check mysql") 482 | print ("============== mysql available ==============") 483 | 484 | if __name__ == '__main__': 485 | pass 486 | -------------------------------------------------------------------------------- /deploy/comm/docker.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | # encoding: utf-8 3 | 4 | import sys 5 | import os 6 | import time 7 | from .utils import * 8 | from .mysql import * 9 | 10 | baseDir = getBaseDir() 11 | currentDir = getCurrentBaseDir() 12 | dockerDir = currentDir + "/docker" 13 | serverWaitTime = 5 14 | 15 | 16 | def installDockerAll(): 17 | configDockerAll() 18 | checkDbExist() 19 | startDockerCompose() 20 | 21 | 22 | def startDockerCompose(): 23 | # check docker-compose 24 | os.chdir(dockerDir) 25 | doCmd("docker-compose up -d") 26 | print ("start docker container success!") 27 | 28 | def stopDockerCompose(): 29 | os.chdir(dockerDir) 30 | doCmd("docker-compose down") 31 | # restart by [docker-compose stop, docker-compose start, docker-compose restart] 32 | 33 | def statusFisco(): 34 | # check docker-compose 35 | doCmd("docker ps | grep fiscobcos") 36 | 37 | def statusWebase(): 38 | # check docker-compose 39 | doCmd("docker-compose ps") 40 | 41 | 42 | def pullDockerComposeImages(): 43 | print("use [vi /etc/docker/daemon.json] to alter your docker image repository source") 44 | # check docker deamon.json 45 | timeout=60 46 | info = "60" 47 | if sys.version_info.major == 2: 48 | info = raw_input("Exec [docker pull] command to get images, please type in timeout seconds, example: [30/60/120]: ") 49 | else: 50 | info = input("Exec [docker pull] command to get images, please type in timeout seconds, example: [30/60/120]: ") 51 | if info.isdigit(): 52 | timeout=int(info) 53 | else: 54 | raise Exception("input [timeout] number of {} not validate, must be digit number!".format(info)) 55 | print ("start pull docker images of fiscobcos, mysql and WeBASE...") 56 | # pull fisco bcos node 57 | # version ex: 2.8.0, required add v as v2.8.0 58 | node_version = getCommProperties("fisco.version") 59 | fisco_repo = "fiscoorg/fiscobcos:v" + node_version 60 | if not checkDockerImageExist(fisco_repo): 61 | print("now pull docker image of {}".format(fisco_repo)) 62 | result = doCmdTimeout("docker pull {}".format(fisco_repo), timeout) 63 | # if code is not zero, throw exception 64 | # if code is zero, success or timeout 65 | if result["status"] == 0 and result["output"] == "timeout": 66 | print("[ERROR] pull image of [{}] timeout, please manually pull".format(fisco_repo)) 67 | else: 68 | print("pull docker image of {} success".format(fisco_repo)) 69 | 70 | # pull mysql 71 | docker_mysql = int(getCommProperties("docker.mysql")) 72 | if docker_mysql == 1: 73 | mysql_repo_name = "mysql:5.6" 74 | if not checkDockerImageExist(mysql_repo_name): 75 | print("now pull docker image of {}".format(mysql_repo_name)) 76 | result = doCmdTimeout("docker pull {}".format(mysql_repo_name), timeout) 77 | # if code is not zero, throw exception 78 | # if code is zero, success or timeout 79 | if result["status"] == 0 and result["output"] == "timeout": 80 | print("[ERROR] pull image of [{}] timeout, please manually pull".format(mysql_repo_name)) 81 | else: 82 | print("pull docker image of {} success".format(mysql_repo_name)) 83 | else: 84 | print("not using docker mysql, skip pull mysql:5.6") 85 | 86 | front_version = getCommProperties("webase.front.version") 87 | mgr_version = getCommProperties("webase.mgr.version") 88 | sign_version = getCommProperties("webase.sign.version") 89 | web_version = getCommProperties("webase.web.version") 90 | 91 | pullSingleImage("webase-front", front_version, timeout) 92 | pullSingleImage("webase-node-mgr", mgr_version, timeout) 93 | pullSingleImage("webase-sign", sign_version, timeout) 94 | pullSingleImage("webase-web", web_version, timeout) 95 | print ("Successfully pull!") 96 | 97 | # image_name: webase-front 98 | # image_ver: v1.5.3 99 | def pullSingleImage(image_name,image_ver,timeout): 100 | # ex: webasepro/webase-front:v1.5.3 101 | repo_with_ver = "webasepro/" + image_name + ":" + image_ver 102 | if not checkDockerImageExist(repo_with_ver): 103 | print("now pull docker image of {}".format(repo_with_ver)) 104 | result = doCmdTimeout("docker pull {}".format(repo_with_ver), timeout) 105 | # if code is not zero, throw exception 106 | # if code is zero, success or timeout 107 | if result["status"] == 0 and result["output"] == "timeout": 108 | print("[ERROR] pull image of [{}] timeout, please manually pull".format(repo_with_ver)) 109 | else: 110 | print("pull docker image of {} success".format(repo_with_ver)) 111 | 112 | 113 | def configDockerAll(): 114 | # in deploy.py dir 115 | os.chdir(currentDir) 116 | doCmdIgnoreException("chmod u+x ./docker/script/*.sh") 117 | doCmdIgnoreException("dos2unix ./docker/script/*.sh") 118 | # init default template yaml 119 | if not os.path.exists(dockerDir + "/docker-compose-temp.yaml"): 120 | doCmd('cp -f {}/docker-compose.yaml {}/docker-compose-temp.yaml'.format(dockerDir, dockerDir)) 121 | else: 122 | doCmd('cp -f {}/docker-compose-temp.yaml {}/docker-compose.yaml'.format(dockerDir, dockerDir)) 123 | 124 | # config nginx.conf 125 | configWeb() 126 | # update yaml of each service 127 | updateYamlMysql() 128 | updateYamlSign() 129 | updateYamlFront() 130 | updateYamlMgr() 131 | updateYamlWeb() 132 | 133 | # run after config yaml 134 | def checkDbExist(): 135 | # if docker mysql 136 | # check mysql file, then docker-compose up mysql 137 | # use pymysql to drop db 138 | docker_mysql = int(getCommProperties("docker.mysql")) 139 | if docker_mysql == 1: 140 | # check mysql files 141 | print ("check database if exist in [docker mysql]") 142 | if os.path.exists("{}/mysql/data/webasesign".format(currentDir)) or os.path.exists("{}/mysql/data/webasenodemanager".format(currentDir)): 143 | # start 144 | doCmd("docker-compose -f docker/docker-compose.yaml up -d mysql") 145 | print ("checking...") 146 | timeTemp = 0 147 | while timeTemp < serverWaitTime : 148 | print(".", end='') 149 | sys.stdout.flush() 150 | time.sleep(1) 151 | timeTemp = timeTemp + 1 152 | # sleep until mysql is on 153 | dropDockerDb("webasesign") 154 | dropDockerDb("webasenodemanager") 155 | # end 156 | print ("ending check [docker mysql]...") 157 | doCmd("docker-compose -f docker/docker-compose.yaml stop mysql") 158 | else: 159 | print ("check database if exist in mysql...") 160 | checkAndDropSignDb() 161 | checkAndDropMgrDb() 162 | print ("end check mysql databases") 163 | 164 | 165 | ###### mysql config ###### 166 | # update mysql/node-mgr/sign configuration 167 | def updateYamlMysql(): 168 | print ("update mysql configuration in yaml") 169 | # set root's password 170 | docker_mysql = int(getCommProperties("docker.mysql")) 171 | if docker_mysql == 1: 172 | print ("using [mysql in docker] mode") 173 | docker_mysql_port = getCommProperties("docker.mysql.port") 174 | docker_mysql_pwd = getCommProperties("docker.mysql.password") 175 | mysql_data_dir = currentDir + "/mysql/data" 176 | # update mysql docker 177 | doCmd('sed -i "s:23306:{}:g" {}/docker-compose.yaml'.format(docker_mysql_port, dockerDir)) 178 | doCmd('sed -i "s:123456:{}:g" {}/docker-compose.yaml'.format(docker_mysql_pwd, dockerDir)) 179 | doCmd('sed -i "s:/webase-deploy/mysql/data:{}:g" {}/docker-compose.yaml'.format(mysql_data_dir, dockerDir)) 180 | # mgr docker 181 | doCmd('sed -i "s:mgrDbIp:127.0.0.1:g" {}/docker-compose.yaml'.format(dockerDir)) 182 | doCmd('sed -i "s:mgrDbPort:{}:g" {}/docker-compose.yaml'.format(docker_mysql_port, dockerDir)) 183 | doCmd('sed -i "s:mgrDefaultAccount:root:g" {}/docker-compose.yaml'.format(dockerDir)) 184 | doCmd('sed -i "s:mgrDefaultPassword:{}:g" {}/docker-compose.yaml'.format(docker_mysql_pwd, dockerDir)) 185 | # sign docker 186 | doCmd('sed -i "s:signDbIp:127.0.0.1:g" {}/docker-compose.yaml'.format(dockerDir)) 187 | doCmd('sed -i "s:signDbPort:{}:g" {}/docker-compose.yaml'.format(docker_mysql_port, dockerDir)) 188 | doCmd('sed -i "s:signDefaultAccount:root:g" {}/docker-compose.yaml'.format(dockerDir)) 189 | doCmd('sed -i "s:signDefaultPassword:{}:g" {}/docker-compose.yaml'.format(docker_mysql_pwd, dockerDir)) 190 | else: 191 | print ("using [mysql in host] mode") 192 | ## not use mysql docker, read configured mysql of node-mgr and sign 193 | # disable mysql docker 194 | doCmd('sed -i "s:# entrypoint:entrypoint:g" {}/docker-compose.yaml'.format(dockerDir)) 195 | 196 | ### set mgr ip port 197 | # checkMgrDb 198 | mgr_mysql_ip = getCommProperties("mysql.ip") 199 | if mgr_mysql_ip == 'localhost': 200 | mgr_mysql_ip = '127.0.0.1' 201 | mgr_mysql_port = getCommProperties("mysql.port") 202 | mgr_mysql_user = getCommProperties("mysql.user") 203 | mgr_mysql_password = getCommProperties("mysql.password") 204 | mgr_mysql_database = getCommProperties("mysql.database") 205 | doCmd('sed -i "s:webasenodemanager:{}:g" {}/docker-compose.yaml'.format(mgr_mysql_database, dockerDir)) 206 | doCmd('sed -i "s:mgrDbIp:{}:g" {}/docker-compose.yaml'.format(mgr_mysql_ip, dockerDir)) 207 | doCmd('sed -i "s:mgrDbPort:{}:g" {}/docker-compose.yaml'.format(mgr_mysql_port, dockerDir)) 208 | doCmd('sed -i "s:mgrDefaultAccount:{}:g" {}/docker-compose.yaml'.format(mgr_mysql_user, dockerDir)) 209 | doCmd('sed -i "s:mgrDefaultPassword:{}:g" {}/docker-compose.yaml'.format(mgr_mysql_password, dockerDir)) 210 | 211 | sign_mysql_ip = getCommProperties("sign.mysql.ip") 212 | if sign_mysql_ip == 'localhost': 213 | sign_mysql_ip = '127.0.0.1' 214 | sign_mysql_port = getCommProperties("sign.mysql.port") 215 | sign_mysql_user = getCommProperties("sign.mysql.user") 216 | sign_mysql_password = getCommProperties("sign.mysql.password") 217 | sign_mysql_database = getCommProperties("sign.mysql.database") 218 | doCmd('sed -i "s:webasesign:{}:g" {}/docker-compose.yaml'.format(sign_mysql_database, dockerDir)) 219 | doCmd('sed -i "s:signDbIp:{}:g" {}/docker-compose.yaml'.format(sign_mysql_ip, dockerDir)) 220 | doCmd('sed -i "s:signDbPort:{}:g" {}/docker-compose.yaml'.format(sign_mysql_port, dockerDir)) 221 | doCmd('sed -i "s:signDefaultAccount:{}:g" {}/docker-compose.yaml'.format(sign_mysql_user, dockerDir)) 222 | doCmd('sed -i "s:signDefaultPassword:{}:g" {}/docker-compose.yaml'.format(sign_mysql_password, dockerDir)) 223 | 224 | print ("end mysql configuration in yaml") 225 | 226 | 227 | def updateYamlFront(): 228 | print ("update webase-front configuration in yaml") 229 | front_dir = currentDir + "/webase-front" 230 | front_version = getCommProperties("webase.front.version") 231 | front_port = getCommProperties("front.port") 232 | channel_ip = getCommProperties("node.listenIp") 233 | channel_port = getCommProperties("node.channelPort") 234 | front_db = getCommProperties("front.h2.name") 235 | sign_port = getCommProperties("sign.port") 236 | 237 | # config node path and sdk path 238 | if_exist_fisco = getCommProperties("if.exist.fisco") 239 | fisco_dir = getCommProperties("fisco.dir") 240 | node_relative_dir = getCommProperties("node.dir") 241 | node_dir = fisco_dir + "/" + node_relative_dir 242 | if if_exist_fisco == "no": 243 | fisco_dir = currentDir + "/nodes/127.0.0.1" 244 | node_dir = currentDir + "/nodes/127.0.0.1/node0" 245 | sdk_dir = fisco_dir + "/sdk" 246 | 247 | doCmd('sed -i "s/5002/{}/g" {}/docker-compose.yaml'.format(front_port, dockerDir)) 248 | doCmd('sed -i "s/webasefront/{}/g" {}/docker-compose.yaml'.format(front_db, dockerDir)) 249 | doCmd('sed -i "s/webase-front:v0.0.2/webase-front:{}/g" {}/docker-compose.yaml'.format(front_version, dockerDir)) 250 | doCmd('sed -i "s/sdkIp/{}/g" {}/docker-compose.yaml'.format(channel_ip, dockerDir)) 251 | doCmd('sed -i "s/sdkChannelPort/{}/g" {}/docker-compose.yaml'.format(channel_port, dockerDir)) 252 | doCmd('sed -i "s/signIpPort/127.0.0.1:{}/g" {}/docker-compose.yaml'.format(sign_port, dockerDir)) 253 | doCmd('sed -i "s:/webase-deploy/webase-front:{}:g" {}/docker-compose.yaml'.format(front_dir, dockerDir)) 254 | # doCmd('sed -i "s:frontNodePath:{}:g" {}/docker-compose.yaml'.format(node_dir, dockerDir)) 255 | doCmd('sed -i "s:/webase-deploy/nodes/127.0.0.1/sdk:{}:g" {}/docker-compose.yaml'.format(sdk_dir, dockerDir)) 256 | print ("end webase-front configuration in yaml") 257 | 258 | 259 | def updateYamlMgr(): 260 | print ("update webase-node-mgr configuration in yaml") 261 | mgr_version = getCommProperties("webase.mgr.version") 262 | mgr_port = getCommProperties("mgr.port") 263 | encrypt_type = getCommProperties("encrypt.type") 264 | mgr_dir = currentDir + "/webase-node-mgr" 265 | doCmd('sed -i "s:/webase-deploy/webase-node-mgr:{}:g" {}/docker-compose.yaml'.format(mgr_dir, dockerDir)) 266 | doCmd('sed -i "s/webase-node-mgr:v0.0.2/webase-node-mgr:{}/g" {}/docker-compose.yaml'.format(mgr_version, dockerDir)) 267 | doCmd('sed -i "s/5001/{}/g" {}/docker-compose.yaml'.format(mgr_port, dockerDir)) 268 | doCmd('sed -i "s/mgrEncryptType/{}/g" {}/docker-compose.yaml'.format(encrypt_type, dockerDir)) 269 | print ("end webase-node-mgr configuration in yaml") 270 | 271 | 272 | def updateYamlSign(): 273 | print ("update webase-sign configuration in yaml") 274 | sign_version = getCommProperties("webase.sign.version") 275 | sign_port = getCommProperties("sign.port") 276 | sign_dir = currentDir + "/webase-sign" 277 | doCmd('sed -i "s:/webase-deploy/webase-sign:{}:g" {}/docker-compose.yaml'.format(sign_dir, dockerDir)) 278 | doCmd('sed -i "s/webase-sign:v0.0.2/webase-sign:{}/g" {}/docker-compose.yaml'.format(sign_version, dockerDir)) 279 | doCmd('sed -i "s/5004/{}/g" {}/docker-compose.yaml'.format(sign_port, dockerDir)) 280 | print ("end webase-sign configuration in yaml") 281 | 282 | 283 | 284 | def updateYamlWeb(): 285 | print ("update webase-web configuration in yaml") 286 | web_version = getCommProperties("webase.web.version") 287 | web_port = getCommProperties("web.port") 288 | web_dir = currentDir + "/webase-web" 289 | doCmd('sed -i "s:/webase-deploy/webase-web:{}:g" {}/docker-compose.yaml'.format(web_dir, dockerDir)) 290 | doCmd('sed -i "s/webase-web:v0.0.2/webase-web:{}/g" {}/docker-compose.yaml'.format(web_version, dockerDir)) 291 | doCmd('sed -i "s/5000/{}/g" {}/docker-compose.yaml'.format(web_port, dockerDir)) 292 | print ("end webase-web configuration in yaml") 293 | 294 | 295 | ###### webase-web config ###### 296 | def configWeb(): 297 | print ("configure nginx.conf file of webase-web") 298 | # dir of webase-web 299 | web_conf_dir = currentDir + "/comm" 300 | web_dir = currentDir + "/webase-web" 301 | web_log_dir = web_dir + "/log" 302 | 303 | # copy nginx-docker.conf 304 | doCmd('mkdir -p {}'.format(web_dir)) 305 | if not os.path.exists(web_dir + "/nginx-docker.conf"): 306 | doCmd('cp -f {}/nginx.conf {}/nginx-docker.conf'.format(web_conf_dir, web_dir)) 307 | 308 | # get properties 309 | web_port = getCommProperties("web.port") 310 | mgr_port = getCommProperties("mgr.port") 311 | # doCmd('mkdir -p {}'.format(web_log_dir)) 312 | doCmd('sed -i "s/5000/{}/g" {}/nginx-docker.conf'.format(web_port, web_dir)) 313 | doCmd('sed -i "s/server 127.0.0.1:5001/server 127.0.0.1:{}/g" {}/nginx-docker.conf'.format(mgr_port, web_dir)) 314 | ## constant dir in docker container 315 | doCmd('sed -i "s:log_path:/dist/log:g" {}/nginx-docker.conf'.format(web_dir)) 316 | doCmd('sed -i "s:pid pid_file:# pid pid_file:g" {}/nginx-docker.conf'.format(web_dir)) 317 | doCmd('sed -i "s:web_page_url:/data/webase-web/dist:g" {}/nginx-docker.conf'.format(web_dir)) 318 | ## todo docker mode not support h5 mobile version of webase-web 319 | # set mobile phone phone_page_url globally 320 | doCmd('sed -i "s:phone_page_url:/data/webase-web/dist:g" {}/nginx-docker.conf'.format(web_dir)) 321 | print ("end nginx configuration") 322 | 323 | 324 | ## check mysql in docker exsit and drop 325 | def dropDockerDb(db2reset): 326 | log.info("dropDockerDb {}".format(db2reset)) 327 | # get properties 328 | mysql_ip = "127.0.0.1" 329 | mysql_user = "root" 330 | mysql_port = int(getCommProperties("docker.mysql.port")) 331 | mysql_password_raw = getCommProperties("docker.mysql.password") 332 | mysql_password = parse.unquote_plus(mysql_password_raw) 333 | try: 334 | # connect 335 | conn = mdb.connect(host=mysql_ip, port=mysql_port, user=mysql_user, passwd=mysql_password, charset='utf8') 336 | conn.autocommit(1) 337 | cursor = conn.cursor() 338 | 339 | # check db 340 | result = cursor.execute('show databases like "%s"' %db2reset) 341 | drop_db = 'DROP DATABASE IF EXISTS {}'.format(db2reset) 342 | if result == 1: 343 | info = "n" 344 | if sys.version_info.major == 2: 345 | info = raw_input("database of [{}] already exists. Do you want drop and recreate it?[y/n]:".format(db2reset)) 346 | else: 347 | info = input("database of [{}] already exists. Do you want drop and recreate it?[y/n]:".format(db2reset)) 348 | if info == "y" or info == "Y": 349 | log.info(drop_db) 350 | cursor.execute(drop_db) 351 | cursor.close() 352 | conn.close() 353 | except: 354 | import traceback 355 | log.info(" mysql except {}".format(traceback.format_exc())) 356 | traceback.print_exc() 357 | sys.exit(0) 358 | 359 | 360 | def checkAndDropMgrDb(): 361 | # get properties 362 | mysql_ip = getCommProperties("mysql.ip") 363 | mysql_port = int(getCommProperties("mysql.port")) 364 | mysql_user = getCommProperties("mysql.user") 365 | mysql_password_raw = getCommProperties("mysql.password") 366 | mysql_password = parse.unquote_plus(mysql_password_raw) 367 | mysql_database = getCommProperties("mysql.database") 368 | 369 | try: 370 | # connect 371 | conn = mdb.connect(host=mysql_ip, port=mysql_port, user=mysql_user, passwd=mysql_password, charset='utf8') 372 | conn.autocommit(1) 373 | cursor = conn.cursor() 374 | 375 | # check db 376 | result = cursor.execute('show databases like "%s"' %mysql_database) 377 | drop_db = 'DROP DATABASE IF EXISTS {}'.format(mysql_database) 378 | if result == 1: 379 | info = "n" 380 | if sys.version_info.major == 2: 381 | info = raw_input("WeBASE-Node-Manager database {} already exists. Do you want drop and re-initialize it?[y/n]:".format(mysql_database)) 382 | else: 383 | info = input("WeBASE-Node-Manager database {} already exists. Do you want drop and re-initialize it?[y/n]:".format(mysql_database)) 384 | if info == "y" or info == "Y": 385 | log.info(drop_db) 386 | cursor.execute(drop_db) 387 | cursor.close() 388 | conn.close() 389 | except: 390 | import traceback 391 | log.info(" mysql except {}".format(traceback.format_exc())) 392 | traceback.print_exc() 393 | sys.exit(0) 394 | 395 | def checkAndDropSignDb(): 396 | # get properties 397 | mysql_ip = getCommProperties("sign.mysql.ip") 398 | mysql_port = int(getCommProperties("sign.mysql.port")) 399 | mysql_user = getCommProperties("sign.mysql.user") 400 | mysql_password_raw = getCommProperties("sign.mysql.password") 401 | mysql_password = parse.unquote_plus(mysql_password_raw) 402 | mysql_database = getCommProperties("sign.mysql.database") 403 | try: 404 | # connect 405 | conn = mdb.connect(host=mysql_ip, port=mysql_port, user=mysql_user, passwd=mysql_password, charset='utf8') 406 | conn.autocommit(1) 407 | cursor = conn.cursor() 408 | 409 | # check db 410 | result = cursor.execute('show databases like "%s"' %mysql_database) 411 | drop_db = 'DROP DATABASE IF EXISTS {}'.format(mysql_database) 412 | if result == 1: 413 | info = "n" 414 | if sys.version_info.major == 2: 415 | info = raw_input("WeBASE-Sign database {} already exists. Do you want drop and recreate it?[y/n]:".format(mysql_database)) 416 | else: 417 | info = input("WeBASE-Sign database {} already exists. Do you want drop and recreate it?[y/n]:".format(mysql_database)) 418 | if info == "y" or info == "Y": 419 | log.info(drop_db) 420 | cursor.execute(drop_db) 421 | cursor.close() 422 | conn.close() 423 | except: 424 | import traceback 425 | log.info(" mysql except {}".format(traceback.format_exc())) 426 | traceback.print_exc() 427 | sys.exit(0) 428 | 429 | --------------------------------------------------------------------------------