Skip to content

Commit 3d29b1f

Browse files
author
TaonaProject
authored
Initial Upload
0 parents  commit 3d29b1f

File tree

1 file changed

+396
-0
lines changed

1 file changed

+396
-0
lines changed

installnode.sh

Lines changed: 396 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,396 @@
1+
#!/bin/bash
2+
3+
#############################
4+
# Script by Thanos #
5+
#############################
6+
7+
LOG_FILE=/tmp/install.log
8+
9+
decho () {
10+
echo `date +"%H:%M:%S"` $1
11+
echo `date +"%H:%M:%S"` $1 >> $LOG_FILE
12+
}
13+
14+
error() {
15+
local parent_lineno="$1"
16+
local message="$2"
17+
local code="${3:-1}"
18+
echo "Error on or near line ${parent_lineno}; exiting with status ${code}"
19+
exit "${code}"
20+
}
21+
trap 'error ${LINENO}' ERR
22+
23+
24+
clear
25+
26+
cat <<'FIG'
27+
28+
__/\\\________/\\\__/\\\\\\\\\\\\________/\\\\\\\\\_____________________________
29+
__\/\\\_____/\\\//__\/\\\////////\\\____/\\\\\\\\\\\\\__________________________
30+
___\/\\\__/\\\//_____\/\\\______\//\\\__/\\\/////////\\\________________________
31+
____\/\\\\\\//\\\_____\/\\\_______\/\\\_\/\\\_______\/\\\_______________________
32+
_____\/\\\//_\//\\\____\/\\\_______\/\\\_\/\\\\\\\\\\\\\\\______________________
33+
______\/\\\____\//\\\___\/\\\_______\/\\\_\/\\\/////////\\\_____________________
34+
_______\/\\\_____\//\\\__\/\\\_______/\\\__\/\\\_______\/\\\____________________
35+
________\/\\\______\//\\\_\/\\\\\\\\\\\\/___\/\\\_______\/\\\___________________
36+
_________\///________\///__\////////////_____\///________\///___________________
37+
__/\\\\\_____/\\\_______/\\\\\_______/\\\\\\\\\\\\_____/\\\\\\\\\\\\\\\_________
38+
__\/\\\\\\___\/\\\_____/\\\///\\\____\/\\\////////\\\__\/\\\///////////_________
39+
___\/\\\/\\\__\/\\\___/\\\/__\///\\\__\/\\\______\//\\\_\/\\\___________________
40+
____\/\\\//\\\_\/\\\__/\\\______\//\\\_\/\\\_______\/\\\_\/\\\\\\\\\\\__________
41+
_____\/\\\\//\\\\/\\\_\/\\\_______\/\\\_\/\\\_______\/\\\_\/\\\///////__________
42+
______\/\\\_\//\\\/\\\_\//\\\______/\\\__\/\\\_______\/\\\_\/\\\________________
43+
_______\/\\\__\//\\\\\\__\///\\\__/\\\____\/\\\_______/\\\__\/\\\_______________
44+
________\/\\\___\//\\\\\____\///\\\\\/_____\/\\\\\\\\\\\\/___\/\\\\\\\\\\\\\\\__
45+
_________\///_____\/////_______\/////_______\////////////_____\///////////////__
46+
47+
FIG
48+
49+
# Check if executed as root user
50+
if [[ $EUID -ne 0 ]]; then
51+
echo -e "This script has to be run as \033[1mroot\033[0m user."
52+
exit 1
53+
fi
54+
55+
56+
# Print variable on a screen
57+
decho "Make sure you double check information before hitting enter!"
58+
59+
read -e -p "Please enter the domain where the Kadena server will run: " whereami
60+
if [[ "$whereami" == "" ]]; then
61+
decho "WARNING: No domain entered, exiting!!!"
62+
exit 3
63+
fi
64+
65+
# Check for systemd
66+
systemctl --version >/dev/null 2>&1 || { decho "systemd is required. Are you using Ubuntu 18.04?" >&2; exit 1; }
67+
68+
69+
# Install swap
70+
decho "Enabling a swap partition..."
71+
72+
if free | awk '/^Swap:/ {exit !$2}'; then
73+
decho "Has swap..."
74+
else
75+
touch /var/swap.img
76+
chmod 600 /var/swap.img
77+
dd if=/dev/zero of=/var/swap.img bs=1024k count=2048
78+
mkswap /var/swap.img
79+
swapon /var/swap.img
80+
echo "/var/swap.img none swap sw 0 0" >> /etc/fstab
81+
fi
82+
83+
84+
# Update packages
85+
decho "Updating system..."
86+
87+
apt-get update -y >> $LOG_FILE 2>&1
88+
dpkg --configure -a
89+
90+
# Install required packages
91+
decho "Installing base packages and dependencies..."
92+
decho "This may take a while..."
93+
94+
apt-get install -y certbot >> $LOG_FILE 2>&1
95+
apt-get install -y librocksdb5.8 >> $LOG_FILE 2>&1
96+
apt-get install -y curl >> $LOG_FILE 2>&1
97+
98+
decho "Installing ufw..."
99+
apt-get install -y ufw >> $LOG_FILE 2>&1
100+
ufw allow ssh/tcp >> $LOG_FILE 2>&1
101+
ufw allow sftp/tcp >> $LOG_FILE 2>&1
102+
ufw allow 80/tcp >> $LOG_FILE 2>&1
103+
ufw allow 443/tcp >> $LOG_FILE 2>&1
104+
ufw default deny incoming >> $LOG_FILE 2>&1
105+
ufw default allow outgoing >> $LOG_FILE 2>&1
106+
ufw logging on >> $LOG_FILE 2>&1
107+
ufw --force enable >> $LOG_FILE 2>&1
108+
109+
decho "Create user kda (if necessary)"
110+
111+
# Deactivate trap only for this command
112+
trap '' ERR
113+
getent passwd kda > /dev/null 2&>1
114+
115+
if [ $? -ne 0 ]; then
116+
trap 'error ${LINENO}' ERR
117+
adduser --disabled-password --gecos "" kda >> $LOG_FILE 2>&1
118+
else
119+
trap 'error ${LINENO}' ERR
120+
fi
121+
122+
# Download Node
123+
decho 'Downloading Node...'
124+
cd /home/kda/
125+
wget --no-check-certificate https://github.com/kadena-io/chainweb-node/releases/download/1.3.1/chainweb.8.6.5.ubuntu-18.04.1e6c76b2.tar.gz >> $LOG_FILE 2>&1
126+
tar -xvf chainweb.8.6.5.ubuntu-18.04.1e6c76b2.tar.gz >> $LOG_FILE 2>&1
127+
wget --no-check-certificate https://github.com/kadena-io/chainweb-miner/releases/download/v1.0.3/chainweb-miner-1.0.3-ubuntu-18.04.tar.gz >> $LOG_FILE 2>&1
128+
tar -xvf chainweb-miner-1.0.3-ubuntu-18.04.tar.gz >> $LOG_FILE 2>&1
129+
130+
# Create config.yaml
131+
decho "Creating config files and Health check..."
132+
133+
touch /home/kda/config.yaml
134+
cat << EOF > /home/kda/config.yaml
135+
chainweb:
136+
# The defining value of the network. To change this means being on a
137+
# completely independent Chainweb.
138+
chainwebVersion: mainnet01
139+
140+
throttling:
141+
local: 0.1
142+
mining: 100000
143+
global: 400
144+
putPeer: 11
145+
146+
mining:
147+
# Settings for how a Node can provide work for remote miners.
148+
coordination:
149+
enabled: true
150+
# "public" or "private".
151+
mode: public
152+
# The number of "/mining/work" calls that can be made in total over a 5
153+
# minute period.
154+
limit: 102400
155+
# The number of work requests per client per second.
156+
mining: 100000
157+
# When "mode: private", this is a list of miner account names who are
158+
# allowed to have work generated for them.
159+
miners:
160+
- account: abc123
161+
predicate: keys-all
162+
public-keys:
163+
- 3438e5bcfd086c5eeee1a2f227b7624df889773e00bd623babf5fc72c8f9aa63
164+
- account: cfd7816f15bd9413e5163308e18bf1b13925f3182aeac9b30ed303e8571ce997
165+
predicate: keys-all
166+
public-keys:
167+
- cfd7816f15bd9413e5163308e18bf1b13925f3182aeac9b30ed303e8571ce997
168+
169+
p2p:
170+
# Your node's network identity.
171+
peer:
172+
# Filepath to the "fullchain.pem" of the certificate of your domain.
173+
# If "null", this will be auto-generated.
174+
certificateChainFile: null
175+
# Filepath to the "privkey.pem" of the certificate of your domain.
176+
# If "null", this will be auto-generated.
177+
keyFile: null
178+
179+
# You.
180+
hostaddress:
181+
# This should be your public IP or domain name.
182+
hostname: $whereami
183+
# The port you'd like to run the Node on. 443 is a safe default.
184+
port: 443
185+
186+
# Initial peers to connect to in order to join the network for the first time.
187+
# These will share more peers and block data to your Node.
188+
peers:
189+
- address:
190+
hostname: akami.chainweb.tech
191+
port: 443
192+
id: null
193+
- address:
194+
hostname: arboretum.tech
195+
port: 443
196+
id: null
197+
- address:
198+
hostname: chainweb.xyz
199+
port: 443
200+
id: null
201+
- address:
202+
hostname: tsundere.waifuwars.org
203+
port: 35090
204+
id: null
205+
- address:
206+
hostname: kadena1.block77.io
207+
port: 443
208+
id: null
209+
- address:
210+
hostname: kadena2.block77.io
211+
port: 443
212+
id: null
213+
- address:
214+
hostname: ponzu.banteg.xyz
215+
port: 1337
216+
id: null
217+
- address:
218+
hostname: dumpling.banteg.xyz
219+
port: 1337
220+
id: null
221+
- address:
222+
hostname: sg.blockventur.es
223+
port: 44444
224+
id: null
225+
- address:
226+
hostname: sg.kadena.asymmetry.ventures
227+
port: 44444
228+
id: null
229+
- address:
230+
hostname: kadena.wayi.cn
231+
port: 443
232+
id: null
233+
- address:
234+
hostname: kadenamerkletree.com
235+
port: 443
236+
id: null
237+
- address:
238+
hostname: chungle.constant.gripe
239+
port: 1343
240+
id: null
241+
- address:
242+
hostname: fr1.chainweb.com
243+
port: 443
244+
id: null
245+
- address:
246+
hostname: pn.hyperioncn.net
247+
port: 443
248+
id: null
249+
- address:
250+
hostname: cw.hyperioncn.net
251+
port: 443
252+
id: null
253+
- address:
254+
hostname: us-w1.chainweb.com
255+
port: 443
256+
id: null
257+
- address:
258+
hostname: us-e1.chainweb.com
259+
port: 443
260+
id: null
261+
- address:
262+
hostname: jp1.chainweb.com
263+
port: 443
264+
id: null
265+
- address:
266+
hostname: fr1.chainweb.com
267+
port: 443
268+
id: null
269+
270+
logging:
271+
# All structural (JSON, etc.) logs.
272+
telemetryBackend:
273+
enabled: true
274+
configuration:
275+
handle: stdout
276+
color: auto
277+
# "text" or "json"
278+
format: text
279+
280+
# Simple text logs.
281+
backend:
282+
handle: stdout
283+
color: auto
284+
# "text" or "json"
285+
format: text
286+
287+
logger:
288+
log_level: warn
289+
290+
filter:
291+
rules:
292+
- key: component
293+
value: cut-monitor
294+
level: info
295+
- key: component
296+
value: pact-tx-replay
297+
level: info
298+
- key: component
299+
value: connection-manager
300+
level: info
301+
- key: component
302+
value: miner
303+
level: info
304+
- key: component
305+
value: local-handler
306+
level: info
307+
default: error
308+
309+
EOF
310+
311+
touch /etc/systemd/system/node.service
312+
cat <<EOF > /etc/systemd/system/node.service
313+
[Unit]
314+
Description=Node Service
315+
316+
[Service]
317+
User=root
318+
WorkingDirectory=/home/kda
319+
ExecStart=/home/kda/node.sh
320+
Restart=always
321+
RestartSec=3
322+
323+
[Install]
324+
WantedBy=multi-user.target
325+
EOF
326+
327+
touch /home/kda/health.sh
328+
chmod +x /home/kda/health.sh
329+
cat <<EOF > /home/kda/health.sh
330+
#!/bin/bash
331+
#!/bin/bash
332+
status_code=\$(timeout 5s curl --write-out %{http_code} https://$whereami:443/chainweb/0.0/mainnet01/cut --silent --output /dev/null)
333+
echo \$status_code
334+
if [[ "\$status_code" -ne 200 ]]; then
335+
echo "RESTART DUE TO NO API RESULT"
336+
systemctl daemon-reload
337+
systemctl restart node
338+
fi
339+
340+
PID=`pidof chainweb-node`
341+
FD=`ss -tnp | grep 443 | grep ESTAB | wc -l`
342+
if [[ "\$FD" -gt 10000 ]]; then
343+
echo "RESTART DUE TO TOO MANY OPEN FILES"
344+
systemctl daemon-reload
345+
systemctl restart node
346+
fi
347+
EOF
348+
349+
touch /home/kda/node.sh
350+
chmod +x /home/kda/node.sh
351+
cat <<EOF > /home/kda/node.sh
352+
#!/bin/bash
353+
/home/kda/chainweb-node \
354+
--config-file /home/kda/config.yaml \
355+
--certificate-chain-file=/etc/letsencrypt/live/$whereami/fullchain.pem \
356+
--certificate-key-file=/etc/letsencrypt/live/$whereami/privkey.pem
357+
# 1>/home/kda/node.log 2>&1
358+
EOF
359+
360+
chmod +x -R /home/kda/
361+
362+
# Setup crontab
363+
364+
echo "*/5 * * * * /home/kda/health.sh >/home/kda/health.out 2>/home/kda/health.err" >> newCrontab
365+
crontab -u kda newCrontab >> $LOG_FILE 2>&1
366+
rm newCrontab >> $LOG_FILE 2>&1
367+
368+
certbot certonly --standalone --agree-tos --register-unsafely-without-email -d $whereami >> $LOG_FILE 2>&1
369+
systemctl daemon-reload
370+
systemctl enable node.service
371+
systemctl start node.service
372+
sleep 10
373+
systemctl stop node.service
374+
375+
#Download recent Bootstrap......"
376+
echo "Downloading recent Bootstrap..."
377+
echo "This may take a while..."
378+
379+
sudo systemctl stop node.service
380+
cd ~/.local/share/chainweb-node/mainnet01/0/
381+
sudo rm -fr rocksDb sqlite
382+
wget https://s3.us-east-2.amazonaws.com/node-dbs.chainweb.com/db-chainweb-node-ubuntu.18.04-latest.tar.gz
383+
sudo tar xvfz db-chainweb-node-ubuntu.18.04-latest.tar.gz
384+
sudo systemctl start node.service
385+
clear
386+
# Installation Completed
387+
echo 'Installation completed...'
388+
echo 'Kadena Node is installed'
389+
echo 'Watchdogs are in place'
390+
echo 'Everything is automated from now on'
391+
echo 'Type "sudo nano /home/kda/config.yaml"'
392+
echo 'Change the coordination mode to "private"'
393+
echo 'Edit the miners section for your addresses'
394+
echo 'CTRL+x to save Y to confirm then "sudo systemctl restart node.service"'
395+
echo 'to restart it with your addresses whitelisted'
396+
echo 'Type "journalctl -fu node.service" to see the node log'

0 commit comments

Comments
 (0)