Skip to content

Commit 071b964

Browse files
committed
Code cleanup and minor improvements
1 parent d543be2 commit 071b964

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

files/raven_status

+2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ node_ver=$(echo ${net_info} | jq -r '.subversion' | awk -F/ '{print $2}')
55
node_ip=$(echo ${net_info} | jq -r '.localaddresses[] | .address')
66
node_port=$(echo ${net_info} | jq -r '.localaddresses[] | .port')
77
node_score=$(echo ${net_info} | jq -r '.localaddresses[] | .score')
8+
node_peer_count=$(echo ${net_info} | jq -r '.connections')
89

910
echo "Node version: ${node_ver}"
1011
echo "Node IP/port: ${node_ip}/${node_port}"
12+
echo "Node Peer Count: ${node_peer_count}"
1113
echo "Node score: ${node_score}"
1214

1315
count=$(raven-cli getblockcount)

files/rvn_init

+32-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
HOME_DIR=/home/kingofthenorth/
4+
KOTN_DIR=/kingofthenorth/
5+
36
function extract_file() {
47
local extraction_dir="./"
58
if [ -n "$2" ]; then
@@ -17,48 +20,48 @@ function extract_file() {
1720
}
1821

1922
function bootstrap_node() {
20-
local download_dir=/kingofthenorth/bootstrap-seed/
21-
local extraction_dir=/kingofthenorth/raven-dir/
22-
local transmission_dir=~/.config/transmission-daemon/
23+
local download_dir=$KOTN_DIR/bootstrap-seed/
24+
local extraction_dir=$KOTN_DIR/raven-dir/
25+
local transmission_dir=$HOME_DIR/.config/transmission-daemon/
2326
local bootstrap_done="bootstrap.done"
2427
while [ ! "$(transmission-remote localhost -n transmission:transmission -l | grep "rvn-bootstrap*.tar.gz" | awk '{print $5}')" = "Done" ];
2528
do
26-
echo -e "$(date) - Waiting for bootstrap file to finish downloading..." > ~/bootstrap-status.log
27-
echo -e "$(transmission-remote localhost -n transmission:transmission -l | grep "rvn-bootstrap*.tar.gz")" >> ~/bootstrap-status.log
29+
echo -e "$(date) - Waiting for bootstrap file to finish downloading..." > $HOME_DIR/bootstrap-status.log
30+
echo -e "$(transmission-remote localhost -n transmission:transmission -l | grep "rvn-bootstrap*.tar.gz")" >> $HOME_DIR/bootstrap-status.log
2831
sleep 60
2932
done
3033

3134
local bootstrap_file=$(find ${download_dir} -type f -name "rvn-bootstrap*tar.gz")
3235
if [ -z "${bootstrap_file}" ]; then
33-
echo -e "$(date) - ERROR: Failed to find the downloaded bootstrap file!" > ~/bootstrap-status.log
36+
echo -e "$(date) - ERROR: Failed to find the downloaded bootstrap file!" > $HOME_DIR/bootstrap-status.log
3437
return 1
3538
fi
3639

37-
echo -e "$(date) - Verifying the bootstrap file integrity..." > ~/bootstrap-status.log
40+
echo -e "$(date) - Verifying the bootstrap file integrity..." > $HOME_DIR/bootstrap-status.log
3841
cp ${transmission_dir}/seeding/rvn-bootstrap.md5 ${download_dir}
3942
pushd $download_dir &> /dev/null
4043
if ! md5sum -c rvn-bootstrap.md5 --status --ignore-missing; then
41-
echo -e "$(date) - ERROR: Failed to verify the MD5 checksum of the downloaded bootstrap file!" > ~/bootstrap-status.log
44+
echo -e "$(date) - ERROR: Failed to verify the MD5 checksum of the downloaded bootstrap file!" > $HOME_DIR/bootstrap-status.log
4245
popd &> /dev/null
4346
return 1
4447
fi
4548
popd &> /dev/null
4649

4750
if [ -f "${download_dir}/${bootstrap_done}" ]; then
48-
echo -e "$(date) - Extraction skipped since file already exists..." > ~/bootstrap-status.log
51+
echo -e "$(date) - Extraction skipped since file already exists..." > $HOME_DIR/bootstrap-status.log
4952
return 0
5053
fi
5154

52-
echo -e "$(date) - Extracting the bootstrap file database..." > ~/bootstrap-status.log
53-
extract_file $bootstrap_file $extraction_dir || { echo -e "Failed to extract the bootstrap database..." > ~/bootstrap-status.log && return 1; }
55+
echo -e "$(date) - Extracting the bootstrap file database..." > $HOME_DIR/bootstrap-status.log
56+
extract_file $bootstrap_file $extraction_dir || { echo -e "Failed to extract the bootstrap database..." > $HOME_DIR/bootstrap-status.log && return 1; }
5457

55-
echo -e "$(date) - Extraction of the bootstrap file completed succesfully!" > ~/bootstrap-status.log
56-
touch $bootstrap_done $download_dir
58+
echo -e "$(date) - Extraction of the bootstrap file completed succesfully!" > $HOME_DIR/bootstrap-status.log
59+
touch $download_dir/$bootstrap_done
5760
return 0
5861
}
5962

6063
function setup_nodejs(){
61-
local app_dir=/home/kingofthenorth/nodejs-app/
64+
local app_dir=$HOME_DIR/nodejs-app/
6265
cd ${app_dir}
6366
npm i
6467
return 0
@@ -85,73 +88,75 @@ function install_rvn() {
8588
ln -sf /opt/raven/bin/ravend /usr/local/bin/ravend
8689
ln -sf /opt/raven/bin/raven-cli /usr/local/bin/raven-cli
8790

88-
local raven_dir=/home/kingofthenorth/.raven/
91+
local raven_dir=$HOME_DIR/.raven/
8992
mkdir -p ${raven_dir}
9093
chown -R kingofthenorth:kingofthenorth ${raven_dir}
9194

9295
rm -rf /tmp/*
9396
}
9497

9598
function node_status() {
96-
local home_dir="/home/kingofthenorth"
97-
local bootstrap_file="${home_dir}/bootstrap-status.log"
99+
local bootstrap_file="${HOME_DIR}/bootstrap-status.log"
98100
if [ -f $bootstrap_file ]; then
99101
cat $bootstrap_file
100102
fi
101103
local ravend_pid=$(ps aux | grep ravend | grep -v grep)
102104
if [ -n "${ravend_pid}" ]; then
103-
local status_file="node_status.log"
105+
local status_file="${HOME_DIR}/node_status.log"
104106
local curr_t=$(date +%s)
105107
local status_file_t=$(date -r ${status_file} +%s)
106108
local diff_t=$[$curr_t - $status_file_t]
107109
if [ $diff_t -gt 60 ]; then
108110
raven_status > $status_file
109-
else
110-
cat $status_file
111111
fi
112+
cat $status_file
112113
fi
113114
return 0
114115
}
115116

116117
function check_env_vars() {
117118
if [ "${UPNP}" = "true" ]; then
118119
echo "Enabling UPNP on services..."
119-
sed -i -e '/upnp=/ s/=.*/=1/' /home/kingofthenorth/.raven/raven.conf
120-
sed -i -e '/\"port-forwarding-enabled\":/ s/:.*/: true,/' /home/kingofthenorth/.config/transmission-daemon/settings.json
120+
sed -i -e '/upnp=/ s/=.*/=1/' ${HOME_DIR}/.raven/raven.conf
121+
sed -i -e '/\"port-forwarding-enabled\":/ s/:.*/: true,/' ${HOME_DIR}/.config/transmission-daemon/settings.json
121122
fi
122123
if [ -n "${RAVEN_PORT}" ]; then
123124
echo "Setting up custom RVN Core port ${RAVEN_PORT}..."
124-
sed -i -e "/port=/ s/=.*/=${RAVEN_PORT}/" /home/kingofthenorth/.raven/raven.conf
125+
sed -i -e "/port=/ s/=.*/=${RAVEN_PORT}/" ${HOME_DIR}/.raven/raven.conf
125126
fi
126127
if [ -n "${TRANSMISSION_PORT}" ]; then
127128
echo "Setting up custom Transmission port ${TRANSMISSION_PORT}..."
128-
sed -i -e "/\"peer-port\":/ s/:.*/: ${TRANSMISSION_PORT},/" /home/kingofthenorth/.config/transmission-daemon/settings.json
129+
sed -i -e "/\"peer-port\":/ s/:.*/: ${TRANSMISSION_PORT},/" ${HOME_DIR}/.config/transmission-daemon/settings.json
129130
fi
130131
if [ -n "${FRONTEND_PORT}" ]; then
131132
echo "Setting up custom Frontend port ${FRONTEND_PORT}..."
132-
sed -i -e "/const PORT = / s/=.*/= ${FRONTEND_PORT}/" /home/kingofthenorth/nodejs-app/index.js
133+
sed -i -e "/const PORT = / s/=.*/= ${FRONTEND_PORT}/" ${HOME_DIR}/nodejs-app/index.js
133134
fi
134135
}
135136

136137
function init() {
137138
# Check for environment variables
138139
check_env_vars
139140
# Start node front-end
140-
local app_dir=/home/kingofthenorth/nodejs-app/
141+
local app_dir=${HOME_DIR}/nodejs-app/
141142
setup_nodejs || return 1
142143
pushd $app_dir
143144
node index.js &
144145
popd
146+
# Create status file
147+
touch $HOME_DIR/node_status.log
145148
# Setup transmission for bootstrap file
146149
transmission-daemon && sleep 30
147150
# Start bootstraping the node
148151
bootstrap_node || { sleep 600 && return 2; }
149152
# Start ravencoin daemon
150-
local ravend_done="ravend-reindex.done"
153+
local ravend_done="${KOTN_DIR}/raven-dir/ravend-reindex.done"
151154
if [ -f "${ravend_done}" ]; then
155+
echo -e "${ravend_done} file found. Running ravend..."
152156
ravend || return 3
153157
else
154158
touch $ravend_done
159+
echo -e "${ravend_done} file NOT found. Running ravend and reindexing chain..."
155160
ravend -reindex || return 4
156161
fi
157162
}

0 commit comments

Comments
 (0)