diff --git a/config.yaml b/config.yaml index 3131222..80a11e7 100644 --- a/config.yaml +++ b/config.yaml @@ -4,6 +4,8 @@ node: chain: "authority" ## enable or disable sworker sworker: "enable" + ## enable or disable smanager + smanager: "disable" ## enable or disable ipfs ipfs: "disable" diff --git a/generator/Dockerfile b/generator/Dockerfile index 6b5c8f0..7a99c97 100644 --- a/generator/Dockerfile +++ b/generator/Dockerfile @@ -1,7 +1,7 @@ FROM "node:12-buster" RUN apt-get update && apt-get install -y wget -RUN wget https://github.com/paritytech/substrate/releases/download/v2.0.0-rc4/subkey -O /usr/local/bin/subkey +RUN wget https://github.com/paritytech/substrate/releases/download/v2.0.0-rc6/subkey -O /usr/local/bin/subkey RUN chmod +x /usr/local/bin/subkey ENV KEY_TOOL /usr/local/bin/subkey diff --git a/generator/config-gen/index.js b/generator/config-gen/index.js index 5b6d8ee..c5c8dd9 100644 --- a/generator/config-gen/index.js +++ b/generator/config-gen/index.js @@ -4,6 +4,7 @@ const path = require('path') const { createDir, writeConfig, } = require('../utils') const { genApiConfig, genApiComposeConfig } = require('./api-config.gen') +const { genSmanagerConfig, genSmanagerComposeConfig } = require('./smanager-config.gen') const { genIpfsConfig, genIpfsComposeConfig } = require('./ipfs-config.gen') const { genChainConfig, genChainComposeConfig } = require('./chain-config.gen') const { genSworkerConfig, genSworkerComposeConfig } = require('./sworker-config.gen') @@ -47,6 +48,12 @@ const configGenerators = [{ to: path.join('sworker', 'sworker_config.json'), composeName: 'crust-sworker-b', composeFunc: genSworkerComposeConfig, +}, { + name: 'smanager', + configFunc: genSmanagerConfig, + to: path.join('smanager', 'smanager_config.json'), + composeName: 'crust-smanager', + composeFunc: genSmanagerComposeConfig, }, { name: 'ipfs', configFunc: genIpfsConfig, diff --git a/generator/config-gen/smanager-config.gen.js b/generator/config-gen/smanager-config.gen.js new file mode 100644 index 0000000..3d86238 --- /dev/null +++ b/generator/config-gen/smanager-config.gen.js @@ -0,0 +1,33 @@ +async function genSmanagerConfig(config, outputCfg) { + const smanagerConfig = { + chain_addr: 'ws://127.0.0.1:19944', + ipfs_addr: 'http://127.0.0.1:5001', + sworker_addr: 'http://127.0.0.1:12222', + } + return { + config: smanagerConfig, + paths: [], + } + } + + async function genSmanagerComposeConfig(config) { + const args = [ + 'ws://127.0.0.1:19944', + 'http://127.0.0.1:5001', + 'http://127.0.0.1:12222', + ].join(' ') + return { + image: 'crustio/crust-smanager:latest', + network_mode: 'host', + restart: 'always', + environment: { + ARGS: args, + } + } + } + + module.exports = { + genSmanagerConfig, + genSmanagerComposeConfig, + } + \ No newline at end of file diff --git a/generator/key-utils.js b/generator/key-utils.js index 991b319..1f6b140 100644 --- a/generator/key-utils.js +++ b/generator/key-utils.js @@ -7,7 +7,7 @@ async function inspectKey(address) { if (!keyTool) { throw 'key tool path not specified' } - const {stdout} = await execa(keyTool, ['inspect', address]); + const {stdout} = await execa(keyTool, ['inspect-key', '--uri', address]); const rows = _.chain(stdout).split('\n').map(_.trim) const accountId = extractAccountId(rows) @@ -28,7 +28,7 @@ function extractAccountId(outputs) { return null } - return ids[0] + return ids[0].substring(2) } diff --git a/generator/schema/index.js b/generator/schema/index.js index b29c967..6e37cfd 100644 --- a/generator/schema/index.js +++ b/generator/schema/index.js @@ -17,6 +17,10 @@ function getConfigSchema(config) { sMap["sworker"] = sworkerSchema.required() } + if (config.node.smanager == "enable") { + sMap["smanager"] = Joi.object().default() + } + if (config.node.ipfs == "enable") { sMap["ipfs"] = Joi.object().default() } diff --git a/generator/schema/node.schema.js b/generator/schema/node.schema.js index cd969bc..a4c4841 100644 --- a/generator/schema/node.schema.js +++ b/generator/schema/node.schema.js @@ -3,6 +3,7 @@ const Joi = require('joi') const nodeSchema = Joi.object({ chain: Joi.string().valid('authority', 'full').required(), sworker: Joi.string().valid('enable', 'disable').required(), + smanager: Joi.string().valid('enable', 'disable').required(), ipfs: Joi.string().valid('enable', 'disable').required(), }) diff --git a/install.sh b/install.sh index 15a039a..440ea66 100755 --- a/install.sh +++ b/install.sh @@ -26,7 +26,7 @@ install_depenencies() fi log_info "------------Install depenencies--------------" - apt install -y git jq curl wget build-essential kmod linux-headers-`uname -r` + apt install -y git jq curl wget build-essential kmod linux-headers-`uname -r` vim if [ $? -ne 0 ]; then log_err "Install libs failed" @@ -71,6 +71,10 @@ download_docker_images() docker pull $aliyun_address/crustio/crust-sworker res=$(($?|$res)) docker tag $aliyun_address/crustio/crust-sworker crustio/crust-sworker + + docker pull $aliyun_address/crustio/crust-smanager + res=$(($?|$res)) + docker tag $aliyun_address/crustio/crust-smanager crustio/crust-smanager docker pull $aliyun_address/crustio/go-ipfs res=$(($?|$res)) @@ -82,6 +86,10 @@ download_docker_images() res=$(($?|$res)) docker pull crustio/crust-api res=$(($?|$res)) + docker pull crustio/crust-sworker + res=$(($?|$res)) + docker pull crustio/crust-smanager + res=$(($?|$res)) docker pull ipfs/go-ipfs res=$(($?|$res)) fi diff --git a/scripts/crust.sh b/scripts/crust.sh index aba6131..462db43 100755 --- a/scripts/crust.sh +++ b/scripts/crust.sh @@ -39,6 +39,12 @@ start() exit 1 fi + start_smanager + if [ $? -ne 0 ]; then + docker-compose -f $builddir/docker-compose.yaml down + exit 1 + fi + start_ipfs if [ $? -ne 0 ]; then docker-compose -f $builddir/docker-compose.yaml down @@ -51,6 +57,7 @@ start() stop() { stop_chain + stop_smanager stop_api stop_sworker stop_ipfs @@ -89,6 +96,13 @@ logs() return 0 fi docker logs -f ipfs + elif [ x"$1" == x"smanager" ]; then + check_docker_status crust-smanager + if [ $? -eq 1 ]; then + log_info "Service crust smanager is not started now" + return 0 + fi + docker logs -f crust-smanager elif [ x"$1" == x"sworker-a" ]; then check_docker_status crust-sworker-a if [ $? -eq 1 ]; then @@ -250,6 +264,34 @@ stop_api() return 0 } +start_smanager() +{ + if [ -d "$builddir/smanager" ]; then + check_docker_status crust-smanager + if [ $? -ne 1 ]; then + return 0 + fi + + docker-compose -f $builddir/docker-compose.yaml up -d crust-smanager + if [ $? -ne 0 ]; then + log_err "[ERROR] Start crust-smanager failed" + return 1 + fi + fi + return 0 +} + +stop_smanager() +{ + check_docker_status crust-smanager + if [ $? -ne 1 ]; then + log_info "Stopping crust smanager service" + docker stop crust-smanager &>/dev/null + docker rm crust-smanager &>/dev/null + fi + return 0 +} + start_ipfs() { if [ -d "$builddir/ipfs" ]; then @@ -343,6 +385,21 @@ reload() { return 0 fi + if [ x"$1" = x"smanager" ]; then + log_info "Reload smanager service" + + stop_smanager + $scriptdir/gen_config.sh + if [ $? -ne 0 ]; then + log_err "[ERROR] Generate configuration files failed" + exit 1 + fi + start_smanager + + log_success "Reload smanager service success" + return 0 + fi + if [ x"$1" = x"ipfs" ]; then log_info "Reload ipfs service" @@ -370,6 +427,8 @@ status() api_status elif [ x"$1" == x"sworker" ]; then sworker_status + elif [ x"$1" == x"smanager" ]; then + smanager_status elif [ x"$1" == x"ipfs" ]; then ipfs_status elif [ x"$1" == x"" ]; then @@ -384,6 +443,7 @@ all_status() local chain_status="stop" local api_status="stop" local sworker_status="stop" + local smanager_status="stop" local ipfs_status="stop" check_docker_status crust @@ -411,6 +471,14 @@ all_status() sworker_status="exited" fi + check_docker_status crust-smanager + res=$? + if [ $res -eq 0 ]; then + smanager_status="running" + elif [ $res -eq 2 ]; then + smanager_status="exited" + fi + check_docker_status ipfs res=$? if [ $res -eq 0 ]; then @@ -426,6 +494,7 @@ cat << EOF chain ${chain_status} api ${api_status} sworker ${sworker_status} + smanager ${smanager_status} ipfs ${ipfs_status} ----------------------------------------- EOF @@ -513,6 +582,27 @@ cat << EOF EOF } +smanager_status() +{ + local smanager_status="stop" + + check_docker_status crust-smanager + res=$? + if [ $res -eq 0 ]; then + smanager_status="running" + elif [ $res -eq 2 ]; then + smanager_status="exited" + fi + +cat << EOF +----------------------------------------- + Service Status +----------------------------------------- + smanager ${smanager_status} +----------------------------------------- +EOF +} + ipfs_status() { local ipfs_status="stop" @@ -538,14 +628,14 @@ help() { cat << EOF Usage: - help show help information - start start all crust service - stop stop all crust service - - status {chain|api|sworker|ipfs} check status or reload one service status - reload {chain|api|sworker|ipfs} reload all service or reload one service - logs {chain|api|sworker|ipfs} track service logs, ctrl-c to exit - tools {...} use 'crust tools help' for more details + help show help information + start start all crust service + stop stop all crust service + + status {chain|api|sworker|smanager|ipfs} check status or reload one service status + reload {chain|api|sworker|smanager|ipfs} reload all service or reload one service + logs {chain|api|sworker|smanager|ipfs} track service logs, ctrl-c to exit + tools {...} use 'crust tools help' for more details EOF } @@ -553,11 +643,11 @@ tools_help() { cat << EOF crust tools usage: - help show help information - rotate-keys generate session key of chain node - workload show workload information - upgrade-reload {chain|api|ipfs|c-gen} upgrade one docker image and reload the service - change-srd {number} change sworker's srd capacity(GB), for example: 'crust tools change-srd 100', 'crust tools change-srd -50' + help show help information + rotate-keys generate session key of chain node + workload show workload information + upgrade-reload {chain|api|smanager|ipfs|c-gen} upgrade one docker image and reload the service + change-srd {number} change sworker's srd capacity(GB), for example: 'crust tools change-srd 100', 'crust tools change-srd -50' EOF } @@ -644,6 +734,12 @@ upgrade_reload() return 1 fi reload api + elif [ x"$1" == x"smanager" ]; then + upgrade_docker_image crustio/crust-smanager + if [ $? -ne 0 ]; then + return 1 + fi + reload smanager elif [ x"$1" == x"ipfs" ]; then upgrade_docker_image ipfs/go-ipfs crustio/go-ipfs if [ $? -ne 0 ]; then diff --git a/scripts/install_sgx_driver.sh b/scripts/install_sgx_driver.sh index 0d0b5f3..763a07b 100755 --- a/scripts/install_sgx_driver.sh +++ b/scripts/install_sgx_driver.sh @@ -4,11 +4,11 @@ basedir=$(cd $scriptdir/..;pwd) is_16=`cat /etc/issue | grep 16.04` if [ x"$is_16" = x"" ]; then - driverbin=sgx_linux_x64_driver_2.6.0_4f5bb63.bin - driverurl=https://download.01.org/intel-sgx/sgx-linux/2.7.1/distro/ubuntu18.04-server/$driverbin + driverbin=sgx_linux_x64_driver_2.6.0_b0a445b.bin + driverurl=https://download.01.org/intel-sgx/sgx-linux/2.11/distro/ubuntu18.04-server/$driverbin else - driverbin=sgx_linux_x64_driver_2.6.0_4f5bb63.bin - driverurl=https://download.01.org/intel-sgx/sgx-linux/2.7.1/distro/ubuntu16.04-server/$driverbin + driverbin=sgx_linux_x64_driver_2.6.0_b0a445b.bin + driverurl=https://download.01.org/intel-sgx/sgx-linux/2.11/distro/ubuntu16.04-server/$driverbin fi . $scriptdir/utils.sh