Skip to content

Commit

Permalink
SRD change command line (#66)
Browse files Browse the repository at this point in the history
* swoker srd change cmd

* get base url from config
  • Loading branch information
LowEntropyBody committed Sep 27, 2020
1 parent 59b5a94 commit 35e2d73
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion generator/config-gen/api-config.gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
async function genApiConfig(config, outputCfg) {
const apiConfig = {
port: 56666,
chain_ws_url: `ws://127.0.0.1:${config.chain.ws_port}`,
chain_ws_url: `ws://127.0.0.1:19944`,
}
return {
config: apiConfig,
Expand Down
61 changes: 61 additions & 0 deletions scripts/crust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ Usage:
reload {chain|sworker|karst} reload all service or reload one service
logs {chain|api|sworker|karst} track service logs, ctrl-c to exit
sworker {...} use 'crust sworker help' for more details
EOF
}

Expand All @@ -382,6 +383,62 @@ check_docker_status()
return 1
fi
}

sworker_help()
{
cat << EOF
sWorker usage:
help show help information
srd-change {number} change sworker's srd capacity(GB), for example: 'crust sworker srd-change 100', 'crust sworker srd-change -50'
EOF
}

sworker_srd_change()
{
if [ x"$1" == x"" ] || [[ ! $1 =~ ^[1-9][0-9]*$|^[-][1-9][0-9]*$|^0$ ]]; then
log_err "The input of srd change must be integer number"
return 1
fi

if [ x"$1" == x"0" ]; then
log_err "Srd change number can't be zero"
return 1
fi

local a_or_b=`cat $basedir/etc/sWorker.ab`
check_docker_status crust-sworker-$a_or_b
if [ $? -ne 0 ]; then
log_info "Service crust sworker is not started or exited now"
return 0
fi

if [ ! -f "$builddir/sworker/sworker_config.json" ]; then
log_err "No sworker configuration file"
return 1
fi

local backup=`cat $builddir/sworker/sworker_config.json | jq .chain.backup`
backup=${backup//\\/}
backup=${backup%?}
backup=${backup:1}

local base_url=`cat $builddir/sworker/sworker_config.json | jq .base_url`
base_url=${base_url%?}
base_url=${base_url:1}

curl -XPOST ''$base_url'/srd/change' -H 'backup: '$backup'' --data-raw '{"change" : '$1'}'
}

sworker()
{
case "$1" in
srd-change)
sworker_srd_change $2
;;
*)
sworker_help
esac
}

case "$1" in
start)
Expand All @@ -399,6 +456,10 @@ case "$1" in
logs)
logs $2
;;
sworker)
shift
sworker $@
;;
*)
help
esac
Expand Down

0 comments on commit 35e2d73

Please sign in to comment.