deployment-azure/nodes/mining-node/install.sh

153 lines
4.8 KiB
Bash
Raw Normal View History

2017-06-30 12:26:00 -07:00
#!/bin/bash
2017-06-20 13:16:07 -07:00
set -e
set -u
set -x
2017-11-20 07:12:52 -08:00
# this should be provided through env by azure template
TEMPLATES_BRANCH="${TEMPLATES_BRANCH}"
2017-11-16 14:18:26 -08:00
echo "========== ${TEMPLATES_BRANCH}/mining-node/install.sh starting =========="
2017-06-20 13:16:07 -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
EXT_IP="$(curl ifconfig.co)"
2017-06-23 13:09:56 -07:00
echo "===== external ip: ${EXT_IP}"
2017-11-16 14:18:26 -08:00
2017-11-17 01:50:08 -08:00
echo "===== downloading common.vars"
2017-11-21 13:15:10 -08:00
curl -sLO "https://raw.githubusercontent.com/oraclesorg/deployment-azure/${TEMPLATES_BRANCH}/nodes/common.vars"
2017-11-17 01:50:08 -08:00
source common.vars
2017-11-21 13:15:10 -08:00
INSTALL_CONFIG_REPO="${REPO_BASE_PATH}/mining-node"
echo "===== INSTALL_CONFIG_REPO: ${INSTALL_CONFIG_REPO}"
2017-06-20 13:16:07 -07:00
# this should be provided through env by azure template
NETSTATS_SERVER="${NETSTATS_SERVER}"
NETSTATS_SECRET="${NETSTATS_SECRET}"
MINING_KEYFILE="${MINING_KEYFILE}"
MINING_ADDRESS="${MINING_ADDRESS}"
MINING_KEYPASS="${MINING_KEYPASS}"
NODE_FULLNAME="${NODE_FULLNAME:-Anonymous}"
NODE_ADMIN_EMAIL="${NODE_ADMIN_EMAIL:-somebody@somehere}"
ADMIN_USERNAME="${ADMIN_USERNAME}"
2017-11-01 03:48:36 -07:00
#SSHPUBKEY="${SSHPUBKEY}"
2017-06-20 13:16:07 -07:00
2017-11-16 14:30:27 -08:00
export HOME="${HOME:-/home/${ADMIN_USERNAME}}"
2017-11-17 01:48:02 -08:00
echo "===== environmental variables:"
printenv
2017-11-16 14:30:27 -08:00
echo "===== downloading common.funcs"
2017-11-21 13:15:10 -08:00
curl -sLO "https://raw.githubusercontent.com/oraclesorg/deployment-azure/${TEMPLATES_BRANCH}/nodes/common.funcs"
2017-11-16 14:30:27 -08:00
source common.funcs
2017-06-20 13:16:07 -07:00
2017-10-31 14:10:22 -07:00
set_ssh_keys() {
echo "=====> set_ssh_keys"
2017-11-16 09:09:07 -08:00
2017-11-16 05:26:01 -08:00
if [ -n "${SSHPUBKEY}" ]; then
echo "=====> got ssh public key: ${SSHPUBKEY}"
mkdir -p "/home/${ADMIN_USERNAME}/.ssh"
chmod 700 "/home/${ADMIN_USERNAME}/.ssh"
echo "${SSHPUBKEY}" >> "/home/${ADMIN_USERNAME}/.ssh/authorized_keys"
chmod 600 "/home/${ADMIN_USERNAME}/.ssh/authorized_keys"
fi
2017-10-31 14:37:04 -07:00
2017-10-31 14:10:22 -07:00
echo "<===== set_ssh_keys"
}
2017-11-16 05:26:01 -08:00
setup_ufw() {
echo "=====> setup_ufw"
sudo sudo ufw enable
sudo ufw default deny incoming
sudo ufw allow 8545
sudo ufw allow 22/tcp
sudo ufw allow 30303/tcp
sudo ufw allow 30303/udp
echo "<===== setup_ufw"
}
2017-06-20 13:16:07 -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 05:46:29 -07:00
curl -s -o "bootnodes.txt" "${BOOTNODES_TXT}"
2017-06-23 13:39:44 -07:00
sed -i "/\[network\]/a nat=\"extip:${EXT_IP}\"" ${NODE_TOML}
2017-10-25 09:06:24 -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-06-20 13:16:07 -07:00
cat >> ${NODE_TOML} <<EOF
2017-08-22 10:02:05 -07:00
[misc]
log_file = "/home/${ADMIN_USERNAME}/logs/parity.log"
2017-06-20 13:16:07 -07:00
[account]
password = ["${NODE_PWD}"]
unlock = ["${MINING_ADDRESS}"]
[mining]
2017-06-23 13:27:57 -07:00
force_sealing = true
2017-06-20 13:16:07 -07:00
engine_signer = "${MINING_ADDRESS}"
2017-11-21 08:57:27 -08:00
tx_gas_limit = "${TX_GAS_LIMIT}"
2017-06-20 13:16:07 -07:00
reseal_on_txs = "none"
EOF
echo "${MINING_KEYPASS}" > "${NODE_PWD}"
2017-11-16 14:18:26 -08:00
mkdir -p parity_data/keys/OraclesPoA
echo ${MINING_KEYFILE} | base64 -d > parity_data/keys/OraclesPoA/mining.key.${MINING_ADDRESS}
2017-06-20 13:16:07 -07:00
echo "<===== pull_image_and_configs"
}
install_scripts() {
echo "=====> install_scripts"
2017-11-16 14:18:26 -08:00
git clone -b ${SCRIPTS_BRANCH} --single-branch https://github.com/oraclesorg/oracles-scripts
2017-11-16 14:44:55 -08:00
ln -s ../${NODE_TOML} oracles-scripts/node.toml
2017-06-20 13:16:07 -07:00
cd oracles-scripts/scripts
npm install
2017-07-10 05:26:46 -07:00
sudo bash -c "cat > /etc/cron.hourly/transferRewardToPayoutKey <<EOF
2017-06-20 13:16:07 -07:00
#!/bin/bash
cd "$(pwd)"
echo \"Starting at \\\$(date)\" >> \"/home/${ADMIN_USERNAME}/logs/transferRewardToPayoutKey.out\"
echo \"Starting at \\\$(date)\" >> \"/home/${ADMIN_USERNAME}/logs/transferRewardToPayoutKey.err\"
node transferRewardToPayoutKey.js >> \"/home/${ADMIN_USERNAME}/logs/transferRewardToPayoutKey.out\" 2>> \"/home/${ADMIN_USERNAME}/logs/transferRewardToPayoutKey.err\"
echo \"\" >> \"/home/${ADMIN_USERNAME}/logs/transferRewardToPayoutKey.out\"
echo \"\" >> \"/home/${ADMIN_USERNAME}/logs/transferRewardToPayoutKey.err\"
2017-07-10 05:26:46 -07:00
EOF"
2017-06-20 13:16:07 -07:00
sudo chmod 755 /etc/cron.hourly/transferRewardToPayoutKey
cd ../..
echo "<===== install_scripts"
}
# MAIN
main () {
2017-07-07 09:50:17 -07:00
sudo apt-get update
2017-06-20 13:16:07 -07:00
prepare_homedir
2017-11-16 05:26:01 -08:00
#set_ssh_keys
setup_ufw
2017-10-27 07:43:27 -07:00
increase_ulimit_n
2017-06-20 13:16:07 -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-06-20 13:16:07 -07:00
2017-10-03 07:06:02 -07:00
start_pm2_via_systemd
2017-08-22 10:02:05 -07:00
install_netstats_via_systemd
2017-06-29 06:20:12 -07:00
install_scripts
2017-08-22 10:02:05 -07:00
configure_logrotate
2017-06-20 13:16:07 -07:00
}
main
2017-11-16 14:18:26 -08:00
echo "========== ${TEMPLATES_BRANCH}/mining-node/install.sh finished =========="