diff --git a/fabric-ca/ica-bootstrap.sh b/fabric-ca/ica-bootstrap.sh index ed96dbb..c4c5d60 100644 --- a/fabric-ca/ica-bootstrap.sh +++ b/fabric-ca/ica-bootstrap.sh @@ -84,6 +84,7 @@ dowait "the docker 'ica' container to start" 60 ${SDIR}/${INT_CA_LOGFILE} ${SDIR tail -f ${SDIR}/${INT_CA_LOGFILE}& TAIL_PID=$! +sleep 5 # 等待'ica'容器执行完成 waitPort "$INT_CA_NAME to start" 90 $INT_CA_LOGFILE $INT_CA_HOST 7054 sleep 5 diff --git a/fabric-ca/orderer-bootstrap.sh b/fabric-ca/orderer-bootstrap.sh index 8a53b42..f2d3da6 100644 --- a/fabric-ca/orderer-bootstrap.sh +++ b/fabric-ca/orderer-bootstrap.sh @@ -89,6 +89,7 @@ dowait "the docker 'orderer' container to start" 60 ${SDIR}/${ORDERER_LOGFILE} $ tail -f ${SDIR}/${ORDERER_LOGFILE}& TAIL_PID=$! +sleep 5 # 等待'orderer'容器执行完成 # Usage: waitPort waitPort "Orderer $ORDERER_HOST to start" 90 $ORDERER_LOGFILE $ORDERER_HOST 7050 diff --git a/fabric-ca/peer-bootstrap.sh b/fabric-ca/peer-bootstrap.sh index 3c376d4..13eca0d 100644 --- a/fabric-ca/peer-bootstrap.sh +++ b/fabric-ca/peer-bootstrap.sh @@ -94,6 +94,7 @@ dowait "the docker 'peer' container to start" 60 ${SDIR}/${PEER_LOGFILE} ${SDIR} tail -f ${SDIR}/${PEER_LOGFILE}& TAIL_PID=$! +sleep 5 # 等待'peer'容器执行完成 # Usage: waitPort waitPort "Peer $PEER_HOST to start" 1800 $PEER_LOGFILE $PEER_HOST 7051 diff --git a/fabric-ca/rca-bootstrap.sh b/fabric-ca/rca-bootstrap.sh index 57b6676..5eb4310 100644 --- a/fabric-ca/rca-bootstrap.sh +++ b/fabric-ca/rca-bootstrap.sh @@ -73,6 +73,7 @@ dowait "the docker 'rca' container to start" 60 ${SDIR}/${ROOT_CA_LOGFILE} ${SDI tail -f ${SDIR}/${ROOT_CA_LOGFILE}& TAIL_PID=$! +sleep 5 # 等待'rca'容器执行完成 waitPort "$ROOT_CA_NAME to start" 90 $ROOT_CA_LOGFILE $ROOT_CA_HOST 7054 sleep 5 diff --git a/fabric-ca/scripts/upgrade_cc.sh b/fabric-ca/scripts/install_cc.sh similarity index 72% rename from fabric-ca/scripts/upgrade_cc.sh rename to fabric-ca/scripts/install_cc.sh index 6845f26..12628d9 100644 --- a/fabric-ca/scripts/upgrade_cc.sh +++ b/fabric-ca/scripts/install_cc.sh @@ -32,15 +32,19 @@ done shift $opts if [ $# -lt 5 ]; then - echo "Usage: upgrade_cc.sh <-o > <-n > " + echo "Usage: upgrade_cc.sh <-o > <-n > []" + echo "Eg, ./install_cc.sh -u -o org0 -n 1 org1 1 mycc 1.1 github.com/hyperledger/fabric-web/chaincode/go/chaincode_example03 '{\"Args\":[\"init\",\"a\",\"90\",\"b\",\"210\"]}'" exit 1 fi -CC_NAME="$1" # 链码名称 -CC_VERSION="$2" # 链码版本 -CC_PATH="$3" # 链码路径 -PEER_ORG="$4" # Peer组织 -PEER_NUM="$5" # Peer节点索引 +PEER_ORG="$1" # Peer组织 +PEER_NUM="$2" # Peer节点索引 +CC_NAME="$3" # 链码名称 +CC_VERSION="$4" # 链码版本 +CC_PATH="$5" # 链码路径 +CC_CTOR="$6" # 链码的具体执行参数信息,json格式,默认为"{}" + +: ${CC_CTOR:="{}"} initOrdererVars $ORDERER_ORG $ORDERER_NUM export ORDERER_PORT_ARGS="-o $ORDERER_HOST:7050 --tls --cafile $CA_CHAINFILE --clientauth" @@ -58,7 +62,7 @@ if $CC_UPGRADE; then set -x set +e makePolicy - peer chaincode upgrade -C $CHANNEL_NAME -n $CC_NAME -v $CC_VERSION -c '{"Args":["init","a","90","b","210"]}' -P "$POLICY" $ORDERER_CONN_ARGS >&log.txt + peer chaincode upgrade -C $CHANNEL_NAME -n $CC_NAME -v $CC_VERSION -c $CC_CTOR -P "$POLICY" $ORDERER_CONN_ARGS >&log.txt res=$? set +x set -e diff --git a/fabric-ca/scripts/invoke_cc.sh b/fabric-ca/scripts/invoke_cc.sh index 0e2f7a9..6643c4f 100644 --- a/fabric-ca/scripts/invoke_cc.sh +++ b/fabric-ca/scripts/invoke_cc.sh @@ -10,10 +10,39 @@ set -e source $(dirname "$0")/env.sh -initOrdererVars org0 1 +opts=0 +while getopts "o:n:" opt; do + case "$opt" in + o) + opts=$((opts+2)) + ORDERER_ORG=$OPTARG + ;; + n) + opts=$((opts+2)) + ORDERER_NUM=$OPTARG + ;; + esac +done + +shift $opts + +if [ $# -lt 5 ]; then + echo "Usage: invoke_cc.sh <-o > <-n > " + echo "Eg, ./invoke_cc.sh -o org0 -n 1 org1 1 mycc 1.4 '{\"Args\":[\"invoke\",\"a\",\"b\",\"10\"]}'" + exit 1 +fi + +PEER_ORG="$1" # Peer组织 +PEER_NUM="$2" # Peer节点索引 +CC_NAME="$3" # 链码名称 +CC_VERSION="$4" # 链码版本 +CC_CTOR="$5" # 链码的具体执行参数信息,json格式 + +initOrdererVars $ORDERER_ORG $ORDERER_NUM export ORDERER_PORT_ARGS="-o $ORDERER_HOST:7050 --tls --cafile $CA_CHAINFILE --clientauth" -initPeerVars org2 1 +initPeerVars $PEER_ORG $PEER_NUM switchToUserIdentity -peer chaincode invoke -C mychannel -n mycc -c '{"Args":["select", "a"]}' +log "Sending invoke transaction to $PEER_HOST ..." +peer chaincode invoke -C $CHANNEL_NAME -n $CC_NAME -c $CC_CTOR $ORDERER_CONN_ARGS diff --git a/fabric-ca/setup-bootstrap.sh b/fabric-ca/setup-bootstrap.sh index 9ad8a74..3aec58a 100644 --- a/fabric-ca/setup-bootstrap.sh +++ b/fabric-ca/setup-bootstrap.sh @@ -28,12 +28,14 @@ startRun() { docker-compose up -d --no-deps run - tail -f ${SDIR}/${RUN_SUMFILE}& - TAIL_PID=$! - + sleep 5 # 等待'run'容器启动,随后tail -f run.sum dowait "the docker 'run' container to start" 60 ${SDIR}/${RUN_LOGFILE} ${SDIR}/${RUN_SUMFILE} + tail -f ${SDIR}/${RUN_SUMFILE}& + TAIL_PID=$! + sleep 5 + # 等待'run'容器执行完成 while true; do if [ -f ${SDIR}/${RUN_SUCCESS_FILE} ]; then @@ -92,15 +94,15 @@ done : ${DOWN_REMOTE_BIN:="false"} +SDIR=$(dirname "$0") +source ${SDIR}/scripts/env.sh +cd ${SDIR} + if [ $(whoami) != "root" ]; then log "Please use root to execute this sh" exit 1 fi -SDIR=$(dirname "$0") -source ${SDIR}/scripts/env.sh -cd ${SDIR} - installJQ # 校验fabric.config配置是否是合法性JSON cat fabric.config | jq . >& /dev/null