-
Notifications
You must be signed in to change notification settings - Fork 12
/
install.sh
205 lines (179 loc) · 5.92 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash
set -e
set -u
set -x
# this should be provided through env by azure template
TEMPLATES_BRANCH="${TEMPLATES_BRANCH}"
MAIN_REPO_FETCH="${MAIN_REPO_FETCH}"
echo "========== ${TEMPLATES_BRANCH}/netstats-server/install.sh starting =========="
echo "===== current time: $(date)"
echo "===== username: $(whoami)"
echo "===== working directory: $(pwd)"
echo "===== operating system info:"
lsb_release -a
echo "===== memory usage info:"
free -m
EXT_IP="$(curl ifconfig.co)"
echo "===== external ip: ${EXT_IP}"
echo "===== downloading common.vars"
curl -sLO "https://raw.githubusercontent.com/${MAIN_REPO_FETCH}/deployment-azure/${TEMPLATES_BRANCH}/nodes/common.vars"
source common.vars
INSTALL_CONFIG_REPO="${REPO_BASE_PATH}/netstats-server"
echo "===== INSTALL_CONFIG_REPO: ${INSTALL_CONFIG_REPO}"
NETSTATS_SERVER="http://localhost:3000"
# this should be provided through env by azure template
NETSTATS_SECRET="${NETSTATS_SECRET}"
NODE_FULLNAME="${NODE_FULLNAME:-NetStat}"
NODE_ADMIN_EMAIL="${NODE_ADMIN_EMAIL:-somebody@somehere}"
ADMIN_USERNAME="${ADMIN_USERNAME}"
export HOME="${HOME:-/home/${ADMIN_USERNAME}}"
echo "===== environmental variables:"
printenv
echo "===== downloading common.funcs"
curl -sLO "https://raw.githubusercontent.com/${MAIN_REPO_FETCH}/deployment-azure/${TEMPLATES_BRANCH}/nodes/common.funcs"
source common.funcs
setup_ufw() {
echo "=====> setup_ufw"
sudo sudo ufw enable
sudo ufw default deny incoming
sudo ufw allow 3000
sudo ufw allow 4000
sudo ufw allow 443
sudo ufw allow 8545
sudo ufw allow 22/tcp
sudo ufw allow 30303/tcp
sudo ufw allow 30303/udp
echo "<===== setup_ufw"
}
pull_image_and_configs() {
echo "=====> pull_image_and_configs"
# curl -s -O "${INSTALL_CONFIG_REPO}/../${GENESIS_JSON}"
curl -s -o "${GENESIS_JSON}" "${GENESIS_REPO_LOC}"
curl -s -O "${INSTALL_CONFIG_REPO}/node.toml"
curl -s -o "bootnodes.txt" "${BOOTNODES_TXT}"
sed -i "/\[network\]/a nat=\"extip:${EXT_IP}\"" ${NODE_TOML}
#sed -i "/\[network\]/a bootnodes=\[$(cat bootnodes.txt | sed 's/\r$//' | awk -F'#' '{ print $1 }' | awk '/enode/{ print "\""$1"\"" }' | paste -sd "," -)\]" ${NODE_TOML}
sed -i "/\[network\]/a reserved_peers=\"/home/${ADMIN_USERNAME}/bootnodes.txt\"" ${NODE_TOML}
cat >> ${NODE_TOML} <<EOF
[misc]
log_file = "/home/${ADMIN_USERNAME}/logs/parity.log"
EOF
mkdir -p parity_data/keys/OraclesPoA
echo "<===== pull_image_and_configs"
}
install_dashboard_via_systemd() {
echo "=====> install_dashboard_via_systemd"
git clone https://github.com/oraclesorg/eth-netstats
cd eth-netstats
npm install
sudo npm install -g grunt-cli
grunt
echo "[\"${NETSTATS_SECRET}\"]" > ws_secret.json
cd ..
sudo bash -c "cat > /etc/systemd/system/oracles-dashboard.service <<EOF
[Unit]
Description=oracles dashboard service
After=network.target
[Service]
User=${ADMIN_USERNAME}
Group=${ADMIN_USERNAME}
Environment=MYVAR=myval
WorkingDirectory=/home/${ADMIN_USERNAME}/eth-netstats
Restart=always
ExecStart=/usr/bin/npm start
[Install]
WantedBy=multi-user.target
EOF"
sudo systemctl enable oracles-dashboard
sudo systemctl start oracles-dashboard
echo "<====== install_dashboard_via_systemd"
}
install_chain_explorer_via_systemd() {
echo "=====> install_chain_explorer_via_systemd"
git clone https://github.com/oraclesorg/chain-explorer
git clone https://github.com/ethereum/solc-bin chain-explorer/utils/solc-bin
cd chain-explorer
npm install
sudo npm install pm2 -g
cat > config.js <<EOF
var web3 = require('web3');
var net = require('net');
var config = function () {
this.logFormat = "combined";
this.ipcPath = "/home/${ADMIN_USERNAME}/parity_data/jsonrpc.ipc";
this.provider = new web3.providers.IpcProvider(this.ipcPath, net);
this.bootstrapUrl = "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/yeti/bootstrap.min.css";
this.names = {
"${OWNER_ADDRESS}": "Master of Ceremony",
};
}
module.exports = config;
EOF
cat > app.json << EOF
[
{
"name" : "explorer",
"script" : "./bin/www",
"log_date_format" : "YYYY-MM-DD HH:mm:SS Z",
"error_file" : "/home/${ADMIN_USERNAME}/logs/explorer.err",
"out_file" : "/home/${ADMIN_USERNAME}/logs/explorer.out",
"merge_logs" : false,
"watch" : false,
"max_restarts" : 100,
"exec_interpreter" : "node",
"exec_mode" : "fork_mode",
"env":
{
"NODE_ENV" : "production",
"PORT" : 4000,
}
}
]
EOF
cd ..
sudo bash -c "cat > /etc/systemd/system/oracles-chain-explorer.service <<EOF
[Unit]
Description=oracles chain explorer service
After=oracles-pm2.service
[Service]
Type=oneshot
RemainAfterExit=true
User=${ADMIN_USERNAME}
Group=${ADMIN_USERNAME}
Environment=MYVAR=myval
WorkingDirectory=/home/${ADMIN_USERNAME}/chain-explorer
ExecStart=/usr/bin/pm2 startOrRestart app.json
[Install]
WantedBy=multi-user.target
EOF"
sudo systemctl enable oracles-chain-explorer
sudo systemctl start oracles-chain-explorer
echo "<===== install_chain_explorer_via_systemd"
}
# MAIN
main () {
sudo apt-get update
prepare_homedir
setup_ufw
increase_ulimit_n
install_ntpd
install_haveged
allocate_swap
install_nodejs
pull_image_and_configs
if [ "${PARITY_INSTALLATION_MODE}" = "BIN" ]; then
use_bin_via_systemd
elif [ "${PARITY_INSTALLATION_MODE}" = "DEB" ]; then
use_deb_via_systemd
else
echo "===== invalid PARITY_INSTALLATION_MODE == ${PARITY_INSTALLATION_MODE}. Should be either BIN or DEB"
exit 1
fi
start_pm2_via_systemd
install_dashboard_via_systemd
install_netstats_via_systemd
install_chain_explorer_via_systemd
configure_logrotate
}
main
echo "========== ${TEMPLATES_BRANCH}/netstats-server/install.sh finished =========="