#!/bin/bash set -e set -u set -x EXT_IP="$(curl ifconfig.co)" echo "========== dev-mainnet/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 echo "===== external ip: ${EXT_IP}" echo "===== environmental variables:" printenv INSTALL_CONFIG_REPO="https://raw.githubusercontent.com/oraclesorg/test-templates/dev-mainnet/TestTestNet/bootnode" GENESIS_REPO_LOC="https://raw.githubusercontent.com/oraclesorg/oracles-scripts/sokol/spec.json" GENESIS_JSON="spec.json" NODE_TOML="node.toml" BOOTNODES_TXT="https://raw.githubusercontent.com/oraclesorg/test-templates/dev-mainnet/TestTestNet/bootnodes.txt" PARITY_DEB_LOC="https://parity-downloads-mirror.parity.io/v1.8.1/x86_64-unknown-linux-gnu/parity_1.8.1_amd64.deb" echo "===== repo base path: ${INSTALL_CONFIG_REPO}" # 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}}" prepare_homedir() { echo "=====> prepare_homedir" # ln -s "$(pwd)" "/home/${ADMIN_USERNAME}/script-dir" cd "/home/${ADMIN_USERNAME}" echo "Now changed directory to: $(pwd)" mkdir -p logs mkdir -p logs/old echo "<===== prepare_homedir" } increase_ulimit_n() { echo "${ADMIN_USERNAME} soft nofile 100000" | sudo tee /etc/security/limits.conf >> /dev/null echo "${ADMIN_USERNAME} hard nofile 100000" | sudo tee /etc/security/limits.conf >> /dev/null } setup_ufw() { echo "=====> setup_ufw" sudo sudo ufw enable sudo ufw default deny incoming 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" } install_ntpd() { echo "=====> install_ntpd" sudo timedatectl set-ntp no sudo apt-get -y install ntp sudo bash -c "cat > /etc/cron.hourly/ntpdate << EOF #!/bin/sh sudo service ntp stop sudo ntpdate -s ntp.ubuntu.com sudo service ntp start EOF" sudo chmod 755 /etc/cron.hourly/ntpdate echo "<===== install_ntpd" } install_haveged() { echo "=====> install_haveged" sudo apt-get -y install haveged sudo update-rc.d haveged defaults echo "<===== install_haveged" } allocate_swap() { echo "=====> allocate_swap" sudo apt-get -y install bc #sudo fallocate -l $(echo "$(free -b | awk '/Mem/{ print $2 }')*2" | bc -l) /swapfile sudo fallocate -l 1G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile sudo sh -c "printf '/swapfile none swap sw 0 0\n' >> /etc/fstab" sudo sh -c "printf 'vm.swappiness=10\n' >> /etc/sysctl.conf" sudo sysctl vm.vfs_cache_pressure=50 sudo sh -c "printf 'vm.vfs_cache_pressure = 50\n' >> /etc/sysctl.conf" echo "<===== allocate_swap" } 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} < clone_dapps" mkdir -p parity/dapps git clone https://github.com/oraclesorg/oracles-dapps-keys-generation.git parity/dapps/KeysGenerator git clone https://github.com/oraclesorg/oracles-dapps-voting.git parity/dapps/Voting git clone https://github.com/oraclesorg/oracles-dapps-validators.git parity/dapps/ValidatorsList echo "<===== clone_dapps" } install_nodejs() { echo "=====> install_nodejs" # curl -sL https://deb.nodesource.com/setup_0.12 | bash - curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - sudo apt-get update sudo apt-get install -y build-essential git unzip wget nodejs ntp cloud-utils # add symlink if it doesn't exist [[ ! -f /usr/bin/node ]] && sudo ln -s /usr/bin/nodejs /usr/bin/node echo "<===== install_nodejs" } start_pm2_via_systemd() { sudo npm install pm2 -g echo "=====> start_pm2_via_systemd" sudo bash -c "cat > /etc/systemd/system/oracles-pm2.service < 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 < install_netstats_via_systemd" git clone https://github.com/oraclesorg/eth-net-intelligence-api cd eth-net-intelligence-api #sed -i '/"web3"/c "web3": "0.19.x",' package.json npm install sudo npm install pm2 -g cat > app.json << EOL [ { "name" : "netstats_daemon", "script" : "app.js", "log_date_format" : "YYYY-MM-DD HH:mm:SS Z", "error_file" : "/home/${ADMIN_USERNAME}/logs/netstats_daemon.err", "out_file" : "/home/${ADMIN_USERNAME}/logs/netstats_daemon.out", "merge_logs" : false, "watch" : false, "max_restarts" : 100, "exec_interpreter" : "node", "exec_mode" : "fork_mode", "env": { "NODE_ENV" : "production", "RPC_HOST" : "localhost", "RPC_PORT" : "8545", "LISTENING_PORT" : "30300", "INSTANCE_NAME" : "${NODE_FULLNAME}", "CONTACT_DETAILS" : "${NODE_ADMIN_EMAIL}", "WS_SERVER" : "http://localhost:3000", "WS_SECRET" : "${NETSTATS_SECRET}", "VERBOSITY" : 2 } } ] EOL cd .. sudo bash -c "cat > /etc/systemd/system/oracles-netstats.service < 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 < 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 < use_deb_via_systemd" curl -LO "${PARITY_DEB_LOC}" sudo dpkg -i "$(basename ${PARITY_DEB_LOC})" sudo bash -c "cat > /etc/systemd/system/oracles-parity.service < configure_logrotate" sudo bash -c "cat > /home/${ADMIN_USERNAME}/oracles-logrotate.conf << EOF /home/${ADMIN_USERNAME}/logs/*.log { rotate 10 size 200M missingok compress copytruncate dateext dateformat %Y-%m-%d-%s olddir old } /home/${ADMIN_USERNAME}/.pm2/pm2.log { su ${ADMIN_USERNAME} ${ADMIN_USERNAME} rotate 10 size 200M missingok compress copytruncate dateext dateformat %Y-%m-%d-%s } EOF" sudo bash -c "cat > /etc/cron.hourly/oracles-logrotate <