mirror of
https://github.com/EvernodeXRPL/hp-devkit.git
synced 2026-04-29 15:37:58 +00:00
Naming
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
#!/bin/bash
|
||||
globalprefix="hpdevkit"
|
||||
global_prefix="hpdevkit"
|
||||
imgname="evernodedev/hotpocket:latest-ubt.20.04-njs.16"
|
||||
volmount="/devkitvol"
|
||||
|
||||
command=$1
|
||||
cluster="${HP_CLUSTER:-default}"
|
||||
volume="${globalprefix}_${cluster}_vol"
|
||||
network="${globalprefix}_${cluster}_net"
|
||||
containerprefix="${globalprefix}_${cluster}_con"
|
||||
volume="${global_prefix}_${cluster}_vol"
|
||||
network="${global_prefix}_${cluster}_net"
|
||||
container_prefix="${global_prefix}_${cluster}_con"
|
||||
|
||||
echo "Hot Pocket development toolkit"
|
||||
|
||||
@@ -21,7 +21,7 @@ fi
|
||||
|
||||
[ -z $cluster ] && echo "Cluster name not specified." && exit 1
|
||||
|
||||
function validatenodenumarg {
|
||||
function validate_node_num_arg {
|
||||
! [ "$1" -eq "$1" ] 2> /dev/null && echo "Arg must be a number." && return 1
|
||||
[ $1 -le 0 ] && echo "Arg must be 1 or higher." && return 1
|
||||
return 0
|
||||
@@ -36,20 +36,20 @@ function exists {
|
||||
fi
|
||||
}
|
||||
|
||||
function clusterexists {
|
||||
if exists "volume" $volume || exists "network" $network || exists "container" $containerprefix ; then
|
||||
function cluster_exists {
|
||||
if exists "volume" $volume || exists "network" $network || exists "container" $container_prefix ; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function getcontainercount {
|
||||
docker ps -a | grep $containerprefix | wc -l
|
||||
function get_container_count {
|
||||
docker ps -a | grep $container_prefix | wc -l
|
||||
}
|
||||
|
||||
function createcluster {
|
||||
clusterexists && echo "Cluster '$cluster' already exists." && exit 1
|
||||
function create_cluster {
|
||||
cluster_exists && echo "Cluster '$cluster' already exists." && exit 1
|
||||
docker volume create $volume
|
||||
docker network create $network
|
||||
|
||||
@@ -59,58 +59,58 @@ function createcluster {
|
||||
docker run --rm --mount type=volume,src=$volume,dst=$volmount --rm $imgname new $volmount/node$i
|
||||
|
||||
# Create container for hot pocket instance.
|
||||
local containername="${containerprefix}_$i"
|
||||
docker container create --name $containername --privileged --mount type=volume,src=$volume,dst=$volmount $imgname run $volmount/node$i
|
||||
local container_name="${container_prefix}_$i"
|
||||
docker container create --name $container_name --privileged --mount type=volume,src=$volume,dst=$volmount $imgname run $volmount/node$i
|
||||
done
|
||||
}
|
||||
|
||||
function destroycluster {
|
||||
! clusterexists && echo "Cluster '$cluster' does not exist." && exit 1
|
||||
function destroy_cluster {
|
||||
! cluster_exists && echo "Cluster '$cluster' does not exist." && exit 1
|
||||
|
||||
echo "action: stop"
|
||||
changeclusterstatus "stop"
|
||||
change_cluster_status "stop"
|
||||
|
||||
# Delete top-most matching container N times.
|
||||
# (This is just in case there are gaps in container numbering due to any tampering by user)
|
||||
echo "action: delete"
|
||||
local containercount=$(getcontainercount)
|
||||
for ((i=1; i<=$containercount; i++));
|
||||
local container_count=$(get_container_count)
|
||||
for ((i=1; i<=$container_count; i++));
|
||||
do
|
||||
local containername="$(docker ps -a --format "{{.Names}}" | grep $containerprefix | head -1)"
|
||||
docker container rm $containername
|
||||
local container_name="$(docker ps -a --format "{{.Names}}" | grep $container_prefix | head -1)"
|
||||
docker container rm $container_name
|
||||
done
|
||||
|
||||
exists "volume" $volume && docker volume rm $volume
|
||||
exists "network" $network && docker network rm $network
|
||||
}
|
||||
|
||||
function changeclusterstatus {
|
||||
! clusterexists && echo "Cluster '$cluster' does not exist." && exit 1
|
||||
function change_cluster_status {
|
||||
! cluster_exists && echo "Cluster '$cluster' does not exist." && exit 1
|
||||
|
||||
local containercount=$(getcontainercount)
|
||||
for ((i=1; i<=$containercount; i++));
|
||||
local container_count=$(get_container_count)
|
||||
for ((i=1; i<=$container_count; i++));
|
||||
do
|
||||
local containername="${containerprefix}_$i"
|
||||
docker $1 $containername
|
||||
local container_name="${container_prefix}_$i"
|
||||
docker $1 $container_name
|
||||
done
|
||||
}
|
||||
|
||||
function attachlogs {
|
||||
! clusterexists && echo "Cluster '$cluster' does not exist." && exit 1
|
||||
local containername="${containerprefix}_$1"
|
||||
docker logs -f --tail=5 $containername
|
||||
function attach_logs {
|
||||
! cluster_exists && echo "Cluster '$cluster' does not exist." && exit 1
|
||||
local container_name="${container_prefix}_$1"
|
||||
docker logs -f --tail=5 $container_name
|
||||
}
|
||||
|
||||
if [ $command = "create" ]; then
|
||||
! validatenodenumarg $2 && echo "Usage: create <node count>" && exit 1
|
||||
createcluster $2
|
||||
! validate_node_num_arg $2 && echo "Usage: create <node count>" && exit 1
|
||||
create_cluster $2
|
||||
elif [ $command = "destroy" ]; then
|
||||
destroycluster
|
||||
destroy_cluster
|
||||
elif [ $command = "start" ]; then
|
||||
changeclusterstatus start
|
||||
change_cluster_status start
|
||||
elif [ $command = "stop" ]; then
|
||||
changeclusterstatus stop
|
||||
change_cluster_status stop
|
||||
elif [ $command = "logs" ]; then
|
||||
! validatenodenumarg $2 && echo "Usage: logs <node id>" && exit 1
|
||||
attachlogs $2
|
||||
! validate_node_num_arg $2 && echo "Usage: logs <node id>" && exit 1
|
||||
attach_logs $2
|
||||
fi
|
||||
Reference in New Issue
Block a user