Skip to content

Commit dcc0e81

Browse files
Set SRD ratio tools (#121)
* set srd ratio * fix error * fix error
1 parent 19bfef4 commit dcc0e81

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

scripts/crust.sh

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,8 @@ Crust tools usage:
764764
workload show workload information
765765
file-info {cid} show all files information or one file details
766766
upgrade-image {chain|api|smanager|ipfs|c-gen|sworker} upgrade one docker image
767-
change-srd {number} change sworker's srd capacity(GB), for example: 'crust tools change-srd 100', 'crust tools change-srd -50'
767+
set-srd-ratio {ratio} set SRD raito, default is 70%, range is 0% - 95%, for example 'set-srd-ratio 75'
768+
change-srd {number} change sworker's srd capacity(GB), for example: 'change-srd 100', 'change-srd -50'
768769
ipfs {...} ipfs command, for example 'ipfs pin ls', 'ipfs swarm peers'
769770
EOF
770771
}
@@ -839,6 +840,39 @@ change_srd()
839840
curl -XPOST ''$base_url'/srd/change' -H 'backup: '$backup'' --data-raw '{"change" : '$1'}'
840841
}
841842

843+
set_srd_ratio()
844+
{
845+
if [ x"$1" == x"" ] || [[ ! $1 =~ ^[1-9][0-9]*$|^[-][1-9][0-9]*$|^0$ ]]; then
846+
log_err "The input of set srd ratio must be integer number"
847+
tools_help
848+
return 1
849+
fi
850+
851+
if [ $1 -lt 0 ] || [ $1 -gt 95 ]; then
852+
log_err "The range of set srd ratio is 0 ~ 95"
853+
tools_help
854+
return 1
855+
fi
856+
857+
local a_or_b=`cat $basedir/etc/sWorker.ab`
858+
check_docker_status crust-sworker-$a_or_b
859+
if [ $? -ne 0 ]; then
860+
log_info "Service crust sworker is not started or exited now"
861+
return 0
862+
fi
863+
864+
if [ ! -f "$builddir/sworker/sworker_config.json" ]; then
865+
log_err "No sworker configuration file"
866+
return 1
867+
fi
868+
869+
local base_url=`cat $builddir/sworker/sworker_config.json | jq .base_url`
870+
base_url=${base_url%?}
871+
base_url=${base_url:1}
872+
873+
curl -XPOST ''$base_url'/srd/ratio' -H 'backup: '$backup'' --data-raw '{"ratio" : '$1'}'
874+
}
875+
842876
workload()
843877
{
844878
local a_or_b=`cat $basedir/etc/sWorker.ab`
@@ -931,6 +965,9 @@ tools()
931965
change-srd)
932966
change_srd $2
933967
;;
968+
set-srd-ratio)
969+
set_srd_ratio $2
970+
;;
934971
rotate-keys)
935972
rotate_keys
936973
;;

scripts/utils.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function log_success()
1717

1818
function log_err()
1919
{
20-
echo_c 35 "$1"
20+
echo_c 35 "ERROR: $1"
2121
}
2222

2323
function upgrade_docker_image()

0 commit comments

Comments
 (0)