Skip to content

Commit

Permalink
Merge pull request #120 from andkononykhin/deployment-improvements
Browse files Browse the repository at this point in the history
improves setup docs
  • Loading branch information
ashcherbakov committed Dec 7, 2021
2 parents 6a78538 + 29a09f2 commit d564c57
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 58 deletions.
95 changes: 56 additions & 39 deletions deployment/scripts/run_dcl_node
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ export PATH="$PATH:/usr/bin"
SCRIPT_PATH="$(readlink -f "$0")"
BASEDIR="$(dirname "$SCRIPT_PATH")"

# TODO DOC dcld.service and other files in the current directory
# TODO errors to stderr
# TODO optionally fetch dcld, dclcli and dcld.service from GitHub release
#
# TODO
# - check wherther ip6 and domain names in persistent-peers work
# - do not show private data
# - requries 'dclcli keys' adjustment, pipes configuration is not an option

SERVICE_FILE="./dcld.service"
PERSISTENT_PEERS_FILE='./persistent_peers.txt'
Expand All @@ -44,13 +47,6 @@ DEF_NODE_TYPE="validator"
DEF_CHAIN_ID="testnet"
DEF_NODE_USER="ubuntu"

# NODE_TYPE="${1:-validator}"
# NODE_NAME="$2"
# KEY_NAME="${3:-${NODE_NAME}admin}"
# CHAIN_ID="${4:-testnet}"
# NODE_USER="${5:-ubuntu}"
# PEER="${5:-}"

