Skip to content

Commit 36bf194

Browse files
Smanager cmd (#93)
* add timeout (#85) * generate smanager config * smanager cmd * Use SGX 211 driver (#90) * use sgx 211 * add vim install * Use subkey rc6 (#91) * fix error (#92) * pull sworker * fix error
1 parent fffc534 commit 36bf194

10 files changed

+172
-21
lines changed

config.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ node:
44
chain: "authority"
55
## enable or disable sworker
66
sworker: "enable"
7+
## enable or disable smanager
8+
smanager: "disable"
79
## enable or disable ipfs
810
ipfs: "disable"
911

generator/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM "node:12-buster"
22

33
RUN apt-get update && apt-get install -y wget
4-
RUN wget https://github.com/paritytech/substrate/releases/download/v2.0.0-rc4/subkey -O /usr/local/bin/subkey
4+
RUN wget https://github.com/paritytech/substrate/releases/download/v2.0.0-rc6/subkey -O /usr/local/bin/subkey
55
RUN chmod +x /usr/local/bin/subkey
66

77
ENV KEY_TOOL /usr/local/bin/subkey

generator/config-gen/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const path = require('path')
55
const { createDir, writeConfig, } = require('../utils')
66
const { genApiConfig, genApiComposeConfig } = require('./api-config.gen')
7+
const { genSmanagerConfig, genSmanagerComposeConfig } = require('./smanager-config.gen')
78
const { genIpfsConfig, genIpfsComposeConfig } = require('./ipfs-config.gen')
89
const { genChainConfig, genChainComposeConfig } = require('./chain-config.gen')
910
const { genSworkerConfig, genSworkerComposeConfig } = require('./sworker-config.gen')
@@ -47,6 +48,12 @@ const configGenerators = [{
4748
to: path.join('sworker', 'sworker_config.json'),
4849
composeName: 'crust-sworker-b',
4950
composeFunc: genSworkerComposeConfig,
51+
}, {
52+
name: 'smanager',
53+
configFunc: genSmanagerConfig,
54+
to: path.join('smanager', 'smanager_config.json'),
55+
composeName: 'crust-smanager',
56+
composeFunc: genSmanagerComposeConfig,
5057
}, {
5158
name: 'ipfs',
5259
configFunc: genIpfsConfig,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
async function genSmanagerConfig(config, outputCfg) {
2+
const smanagerConfig = {
3+
chain_addr: 'ws://127.0.0.1:19944',
4+
ipfs_addr: 'http://127.0.0.1:5001',
5+
sworker_addr: 'http://127.0.0.1:12222',
6+
}
7+
return {
8+
config: smanagerConfig,
9+
paths: [],
10+
}
11+
}
12+
13+
async function genSmanagerComposeConfig(config) {
14+
const args = [
15+
'ws://127.0.0.1:19944',
16+
'http://127.0.0.1:5001',
17+
'http://127.0.0.1:12222',
18+
].join(' ')
19+
return {
20+
image: 'crustio/crust-smanager:latest',
21+
network_mode: 'host',
22+
restart: 'always',
23+
environment: {
24+
ARGS: args,
25+
}
26+
}
27+
}
28+
29+
module.exports = {
30+
genSmanagerConfig,
31+
genSmanagerComposeConfig,
32+
}
33+

generator/key-utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ async function inspectKey(address) {
77
if (!keyTool) {
88
throw 'key tool path not specified'
99
}
10-
const {stdout} = await execa(keyTool, ['inspect', address]);
10+
const {stdout} = await execa(keyTool, ['inspect-key', '--uri', address]);
1111

1212
const rows = _.chain(stdout).split('\n').map(_.trim)
1313
const accountId = extractAccountId(rows)
@@ -28,7 +28,7 @@ function extractAccountId(outputs) {
2828
return null
2929
}
3030

31-
return ids[0]
31+
return ids[0].substring(2)
3232
}
3333

3434

generator/schema/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ function getConfigSchema(config) {
1717
sMap["sworker"] = sworkerSchema.required()
1818
}
1919

20+
if (config.node.smanager == "enable") {
21+
sMap["smanager"] = Joi.object().default()
22+
}
23+
2024
if (config.node.ipfs == "enable") {
2125
sMap["ipfs"] = Joi.object().default()
2226
}

generator/schema/node.schema.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const Joi = require('joi')
33
const nodeSchema = Joi.object({
44
chain: Joi.string().valid('authority', 'full').required(),
55
sworker: Joi.string().valid('enable', 'disable').required(),
6+
smanager: Joi.string().valid('enable', 'disable').required(),
67
ipfs: Joi.string().valid('enable', 'disable').required(),
78
})
89

install.sh

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ install_depenencies()
2626
fi
2727

2828
log_info "------------Install depenencies--------------"
29-
apt install -y git jq curl wget build-essential kmod linux-headers-`uname -r`
29+
apt install -y git jq curl wget build-essential kmod linux-headers-`uname -r` vim
3030

3131
if [ $? -ne 0 ]; then
3232
log_err "Install libs failed"
@@ -71,6 +71,10 @@ download_docker_images()
7171
docker pull $aliyun_address/crustio/crust-sworker
7272
res=$(($?|$res))
7373
docker tag $aliyun_address/crustio/crust-sworker crustio/crust-sworker
74+
75+
docker pull $aliyun_address/crustio/crust-smanager
76+
res=$(($?|$res))
77+
docker tag $aliyun_address/crustio/crust-smanager crustio/crust-smanager
7478

7579
docker pull $aliyun_address/crustio/go-ipfs
7680
res=$(($?|$res))
@@ -82,6 +86,10 @@ download_docker_images()
8286
res=$(($?|$res))
8387
docker pull crustio/crust-api
8488
res=$(($?|$res))
89+
docker pull crustio/crust-sworker
90+
res=$(($?|$res))
91+
docker pull crustio/crust-smanager
92+
res=$(($?|$res))
8593
docker pull ipfs/go-ipfs
8694
res=$(($?|$res))
8795
fi

scripts/crust.sh

+109-13
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ start()
3939
exit 1
4040
fi
4141

42+
start_smanager
43+
if [ $? -ne 0 ]; then
44+
docker-compose -f $builddir/docker-compose.yaml down
45+
exit 1
46+
fi
47+
4248
start_ipfs
4349
if [ $? -ne 0 ]; then
4450
docker-compose -f $builddir/docker-compose.yaml down
@@ -51,6 +57,7 @@ start()
5157
stop()
5258
{
5359
stop_chain
60+
stop_smanager
5461
stop_api
5562
stop_sworker
5663
stop_ipfs
@@ -89,6 +96,13 @@ logs()
8996
return 0
9097
fi
9198
docker logs -f ipfs
99+
elif [ x"$1" == x"smanager" ]; then
100+
check_docker_status crust-smanager
101+
if [ $? -eq 1 ]; then
102+
log_info "Service crust smanager is not started now"
103+
return 0
104+
fi
105+
docker logs -f crust-smanager
92106
elif [ x"$1" == x"sworker-a" ]; then
93107
check_docker_status crust-sworker-a
94108
if [ $? -eq 1 ]; then
@@ -250,6 +264,34 @@ stop_api()
250264
return 0
251265
}
252266

267+
start_smanager()
268+
{
269+
if [ -d "$builddir/smanager" ]; then
270+
check_docker_status crust-smanager
271+
if [ $? -ne 1 ]; then
272+
return 0
273+
fi
274+
275+
docker-compose -f $builddir/docker-compose.yaml up -d crust-smanager
276+
if [ $? -ne 0 ]; then
277+
log_err "[ERROR] Start crust-smanager failed"
278+
return 1
279+
fi
280+
fi
281+
return 0
282+
}
283+
284+
stop_smanager()
285+
{
286+
check_docker_status crust-smanager
287+
if [ $? -ne 1 ]; then
288+
log_info "Stopping crust smanager service"
289+
docker stop crust-smanager &>/dev/null
290+
docker rm crust-smanager &>/dev/null
291+
fi
292+
return 0
293+
}
294+
253295
start_ipfs()
254296
{
255297
if [ -d "$builddir/ipfs" ]; then
@@ -343,6 +385,21 @@ reload() {
343385
return 0
344386
fi
345387

388+
if [ x"$1" = x"smanager" ]; then
389+
log_info "Reload smanager service"
390+
391+
stop_smanager
392+
$scriptdir/gen_config.sh
393+
if [ $? -ne 0 ]; then
394+
log_err "[ERROR] Generate configuration files failed"
395+
exit 1
396+
fi
397+
start_smanager
398+
399+
log_success "Reload smanager service success"
400+
return 0
401+
fi
402+
346403
if [ x"$1" = x"ipfs" ]; then
347404
log_info "Reload ipfs service"
348405

@@ -370,6 +427,8 @@ status()
370427
api_status
371428
elif [ x"$1" == x"sworker" ]; then
372429
sworker_status
430+
elif [ x"$1" == x"smanager" ]; then
431+
smanager_status
373432
elif [ x"$1" == x"ipfs" ]; then
374433
ipfs_status
375434
elif [ x"$1" == x"" ]; then
@@ -384,6 +443,7 @@ all_status()
384443
local chain_status="stop"
385444
local api_status="stop"
386445
local sworker_status="stop"
446+
local smanager_status="stop"
387447
local ipfs_status="stop"
388448

389449
check_docker_status crust
@@ -411,6 +471,14 @@ all_status()
411471
sworker_status="exited"
412472
fi
413473

474+
check_docker_status crust-smanager
475+
res=$?
476+
if [ $res -eq 0 ]; then
477+
smanager_status="running"
478+
elif [ $res -eq 2 ]; then
479+
smanager_status="exited"
480+
fi
481+
414482
check_docker_status ipfs
415483
res=$?
416484
if [ $res -eq 0 ]; then
@@ -426,6 +494,7 @@ cat << EOF
426494
chain ${chain_status}
427495
api ${api_status}
428496
sworker ${sworker_status}
497+
smanager ${smanager_status}
429498
ipfs ${ipfs_status}
430499
-----------------------------------------
431500
EOF
@@ -513,6 +582,27 @@ cat << EOF
513582
EOF
514583
}
515584

585+
smanager_status()
586+
{
587+
local smanager_status="stop"
588+
589+
check_docker_status crust-smanager
590+
res=$?
591+
if [ $res -eq 0 ]; then
592+
smanager_status="running"
593+
elif [ $res -eq 2 ]; then
594+
smanager_status="exited"
595+
fi
596+
597+
cat << EOF
598+
-----------------------------------------
599+
Service Status
600+
-----------------------------------------
601+
smanager ${smanager_status}
602+
-----------------------------------------
603+
EOF
604+
}
605+
516606
ipfs_status()
517607
{
518608
local ipfs_status="stop"
@@ -538,26 +628,26 @@ help()
538628
{
539629
cat << EOF
540630
Usage:
541-
help show help information
542-
start start all crust service
543-
stop stop all crust service
544-
545-
status {chain|api|sworker|ipfs} check status or reload one service status
546-
reload {chain|api|sworker|ipfs} reload all service or reload one service
547-
logs {chain|api|sworker|ipfs} track service logs, ctrl-c to exit
548-
tools {...} use 'crust tools help' for more details
631+
help show help information
632+
start start all crust service
633+
stop stop all crust service
634+
635+
status {chain|api|sworker|smanager|ipfs} check status or reload one service status
636+
reload {chain|api|sworker|smanager|ipfs} reload all service or reload one service
637+
logs {chain|api|sworker|smanager|ipfs} track service logs, ctrl-c to exit
638+
tools {...} use 'crust tools help' for more details
549639
EOF
550640
}
551641

552642
tools_help()
553643
{
554644
cat << EOF
555645
crust tools usage:
556-
help show help information
557-
rotate-keys generate session key of chain node
558-
workload show workload information
559-
upgrade-reload {chain|api|ipfs|c-gen} upgrade one docker image and reload the service
560-
change-srd {number} change sworker's srd capacity(GB), for example: 'crust tools change-srd 100', 'crust tools change-srd -50'
646+
help show help information
647+
rotate-keys generate session key of chain node
648+
workload show workload information
649+
upgrade-reload {chain|api|smanager|ipfs|c-gen} upgrade one docker image and reload the service
650+
change-srd {number} change sworker's srd capacity(GB), for example: 'crust tools change-srd 100', 'crust tools change-srd -50'
561651
EOF
562652
}
563653

@@ -644,6 +734,12 @@ upgrade_reload()
644734
return 1
645735
fi
646736
reload api
737+
elif [ x"$1" == x"smanager" ]; then
738+
upgrade_docker_image crustio/crust-smanager
739+
if [ $? -ne 0 ]; then
740+
return 1
741+
fi
742+
reload smanager
647743
elif [ x"$1" == x"ipfs" ]; then
648744
upgrade_docker_image ipfs/go-ipfs crustio/go-ipfs
649745
if [ $? -ne 0 ]; then

scripts/install_sgx_driver.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ basedir=$(cd $scriptdir/..;pwd)
44

55
is_16=`cat /etc/issue | grep 16.04`
66
if [ x"$is_16" = x"" ]; then
7-
driverbin=sgx_linux_x64_driver_2.6.0_4f5bb63.bin
8-
driverurl=https://download.01.org/intel-sgx/sgx-linux/2.7.1/distro/ubuntu18.04-server/$driverbin
7+
driverbin=sgx_linux_x64_driver_2.6.0_b0a445b.bin
8+
driverurl=https://download.01.org/intel-sgx/sgx-linux/2.11/distro/ubuntu18.04-server/$driverbin
99
else
10-
driverbin=sgx_linux_x64_driver_2.6.0_4f5bb63.bin
11-
driverurl=https://download.01.org/intel-sgx/sgx-linux/2.7.1/distro/ubuntu16.04-server/$driverbin
10+
driverbin=sgx_linux_x64_driver_2.6.0_b0a445b.bin
11+
driverurl=https://download.01.org/intel-sgx/sgx-linux/2.11/distro/ubuntu16.04-server/$driverbin
1212
fi
1313

1414
. $scriptdir/utils.sh

0 commit comments

Comments
 (0)