deployment-azure/nodes/netstats-server/install.sh

206 lines
5.9 KiB
Bash
Raw Permalink Normal View History

2017-10-02 14:18:38 -07:00
#!/bin/bash
set -e
set -u
set -x
2017-11-20 07:13:27 -08:00
# this should be provided through env by azure template
TEMPLATES_BRANCH="${TEMPLATES_BRANCH}"
MAIN_REPO_FETCH="${MAIN_REPO_FETCH}"
2017-10-02 14:18:38 -07:00
2017-11-16 14:18:26 -08:00
echo "========== ${TEMPLATES_BRANCH}/netstats-server/install.sh starting =========="
2017-10-02 14:18:38 -07:00
echo "===== current time: $(date)"
echo "===== username: $(whoami)"
echo "===== working directory: $(pwd)"
echo "===== operating system info:"
lsb_release -a
echo "===== memory usage info:"
free -m
2017-11-16 14:18:26 -08:00
2017-11-16 14:44:55 -08:00
EXT_IP="$(curl ifconfig.co)"
echo "===== external ip: ${EXT_IP}"
2017-11-17 01:49:42 -08:00
echo "===== downloading common.vars"
curl -sLO "https://raw.githubusercontent.com/${MAIN_REPO_FETCH}/deployment-azure/${TEMPLATES_BRANCH}/nodes/common.vars"
2017-11-17 01:49:42 -08:00
source common.vars
2017-11-21 13:15:10 -08:00
INSTALL_CONFIG_REPO="${REPO_BASE_PATH}/netstats-server"
echo "===== INSTALL_CONFIG_REPO: ${INSTALL_CONFIG_REPO}"
2017-12-06 06:35:28 -08:00
NETSTATS_SERVER="http://localhost:3000"
2017-10-02 14:18:38 -07:00
# 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}}"
2017-11-17 01:48:21 -08:00
echo "===== environmental variables:"
printenv
2017-11-16 14:30:27 -08:00
echo "===== downloading common.funcs"
curl -sLO "https://raw.githubusercontent.com/${MAIN_REPO_FETCH}/deployment-azure/${TEMPLATES_BRANCH}/nodes/common.funcs"
2017-11-16 14:30:27 -08:00
source common.funcs
2017-10-27 07:44:19 -07:00
2017-11-16 05:49:27 -08:00
setup_ufw() {
echo "=====> setup_ufw"
sudo sudo ufw enable
sudo ufw default deny incoming
2017-11-17 07:23:50 -08:00
sudo ufw allow 3000
sudo ufw allow 4000
2017-11-16 05:49:27 -08:00
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"
}
2017-10-02 14:18:38 -07:00
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}"
2017-11-16 14:44:55 -08:00
curl -s -O "${INSTALL_CONFIG_REPO}/node.toml"
2017-10-11 07:55:47 -07:00
curl -s -o "bootnodes.txt" "${BOOTNODES_TXT}"
2017-10-02 14:18:38 -07:00
sed -i "/\[network\]/a nat=\"extip:${EXT_IP}\"" ${NODE_TOML}
2017-10-25 09:05:49 -07:00
#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}
2017-10-02 14:18:38 -07:00
cat >> ${NODE_TOML} <<EOF
[misc]
log_file = "/home/${ADMIN_USERNAME}/logs/parity.log"
EOF
2017-11-16 14:18:26 -08:00
mkdir -p parity_data/keys/OraclesPoA
2017-10-02 14:18:38 -07:00
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";
2017-11-16 14:18:26 -08:00
this.ipcPath = "/home/${ADMIN_USERNAME}/parity_data/jsonrpc.ipc";
2017-10-02 14:18:38 -07:00
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 = {
2017-11-29 08:23:25 -08:00
"${OWNER_ADDRESS}": "Master of Ceremony",
2017-10-02 14:18:38 -07:00
};
}
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
2017-11-16 05:49:27 -08:00
setup_ufw
2017-10-27 07:44:19 -07:00
increase_ulimit_n
2017-10-02 14:18:38 -07:00
install_ntpd
install_haveged
allocate_swap
install_nodejs
pull_image_and_configs
2017-11-16 14:18:26 -08:00
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
2017-10-02 14:18:38 -07:00
start_pm2_via_systemd
2017-10-03 07:06:02 -07:00
install_dashboard_via_systemd
2017-10-02 14:18:38 -07:00
install_netstats_via_systemd
install_chain_explorer_via_systemd
configure_logrotate
}
main
2017-11-16 14:18:26 -08:00
echo "========== ${TEMPLATES_BRANCH}/netstats-server/install.sh finished =========="