verbosity=0
NODE_NAME=
KEY_NAME=
Expand All @@ -70,7 +66,7 @@ Initializes DCL node of a given type.
Options:
-c, --chain-id chain id, default: '$DEF_CHAIN_ID'
-h, --help print this help and exit
-k, --key-name account key-name, default: '<node-name>admin'
-k, --key-name account key-name, default: '<node-name>-admin'
-u, --user node service user, default: '$DEF_NODE_USER'
-t, --type node type, one of 'genesis', 'validator', 'observer', default: '$DEF_NODE_TYPE'
"
Expand All @@ -97,7 +93,6 @@ function parse_args {
# exit 2
#fi

# TODO why eval here
eval set -- "$_getopt_res"

while true; do
Expand Down Expand Up @@ -153,7 +148,7 @@ function parse_args {
NODE_NAME="$1"

if [[ -z "$KEY_NAME" ]]; then
KEY_NAME="${NODE_NAME}admin"
KEY_NAME="${NODE_NAME}-admin"
fi

if [[ "$NODE_TYPE" == "genesis" ]]; then
Expand Down Expand Up @@ -250,28 +245,27 @@ function config_node {

sed -i -r 's~^laddr = "tcp://127.0.0.1:~laddr = "tcp://0.0.0.0:~' "$CONFIG_FILE"

# FIXME verify
if [[ -n "$_peers" ]]; then
sed -i -r "s~^persistent_peers = .*~persistent_peers = \"$_peers\"~" "$CONFIG_FILE"
fi

if [[ -z "$_debug" ]]; then
# config the service
# Ubuntu only
grep -q -i -e 'ubuntu' /etc/*-release && {
test -d "/etc/systemd/system" && {
if [[ ! -f "$_dcld_service_p" ]]; then
echo "Error. '$_dcld_service_p' file not found"
exit 1
fi

# TODO move ot a separate script
# Open '26656' (p2p) and '26657' (RPC) ports.
sudo ufw allow 26656/tcp
sudo ufw allow 26657/tcp
# sudo ufw allow 26656/tcp
# sudo ufw allow 26657/tcp

# set systemd dcld.service
sed -i -r "s~^User=ubuntu$~User=${NODE_USER}~" "$_dcld_service_p"
sudo cp -f "$_dcld_service_p" /etc/systemd/system/dcld.service
} || { echo "Warning: Not an Ubuntu system. Skipping systemd service configuration";}
} || { echo "WARNING: Not a systemd system. Skipping systemd service configuration";}
fi
}

Expand All @@ -283,13 +277,12 @@ function run_node {
local _debug="${DEBUG:-}"

if [[ -z "$_debug" ]]; then
# Ubuntu only
grep -q -i -e 'ubuntu' /etc/*-release && {
test -d "/etc/systemd/system" && {
# Enable the service
sudo systemctl enable dcld
# Start node
sudo systemctl start dcld
} || { echo "Warning: Not an Ubuntu system. Skipping service start..."; return 0; }
} || { echo "WARNING: Not a systemd system. Skipping service start..."; return 0; }

echo "Node has been stared as a service."

Expand All @@ -302,6 +295,25 @@ function run_node {
}


function wait_node_up {
local _timeout="${1:-5}"
local _try=1

echo -e "Waiting the node becomes up"
until dclcli status >/dev/null 2>&1
do
if [[ "$_try" -gt "$_timeout" ]]; then
echo -e "\nERROR: dcld node seems not ready after $_timeout seconds."
return 1
fi
echo -n "."
_try=$(( $_try + 1 ))
sleep 1
done
echo -e "\n\tNode is responding"
}


function verify_node {
set -eu
set -o pipefail
Expand Down Expand Up @@ -401,7 +413,6 @@ node_init "$NODE_NAME" "$CHAIN_ID"
if [[ "$NODE_TYPE" == "genesis" ]]; then
echo "Building genesis file"
build_genesis "$KEY_NAME" "$ACC_ADDR" "$ACC_PUBKEY"
# TODO copy to the current directory
else
echo "Locating the genesis file at $GENESIS_FILE"
cp -f "$GENESIS_IN_FILE" "$GENESIS_FILE"
Expand All @@ -415,35 +426,41 @@ echo -e "\nOptionally, edit '$CONFIG_FILE' in order to set different setting (li
echo "Running the node"
run_node

if [[ "$NODE_TYPE" == "validator" ]]; then
VAL_ADDR="$(dcld tendermint show-address)"
VAL_PUBKEY="$(dcld tendermint show-validator)"
VAL_ID="unknown"
wait_node_up && VAL_ID="$(dclcli status | grep '"id"' | awk -F'"' '{print $4}')"

VAL_ADDR="$(dcld tendermint show-address)"
VAL_PUBKEY="$(dcld tendermint show-validator)"

echo "Done"

echo "Done"
echo -e "\n====================================\n"

echo -e "\n====================================\n"
echo "Generated data:"
echo -e "\n\tAccount data:"
echo -e "\t\tkey name: '$KEY_NAME'"
echo -e "\t\taddress: '$ACC_ADDR'"
echo -e "\t\tpublic key: '$ACC_PUBKEY'"
echo -e "\n\tValidator node data:"
echo -e "\t\tname: '$NODE_NAME'"
echo -e "\t\taddress: '$VAL_ADDR'"
echo -e "\t\tpublic key: '$VAL_PUBKEY'"
echo -e "\t\tID: '$VAL_ID'"

echo "Generated data:"
echo -e "\tAccount data:"
echo -e "\t\taddress: '$ACC_ADDR'"
echo -e "\t\tpublic key: '$ACC_PUBKEY'"
echo -e "\tValidator node data:"
echo -e "\t\taddress: '$VAL_ADDR'"
echo -e "\t\tpublic key: '$VAL_PUBKEY'"
if [[ "$NODE_TYPE" == "genesis" ]]; then
echo -e "\n\tGenesis file: '$GENESIS_FILE'"

elif [[ "$NODE_TYPE" == "validator" ]]; then
echo -e "\nNext steps:"
echo -e "\t1. Share generated account addres and pubkey to any 'Trustee' to create an account with 'NodeAdmin' role."
echo -e "\t(e.g. dclcli tx auth propose-add-account --address=$ACC_ADDR --pubkey=$ACC_PUBKEY --roles=NodeAdmin --from=<signer>)"
echo -e "\n\t2 Once the account is approved, please run the following command to make the node a validator:"
echo -e "\n\t2. Once the account is approved, please run the following command to make the node a validator:"
echo -e "\t\t'dclcli tx validator add-node --validator-address=$VAL_ADDR --validator-pubkey=$VAL_PUBKEY --name=$NODE_NAME --from=$KEY_NAME'"

echo -e "\n\t3. Explore the node external IP and provide it along with validator ID '$VAL_ID'"
echo -e "\t\t to DCLedger '$CHAIN_ID' network validator administrators"

fi

echo "Done"


# useful commands
# - keys:
# dclcli keys show <name>: to get address and oubkey for a ketname
Expand Down
25 changes: 25 additions & 0 deletions deployment/scripts/update_peers
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
# Copyright 2020 DSR Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu
set -o pipefail

CONFIG_FILE="$HOME/.dcld/config/config.toml"
PERSISTENT_PEERS_FILE="${1:-./persistent_peers.txt}"
PERSISTENT_PEERS="$(cat $PERSISTENT_PEERS_FILE | head -n1)"

sed -i -r "s~^persistent_peers = .*~persistent_peers = \"$PERSISTENT_PEERS\"~" "$CONFIG_FILE"

echo "Updated"
Loading

0 comments on commit d564c57

Please sign in to comment.