Skip to content

Commit d564c57

Browse files
authored
Merge pull request #120 from andkononykhin/deployment-improvements
improves setup docs
2 parents 6a78538 + 29a09f2 commit d564c57

File tree

3 files changed

+195
-58
lines changed

3 files changed

+195
-58
lines changed

deployment/scripts/run_dcl_node

+56-39
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ export PATH="$PATH:/usr/bin"
2121
SCRIPT_PATH="$(readlink -f "$0")"
2222
BASEDIR="$(dirname "$SCRIPT_PATH")"
2323

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

2831
SERVICE_FILE="./dcld.service"
2932
PERSISTENT_PEERS_FILE='./persistent_peers.txt'
@@ -44,13 +47,6 @@ DEF_NODE_TYPE="validator"
4447
DEF_CHAIN_ID="testnet"
4548
DEF_NODE_USER="ubuntu"
4649

47-
# NODE_TYPE="${1:-validator}"
48-
# NODE_NAME="$2"
49-
# KEY_NAME="${3:-${NODE_NAME}admin}"
50-
# CHAIN_ID="${4:-testnet}"
51-
# NODE_USER="${5:-ubuntu}"
52-
# PEER="${5:-}"
53-
5450
verbosity=0
5551
NODE_NAME=
5652
KEY_NAME=
@@ -70,7 +66,7 @@ Initializes DCL node of a given type.
7066
Options:
7167
-c, --chain-id chain id, default: '$DEF_CHAIN_ID'
7268
-h, --help print this help and exit
73-
-k, --key-name account key-name, default: '<node-name>admin'
69+
-k, --key-name account key-name, default: '<node-name>-admin'
7470
-u, --user node service user, default: '$DEF_NODE_USER'
7571
-t, --type node type, one of 'genesis', 'validator', 'observer', default: '$DEF_NODE_TYPE'
7672
"
@@ -97,7 +93,6 @@ function parse_args {
9793
# exit 2
9894
#fi
9995

100-
# TODO why eval here
10196
eval set -- "$_getopt_res"
10297

10398
while true; do
@@ -153,7 +148,7 @@ function parse_args {
153148
NODE_NAME="$1"
154149

155150
if [[ -z "$KEY_NAME" ]]; then
156-
KEY_NAME="${NODE_NAME}admin"
151+
KEY_NAME="${NODE_NAME}-admin"
157152
fi
158153

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

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

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

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

267260
# TODO move ot a separate script
268261
# Open '26656' (p2p) and '26657' (RPC) ports.
269-
sudo ufw allow 26656/tcp
270-
sudo ufw allow 26657/tcp
262+
# sudo ufw allow 26656/tcp
263+
# sudo ufw allow 26657/tcp
264+
271265
# set systemd dcld.service
272266
sed -i -r "s~^User=ubuntu$~User=${NODE_USER}~" "$_dcld_service_p"
273267
sudo cp -f "$_dcld_service_p" /etc/systemd/system/dcld.service
274-
} || { echo "Warning: Not an Ubuntu system. Skipping systemd service configuration";}
268+
} || { echo "WARNING: Not a systemd system. Skipping systemd service configuration";}
275269
fi
276270
}
277271

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

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

294287
echo "Node has been stared as a service."
295288

@@ -302,6 +295,25 @@ function run_node {
302295
}
303296

304297

