From 2bedd7c08e53cf69e26eb755f2fbb638779f7744 Mon Sep 17 00:00:00 2001 From: Yang Zhao Date: Tue, 15 Sep 2020 14:24:44 +0800 Subject: [PATCH 1/8] remove path and port --- config.yaml | 21 --------------------- generator/config-gen/api-config.gen.js | 4 ++-- generator/config-gen/chain-config.gen.js | 14 +++++++------- generator/config-gen/karst-config.gen.js | 14 +++++++------- generator/config-gen/sworker-config.gen.js | 21 ++++++--------------- generator/schema/api.schema.js | 9 --------- generator/schema/index.js | 1 - 7 files changed, 22 insertions(+), 62 deletions(-) delete mode 100644 generator/schema/api.schema.js diff --git a/config.yaml b/config.yaml index f76089e..c125678 100644 --- a/config.yaml +++ b/config.yaml @@ -16,40 +16,19 @@ identity: ## chain configurations chain: - ## chain data will be saved in this path, need absolute path - base_path: "/opt/crust/data/chain" ## the name of chain node name: "vnode" - ## the port - port: 30333 - ## the rpc port - rpc_port: 9933 - ## the ws port - ws_port: 9944 - -## api configurations -api: - ## the port - port: 56666 ## sworker configurations sworker: - ## sworker base data will be saved in this path, need absolute path - base_path: "/opt/crust/data/sworker" ## the srd data will be saved in those paths, need absolute path srd_paths: - "/opt/crust/data/sworker/srd1" - "/opt/crust/data/sworker/srd2" ## the number of srd in GB, input must be an integer greater than 0 srd_init_capacity: 1 - ## the port - port: 12222 ## karst configurations karst: - ## karst data will be saved in this path, need absolute path - base_path: "/opt/crust/data/karst" ## the thacker address tracker_addrs: "127.0.0.1:22122" - ## the port - port: 17000 diff --git a/generator/config-gen/api-config.gen.js b/generator/config-gen/api-config.gen.js index c9079a4..03c0203 100644 --- a/generator/config-gen/api-config.gen.js +++ b/generator/config-gen/api-config.gen.js @@ -1,7 +1,7 @@ async function genApiConfig(config, outputCfg) { const apiConfig = { - ...config.api, + port: 56666, chain_ws_url: `ws://127.0.0.1:${config.chain.ws_port}`, } return { @@ -12,7 +12,7 @@ async function genApiConfig(config, outputCfg) { async function genApiComposeConfig(config) { const args = [ - `${config.api.port}`, + '56666', `ws://127.0.0.1:${config.chain.ws_port}`, ].join(' ') return { diff --git a/generator/config-gen/chain-config.gen.js b/generator/config-gen/chain-config.gen.js index aa25a29..d5e050e 100644 --- a/generator/config-gen/chain-config.gen.js +++ b/generator/config-gen/chain-config.gen.js @@ -14,17 +14,17 @@ async function genChainComposeConfig(config) { let args = [ './crust', '--base-path', - `${config.chain.base_path}`, + '/opt/crust/data/chain', '--chain', 'maxwell', '--port', - `${config.chain.port}`, + 30333, '--name', `${config.chain.name}`, '--rpc-port', - `${config.chain.rpc_port}`, + 9933, '--ws-port', - `${config.chain.ws_port}`, + 9944, ] if (config.node.chain == "authority") { @@ -37,7 +37,7 @@ async function genChainComposeConfig(config) { image: 'crustio/crust:latest', network_mode: 'host', volumes: [ - `${config.chain.base_path}:${config.chain.base_path}` + '/opt/crust/data/chain:/opt/crust/data/chain' ], command: args, } @@ -46,7 +46,7 @@ async function genChainComposeConfig(config) { function getSharedChainConfig(config) { return { ...config.identity, - base_url: `http://127.0.0.1:${config.api.port}/api/v1`, + base_url: `http://127.0.0.1:56666/api/v1`, address: config.identity.backup.address, account_id: config.identity.account_id, backup: JSON.stringify(config.identity.backup), @@ -56,7 +56,7 @@ function getSharedChainConfig(config) { function getSharedChainConfigForKarst(config) { return { ...config.identity, - base_url: `127.0.0.1:${config.api.port}`, + base_url: `127.0.0.1:56666`, address: config.identity.backup.address, backup: JSON.stringify(config.identity.backup), } diff --git a/generator/config-gen/karst-config.gen.js b/generator/config-gen/karst-config.gen.js index 658786a..7b83cfc 100644 --- a/generator/config-gen/karst-config.gen.js +++ b/generator/config-gen/karst-config.gen.js @@ -3,12 +3,12 @@ const { getSharedChainConfigForKarst } = require('./chain-config.gen') async function genKarstConfig(config, outputCfg) { const karstConfig = { - base_path: config.karst.base_path, - port: config.karst.port, + base_path: '/opt/crust/data/karst', + port: 17000, debug: true, crust: getSharedChainConfigForKarst(config), sworker: { - base_url: `127.0.0.1:${config.sworker.port}` + base_url: `127.0.0.1:12222` }, file_system: { fastdfs: { @@ -19,9 +19,9 @@ async function genKarstConfig(config, outputCfg) { } } } - const basePaths = _.isEmpty(config.karst.base_path) ? [] : [{ + const basePaths = [{ required: true, - path: config.karst.base_path, + path: '/opt/crust/data/karst', }] return { config: karstConfig, @@ -30,8 +30,8 @@ async function genKarstConfig(config, outputCfg) { } async function genKarstComposeConfig(config) { - const basePath = _.isEmpty(config.karst.base_path) ? '/home/crust/crust/karst' : config.karst.base_path - const baseVolume = _.isEmpty(config.karst.base_path) ? [] : [ `${basePath}:${basePath}` ] + const basePath = '/opt/crust/data/karst' + const baseVolume =[ `${basePath}:${basePath}` ] return { image: 'crustio/karst:latest', diff --git a/generator/config-gen/sworker-config.gen.js b/generator/config-gen/sworker-config.gen.js index 74a2494..b4877de 100644 --- a/generator/config-gen/sworker-config.gen.js +++ b/generator/config-gen/sworker-config.gen.js @@ -1,17 +1,11 @@ const _ = require('lodash') -const { createDir, writeConfig, } = require('../utils') const { getSharedChainConfig } = require('./chain-config.gen') async function genSworkerConfig(config, outputCfg) { - karstPort = 17000 - if (config.karst) { - karstPort = config.karst.port - } - const sworkerConfig = { ..._.omit(config.sworker, ['port']), - base_url: `http://0.0.0.0:${config.sworker.port}/api/v0`, - karst_url: `ws://127.0.0.1:${karstPort}/api/v0/node/data`, + base_url: `http://0.0.0.0:12222/api/v0`, + karst_url: `ws://127.0.0.1:17000/api/v0/node/data`, chain: getSharedChainConfig(config), } const srdPaths = _.map(config.sworker.srdPaths, (p) => ({ @@ -22,7 +16,7 @@ async function genSworkerConfig(config, outputCfg) { config: sworkerConfig, paths: [{ required: true, - path: config.sworker.base_path, + path: '/opt/crust/data/sworker', }, ...srdPaths], } } @@ -32,15 +26,12 @@ async function genSworkerComposeConfig(config) { .map((p) => `${p}:${p}`) let tempVolumes = [ - `${config.sworker.base_path}:${config.sworker.base_path}`, + '/opt/crust/data/sworker:/opt/crust/data/sworker', ...srdVolumes, - './sworker:/config' + './sworker:/config', + '/opt/crust/data/karst:/opt/crust/data/karst' ] - if (config.karst) { - tempVolumes.push(`${config.karst.base_path}:${config.karst.base_path}`) - } - return { image: 'crustio/crust-sworker:latest', network_mode: 'host', diff --git a/generator/schema/api.schema.js b/generator/schema/api.schema.js deleted file mode 100644 index 21cba5e..0000000 --- a/generator/schema/api.schema.js +++ /dev/null @@ -1,9 +0,0 @@ -const Joi = require('joi') - -const apiSchema = Joi.object({ - port: Joi.number().port().default(56666), -}) - -module.exports = { - apiSchema, -} diff --git a/generator/schema/index.js b/generator/schema/index.js index 1753b64..e97b736 100644 --- a/generator/schema/index.js +++ b/generator/schema/index.js @@ -16,7 +16,6 @@ function getConfigSchema(config) { if (config.node.sworker != "enable") { return Joi.object(sMap) } - sMap["api"] = apiSchema.required() sMap["identity"] = identitySchema.required() sMap["sworker"] = sworkerSchema.required() From 8eb4853ae51f5600570b3e0b4ed95c13ac64b83e Mon Sep 17 00:00:00 2001 From: Yang Zhao Date: Tue, 15 Sep 2020 14:32:28 +0800 Subject: [PATCH 2/8] fix error --- generator/schema/chain.schema.js | 6 +----- generator/schema/index.js | 1 - generator/schema/karst.schema.js | 2 -- generator/schema/sworker.schema.js | 2 -- 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/generator/schema/chain.schema.js b/generator/schema/chain.schema.js index d4202e3..424b718 100644 --- a/generator/schema/chain.schema.js +++ b/generator/schema/chain.schema.js @@ -2,11 +2,7 @@ const Joi = require('joi') const bluebird = require('bluebird') const chainSchema = Joi.object({ - base_path: Joi.string().required(), - name: Joi.string().required(), - port: Joi.number().port().default(30333), - rpc_port: Joi.number().port().default(9933), - ws_port: Joi.number().port().default(9944), + name: Joi.string().required() }) module.exports = { diff --git a/generator/schema/index.js b/generator/schema/index.js index e97b736..46ac3a0 100644 --- a/generator/schema/index.js +++ b/generator/schema/index.js @@ -1,6 +1,5 @@ const Joi = require('joi') -const { apiSchema } = require('./api.schema') const { chainSchema } = require('./chain.schema') const { karstSchema } = require('./karst.schema') const { identitySchema } = require('./identity.schema') diff --git a/generator/schema/karst.schema.js b/generator/schema/karst.schema.js index ca5320e..be58440 100644 --- a/generator/schema/karst.schema.js +++ b/generator/schema/karst.schema.js @@ -2,9 +2,7 @@ const Joi = require('joi') const karstSchema = Joi.object({ - base_path: Joi.string().required(), tracker_addrs: Joi.string().required(), - port: Joi.number().port().default(17000), }) module.exports = { diff --git a/generator/schema/sworker.schema.js b/generator/schema/sworker.schema.js index 4c779bd..3c89f6c 100644 --- a/generator/schema/sworker.schema.js +++ b/generator/schema/sworker.schema.js @@ -2,10 +2,8 @@ const Joi = require('joi') const sworkerSchema = Joi.object({ - base_path: Joi.string().required(), srd_paths: Joi.array().items(Joi.string()).required(), srd_init_capacity: Joi.number().positive().integer().default(1), - port: Joi.number().port().default(12222), }) module.exports = { From 9627fe40fa851eb2bbf2db00fef99f24ab6a29aa Mon Sep 17 00:00:00 2001 From: Yang Zhao Date: Tue, 15 Sep 2020 15:10:45 +0800 Subject: [PATCH 3/8] remove light --- config.yaml | 2 +- generator/config-gen/chain-config.gen.js | 2 -- generator/schema/node.schema.js | 2 +- scripts/crust.sh | 12 ++++++++++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/config.yaml b/config.yaml index c125678..52668bf 100644 --- a/config.yaml +++ b/config.yaml @@ -1,6 +1,6 @@ ## node configurations node: - ## the type of crust, for example: authority, full, light + ## the type of crust, for example: authority, full chain: "authority" ## enable or disable sworker sworker: "enable" diff --git a/generator/config-gen/chain-config.gen.js b/generator/config-gen/chain-config.gen.js index d5e050e..63483e7 100644 --- a/generator/config-gen/chain-config.gen.js +++ b/generator/config-gen/chain-config.gen.js @@ -29,8 +29,6 @@ async function genChainComposeConfig(config) { if (config.node.chain == "authority") { args.push('--validator', '--pruning', 'archive') - } else if (config.node.chain == "light") { - args.push('--light') } return { diff --git a/generator/schema/node.schema.js b/generator/schema/node.schema.js index 55cde0f..b7043e0 100644 --- a/generator/schema/node.schema.js +++ b/generator/schema/node.schema.js @@ -1,7 +1,7 @@ const Joi = require('joi') const nodeSchema = Joi.object({ - chain: Joi.string().valid('authority', 'full', 'light').required(), + chain: Joi.string().valid('authority', 'full').required(), sworker: Joi.string().valid('enable', 'disable').required(), karst: Joi.string().valid('enable', 'disable').required(), }) diff --git a/scripts/crust.sh b/scripts/crust.sh index e6f5e20..7b987fd 100755 --- a/scripts/crust.sh +++ b/scripts/crust.sh @@ -7,6 +7,8 @@ builddir=$basedir/build start() { echo "Start" + check_port 30333 && check_port 9933 && check_port 9944 + $scriptdir/gen_config.sh if [ $? -ne 0 ]; then echo "Generate configuration files failed" @@ -28,6 +30,8 @@ start() fi if [ -d "$builddir/sworker" ]; then + check_port 56666 && check_port 12222 && check_port 17000 + docker-compose -f $builddir/docker-compose.yaml up -d crust-api if [ $? -ne 0 ]; then echo "Start crust-api failed" @@ -62,6 +66,14 @@ reload() { stop start } + +check_port() { + port=$1 + grep_port=`netstat -tlpn | grep "\b$port\b"` + if [ -n "$grep_port" ]; then + echo "Please make sure port $port is not occupied" + fi +} case "$1" in start) From 74472f667704d679dcadb0687e356bd205d453c8 Mon Sep 17 00:00:00 2001 From: Yang Zhao Date: Tue, 15 Sep 2020 15:25:00 +0800 Subject: [PATCH 4/8] fix number error --- generator/config-gen/chain-config.gen.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/generator/config-gen/chain-config.gen.js b/generator/config-gen/chain-config.gen.js index 63483e7..4ddd4af 100644 --- a/generator/config-gen/chain-config.gen.js +++ b/generator/config-gen/chain-config.gen.js @@ -18,13 +18,13 @@ async function genChainComposeConfig(config) { '--chain', 'maxwell', '--port', - 30333, + '30333', '--name', `${config.chain.name}`, '--rpc-port', - 9933, + '9933', '--ws-port', - 9944, + '9944', ] if (config.node.chain == "authority") { From b51b2a1a45199bdf1397c4c5340f097b45daec3f Mon Sep 17 00:00:00 2001 From: Yang Zhao Date: Tue, 15 Sep 2020 15:41:49 +0800 Subject: [PATCH 5/8] fix api error --- generator/config-gen/api-config.gen.js | 2 +- generator/schema/index.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/generator/config-gen/api-config.gen.js b/generator/config-gen/api-config.gen.js index 03c0203..ea3fef3 100644 --- a/generator/config-gen/api-config.gen.js +++ b/generator/config-gen/api-config.gen.js @@ -13,7 +13,7 @@ async function genApiConfig(config, outputCfg) { async function genApiComposeConfig(config) { const args = [ '56666', - `ws://127.0.0.1:${config.chain.ws_port}`, + `ws://127.0.0.1:9944`, ].join(' ') return { image: 'crustio/crust-api:latest', diff --git a/generator/schema/index.js b/generator/schema/index.js index 46ac3a0..fe1fd7f 100644 --- a/generator/schema/index.js +++ b/generator/schema/index.js @@ -15,6 +15,7 @@ function getConfigSchema(config) { if (config.node.sworker != "enable") { return Joi.object(sMap) } + sMap["api"] = Joi.object().default() sMap["identity"] = identitySchema.required() sMap["sworker"] = sworkerSchema.required() From 0f23d3a0ddd60f4c3893f08b24b15be6e8c5ac16 Mon Sep 17 00:00:00 2001 From: Yang Zhao Date: Tue, 15 Sep 2020 16:01:13 +0800 Subject: [PATCH 6/8] check karst folder --- README.md | 3 ++- scripts/crust.sh | 10 +++++----- scripts/karst.sh | 7 +++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9998ffd..5707723 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,11 @@ sudo ./install.sh sudo vim /opt/crust/crust-node/config.yaml ``` -### Run crust service +### Run crust service and karst service ```shell sudo systemctl start crust +sudo systemctl start karst ``` ## License diff --git a/scripts/crust.sh b/scripts/crust.sh index 7b987fd..7b5dfbf 100755 --- a/scripts/crust.sh +++ b/scripts/crust.sh @@ -68,11 +68,11 @@ reload() { } check_port() { - port=$1 - grep_port=`netstat -tlpn | grep "\b$port\b"` - if [ -n "$grep_port" ]; then - echo "Please make sure port $port is not occupied" - fi + port=$1 + grep_port=`netstat -tlpn | grep "\b$port\b"` + if [ -n "$grep_port" ]; then + echo "Please make sure port $port is not occupied" + fi } case "$1" in diff --git a/scripts/karst.sh b/scripts/karst.sh index 55b2c8e..b86d37a 100755 --- a/scripts/karst.sh +++ b/scripts/karst.sh @@ -7,13 +7,13 @@ builddir=$basedir/build start() { echo "Start" - $scriptdir/gen_config.sh + $scriptdir/gen_config.sh if [ $? -ne 0 ]; then echo "Generate configuration files failed" exit 1 fi - if [ ! -d "$builddir/sworker" ]; then + if [ ! -d "$builddir/sworker" ]; then echo "No sworker" exit 1 fi @@ -24,6 +24,9 @@ start() echo "Start karst failed" exit 1 fi + else + echo "Please enable karst in /opt/crust/crust-node/config.yaml" + exit 1 fi } From 79ee7f52fdf7dd298a3f7e5614478f73302c1511 Mon Sep 17 00:00:00 2001 From: Yang Zhao Date: Tue, 15 Sep 2020 16:21:16 +0800 Subject: [PATCH 7/8] exit when error --- scripts/crust.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/crust.sh b/scripts/crust.sh index 7b5dfbf..2a1f20b 100755 --- a/scripts/crust.sh +++ b/scripts/crust.sh @@ -7,7 +7,9 @@ builddir=$basedir/build start() { echo "Start" - check_port 30333 && check_port 9933 && check_port 9944 + check_port 30333 + check_port 9933 + check_port 9944 $scriptdir/gen_config.sh if [ $? -ne 0 ]; then @@ -30,10 +32,13 @@ start() fi if [ -d "$builddir/sworker" ]; then - check_port 56666 && check_port 12222 && check_port 17000 + check_port 56666 + check_port 12222 + check_port 17000 docker-compose -f $builddir/docker-compose.yaml up -d crust-api if [ $? -ne 0 ]; then + docker-compose -f $builddir/docker-compose.yaml rm -fsv crust echo "Start crust-api failed" exit 1 fi @@ -41,6 +46,8 @@ start() a_or_b=`cat $basedir/etc/sWorker.ab` docker-compose -f $builddir/docker-compose.yaml up -d crust-sworker-$a_or_b if [ $? -ne 0 ]; then + docker-compose -f $builddir/docker-compose.yaml rm -fsv crust + docker-compose -f $builddir/docker-compose.yaml rm -fsv crust-api echo "Start crust-sworker-$a_or_b failed" exit 1 fi @@ -72,6 +79,7 @@ check_port() { grep_port=`netstat -tlpn | grep "\b$port\b"` if [ -n "$grep_port" ]; then echo "Please make sure port $port is not occupied" + exit 1 fi } From 971689a5fbc6fb2db35f8b9bebbc13bfcfa3d290 Mon Sep 17 00:00:00 2001 From: Yang Zhao Date: Tue, 15 Sep 2020 16:36:36 +0800 Subject: [PATCH 8/8] update readme --- README.md | 5 +++++ generator/schema/index.js | 2 +- scripts/crust.sh | 8 +------- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5707723..34fb510 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,11 @@ sudo vim /opt/crust/crust-node/config.yaml ``` ### Run crust service and karst service +Please make sure the following ports are not occupied before startingļ¼š +- 30333 9933 9944 (for crust chain) +- 56666 (for crust API) +- 12222 (for crust sWorker) +- 17000 (for karst) ```shell sudo systemctl start crust diff --git a/generator/schema/index.js b/generator/schema/index.js index fe1fd7f..34b5380 100644 --- a/generator/schema/index.js +++ b/generator/schema/index.js @@ -7,7 +7,7 @@ const { sworkerSchema } = require('./sworker.schema') const { nodeSchema } = require('./node.schema') function getConfigSchema(config) { - sMap = { + let sMap = { node: nodeSchema.required(), chain: chainSchema.required(), } diff --git a/scripts/crust.sh b/scripts/crust.sh index 2a1f20b..0f74c3d 100755 --- a/scripts/crust.sh +++ b/scripts/crust.sh @@ -7,9 +7,7 @@ builddir=$basedir/build start() { echo "Start" - check_port 30333 - check_port 9933 - check_port 9944 + check_port 30333 && check_port 9933 && check_port 9944 && check_port 56666 && check_port 12222 && check_port 17000 $scriptdir/gen_config.sh if [ $? -ne 0 ]; then @@ -32,10 +30,6 @@ start() fi if [ -d "$builddir/sworker" ]; then - check_port 56666 - check_port 12222 - check_port 17000 - docker-compose -f $builddir/docker-compose.yaml up -d crust-api if [ $? -ne 0 ]; then docker-compose -f $builddir/docker-compose.yaml rm -fsv crust