298+
function wait_node_up {
299+
local _timeout="${1:-5}"
300+
local _try=1
301+
302+
echo -e "Waiting the node becomes up"
303+
until dclcli status >/dev/null 2>&1
304+
do
305+
if [[ "$_try" -gt "$_timeout" ]]; then
306+
echo -e "\nERROR: dcld node seems not ready after $_timeout seconds."
307+
return 1
308+
fi
309+
echo -n "."
310+
_try=$(( $_try + 1 ))
311+
sleep 1
312+
done
313+
echo -e "\n\tNode is responding"
314+
}
315+
316+
305317
function verify_node {
306318
set -eu
307319
set -o pipefail
@@ -401,7 +413,6 @@ node_init "$NODE_NAME" "$CHAIN_ID"
401413
if [[ "$NODE_TYPE" == "genesis" ]]; then
402414
echo "Building genesis file"
403415
build_genesis "$KEY_NAME" "$ACC_ADDR" "$ACC_PUBKEY"
404-
# TODO copy to the current directory
405416
else
406417
echo "Locating the genesis file at $GENESIS_FILE"
407418
cp -f "$GENESIS_IN_FILE" "$GENESIS_FILE"
@@ -415,35 +426,41 @@ echo -e "\nOptionally, edit '$CONFIG_FILE' in order to set different setting (li
415426
echo "Running the node"
416427
run_node
417428

418-
if [[ "$NODE_TYPE" == "validator" ]]; then
419-
VAL_ADDR="$(dcld tendermint show-address)"
420-
VAL_PUBKEY="$(dcld tendermint show-validator)"
429+
VAL_ID="unknown"
430+
wait_node_up && VAL_ID="$(dclcli status | grep '"id"' | awk -F'"' '{print $4}')"
431+
432+
VAL_ADDR="$(dcld tendermint show-address)"
433+
VAL_PUBKEY="$(dcld tendermint show-validator)"
421434

435+
echo "Done"
422436

423-
echo "Done"
437+
echo -e "\n====================================\n"
424438

425-
echo -e "\n====================================\n"
439+
echo "Generated data:"
440+
echo -e "\n\tAccount data:"
441+
echo -e "\t\tkey name: '$KEY_NAME'"
442+
echo -e "\t\taddress: '$ACC_ADDR'"
443+
echo -e "\t\tpublic key: '$ACC_PUBKEY'"
444+
echo -e "\n\tValidator node data:"
445+
echo -e "\t\tname: '$NODE_NAME'"
446+
echo -e "\t\taddress: '$VAL_ADDR'"
447+
echo -e "\t\tpublic key: '$VAL_PUBKEY'"
448+
echo -e "\t\tID: '$VAL_ID'"
426449

427-
echo "Generated data:"
428-
echo -e "\tAccount data:"
429-
echo -e "\t\taddress: '$ACC_ADDR'"
430-
echo -e "\t\tpublic key: '$ACC_PUBKEY'"
431-
echo -e "\tValidator node data:"
432-
echo -e "\t\taddress: '$VAL_ADDR'"
433-
echo -e "\t\tpublic key: '$VAL_PUBKEY'"
450+
if [[ "$NODE_TYPE" == "genesis" ]]; then
451+
echo -e "\n\tGenesis file: '$GENESIS_FILE'"
434452

453+
elif [[ "$NODE_TYPE" == "validator" ]]; then
435454
echo -e "\nNext steps:"
436455
echo -e "\t1. Share generated account addres and pubkey to any 'Trustee' to create an account with 'NodeAdmin' role."
437456
echo -e "\t(e.g. dclcli tx auth propose-add-account --address=$ACC_ADDR --pubkey=$ACC_PUBKEY --roles=NodeAdmin --from=<signer>)"
438-
echo -e "\n\t2 Once the account is approved, please run the following command to make the node a validator:"
457+
echo -e "\n\t2. Once the account is approved, please run the following command to make the node a validator:"
439458
echo -e "\t\t'dclcli tx validator add-node --validator-address=$VAL_ADDR --validator-pubkey=$VAL_PUBKEY --name=$NODE_NAME --from=$KEY_NAME'"
440-
459+
echo -e "\n\t3. Explore the node external IP and provide it along with validator ID '$VAL_ID'"
460+
echo -e "\t\t to DCLedger '$CHAIN_ID' network validator administrators"
441461

442462
fi
443463

444-
echo "Done"
445-
446-
447464
# useful commands
448465
# - keys:
449466
# dclcli keys show <name>: to get address and oubkey for a ketname

deployment/scripts/update_peers

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
# Copyright 2020 DSR Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -eu
17+
set -o pipefail
18+
19+
CONFIG_FILE="$HOME/.dcld/config/config.toml"
20+
PERSISTENT_PEERS_FILE="${1:-./persistent_peers.txt}"
21+
PERSISTENT_PEERS="$(cat $PERSISTENT_PEERS_FILE | head -n1)"
22+
23+
sed -i -r "s~^persistent_peers = .*~persistent_peers = \"$PERSISTENT_PEERS\"~" "$CONFIG_FILE"
24+
25+
echo "Updated"

0 commit comments

Comments
 (0)