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

366 lines
11 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
EXT_IP="$(curl ifconfig.co)"
# Install logentries daemon /*
start_logentries() {
echo "=====> start_logentries"
sudo bash -c "echo 'deb http://rep.logentries.com/ trusty main' > /etc/apt/sources.list.d/logentries.list"
sudo bash -c "gpg --keyserver pgp.mit.edu --recv-keys C43C79AD && gpg -a --export C43C79AD | apt-key add -"
sudo apt-get update
sudo apt-get install -y logentries
2017-08-31 06:55:59 -07:00
sudo le reinit --user-key=0665901a-e843-41c5-82c1-2cc4b39f0b21 --pull-server-side-config=False
mkdir -p /home/${ADMIN_USERNAME}/logs
touch /home/${ADMIN_USERNAME}/logs/netstats_daemon.err
touch /home/${ADMIN_USERNAME}/logs/netstats_daemon.out
touch /home/${ADMIN_USERNAME}/logs/parity.err
touch /home/${ADMIN_USERNAME}/logs/parity.out
2017-08-22 10:02:05 -07:00
touch /home/${ADMIN_USERNAME}/logs/parity.log
2017-08-09 12:59:46 -07:00
touch /home/${ADMIN_USERNAME}/logs/transferRewardToPayoutKey.out
touch /home/${ADMIN_USERNAME}/logs/transferRewardToPayoutKey.err
sudo bash -c "cat >> /etc/le/config << EOF
[install_err]
path = /var/lib/waagent/custom-script/download/0/stderr
2017-09-29 08:29:56 -07:00
destination = dev-mainnet/${EXT_IP}
[install_out]
path = /var/lib/waagent/custom-script/download/0/stdout
2017-09-29 08:29:56 -07:00
destination = dev-mainnet/${EXT_IP}
[netstats_daemon_err]
path = /home/${ADMIN_USERNAME}/logs/netstats_daemon.err
2017-09-29 08:29:56 -07:00
destination = dev-mainnet/${EXT_IP}
[netstats_daemon_out]
path = /home/${ADMIN_USERNAME}/logs/netstats_daemon.out
2017-09-29 08:29:56 -07:00
destination = dev-mainnet/${EXT_IP}
[parity_err]
path = /home/${ADMIN_USERNAME}/logs/parity.err
2017-09-29 08:29:56 -07:00
destination = dev-mainnet/${EXT_IP}
[parity_out]
path = /home/${ADMIN_USERNAME}/logs/parity.out
2017-09-29 08:29:56 -07:00
destination = dev-mainnet/${EXT_IP}
2017-08-22 10:02:05 -07:00
[parity_log]
path = /home/${ADMIN_USERNAME}/logs/parity.log
2017-09-29 08:29:56 -07:00
destination = dev-mainnet/${EXT_IP}
2017-08-09 12:59:46 -07:00
[transferReward_out]
path = /home/${ADMIN_USERNAME}/logs/transferRewardToPayoutKey.out
2017-09-29 08:29:56 -07:00
destination = dev-mainnet/${EXT_IP}
2017-08-09 12:59:46 -07:00
[transferReward_err]
path = /home/${ADMIN_USERNAME}/logs/transferRewardToPayoutKey.err
2017-09-29 08:29:56 -07:00
destination = dev-mainnet/${EXT_IP}
EOF"
sudo apt-get install -y logentries-daemon
sudo service logentries start
echo "<===== start_logentries"
}
2017-10-19 04:01:38 -07:00
#start_logentries
# */
2017-10-02 14:18:38 -07:00
echo "========== dev-mainnet/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-06-23 13:09:56 -07:00
echo "===== external ip: ${EXT_IP}"
2017-06-20 13:16:07 -07:00
echo "===== environmental variables:"
printenv
# script parameters
2017-10-03 03:52:19 -07:00
INSTALL_CONFIG_REPO="https://raw.githubusercontent.com/oraclesorg/test-templates/dev-mainnet/TestTestNet/mining-node"
2017-10-24 07:50:35 -07:00
GENESIS_REPO_LOC="https://raw.githubusercontent.com/oraclesorg/oracles-scripts/sokol/spec.json"
2017-06-20 13:16:07 -07:00
GENESIS_JSON="spec.json"
NODE_TOML="node.toml"
NODE_PWD="node.pwd"
2017-10-03 03:52:19 -07:00
BOOTNODES_TXT="https://raw.githubusercontent.com/oraclesorg/test-templates/dev-mainnet/TestTestNet/bootnodes.txt"
2017-10-24 07:50:35 -07:00
PARITY_DEB_LOC="https://parity-downloads-mirror.parity.io/v1.8.1/x86_64-unknown-linux-gnu/parity_1.8.1_amd64.deb"
2017-07-03 09:18:32 -07:00
export HOME="${HOME:-/home/${ADMIN_USERNAME}}"
2017-06-20 13:16:07 -07:00
echo "===== repo base path: ${INSTALL_CONFIG_REPO}"
# 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}"
prepare_homedir() {
echo "=====> prepare_homedir"
#ln -s "$(pwd)" "/home/${ADMIN_USERNAME}/script-dir"
cd "/home/${ADMIN_USERNAME}"
2017-07-03 09:18:32 -07:00
mkdir -p logs
2017-08-22 10:02:05 -07:00
mkdir -p logs/old
2017-06-20 13:16:07 -07:00
echo "<===== prepare_homedir"
}
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"
}
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"
}
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}"
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}"
reseal_on_txs = "none"
EOF
echo "${MINING_KEYPASS}" > "${NODE_PWD}"
mkdir -p parity/keys/OraclesPoA
echo ${MINING_KEYFILE} | base64 -d > parity/keys/OraclesPoA/mining.key.${MINING_ADDRESS}
echo "<===== pull_image_and_configs"
}
2017-10-03 07:06:02 -07:00
start_pm2_via_systemd() {
echo "=====> start_pm2_via_systemd"
2017-10-12 12:25:11 -07:00
sudo npm install pm2 -g
2017-10-03 07:06:02 -07:00
sudo bash -c "cat > /etc/systemd/system/oracles-pm2.service <<EOF
[Unit]
Description=oracles pm2 service
After=network.target
[Service]
Type=oneshot
RemainAfterExit=true
User=${ADMIN_USERNAME}
Group=${ADMIN_USERNAME}
Environment=MYVAR=myval
WorkingDirectory=/home/${ADMIN_USERNAME}
ExecStart=/usr/bin/pm2 ping
[Install]
WantedBy=multi-user.target
EOF"
sudo systemctl enable oracles-pm2
sudo systemctl start oracles-pm2
echo "<===== start_pm2_via_systemd"
}
2017-06-20 13:16:07 -07:00
# based on https://get.parity.io
2017-08-22 10:02:05 -07:00
install_netstats_via_systemd() {
echo "=====> 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://${NETSTATS_SERVER}:3000",
"WS_SECRET" : "${NETSTATS_SECRET}",
"VERBOSITY" : 2
}
}
]
EOL
cd ..
sudo bash -c "cat > /etc/systemd/system/oracles-netstats.service <<EOF
[Unit]
Description=oracles netstats service
After=network.target
[Service]
Type=oneshot
RemainAfterExit=true
User=${ADMIN_USERNAME}
Group=${ADMIN_USERNAME}
Environment=MYVAR=myval
WorkingDirectory=/home/${ADMIN_USERNAME}/eth-net-intelligence-api
ExecStart=/usr/bin/pm2 startOrRestart app.json
[Install]
WantedBy=multi-user.target
EOF"
sudo systemctl enable oracles-netstats
sudo systemctl start oracles-netstats
echo "<===== install_netstats_via_systemd"
}
use_deb_via_systemd() {
echo "=====> use_deb_via_systemd"
2017-10-24 07:50:35 -07:00
curl -LO "${PARITY_DEB_LOC}"
sudo dpkg -i "$(basename ${PARITY_DEB_LOC})"
2017-08-22 10:02:05 -07:00
sudo bash -c "cat > /etc/systemd/system/oracles-parity.service <<EOF
[Unit]
Description=oracles parity service
After=network.target
[Service]
User=${ADMIN_USERNAME}
Group=${ADMIN_USERNAME}
WorkingDirectory=/home/${ADMIN_USERNAME}
ExecStart=/usr/bin/parity --config=node.toml
Restart=always
[Install]
WantedBy=multi-user.target
EOF"
sudo systemctl enable oracles-parity
sudo systemctl start oracles-parity
echo "<===== use_deb_via_systemd"
}
2017-06-20 13:16:07 -07:00
install_scripts() {
echo "=====> install_scripts"
2017-10-24 07:50:35 -07:00
git clone -b sokol --single-branch https://github.com/oraclesorg/oracles-scripts
2017-08-09 12:59:46 -07: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"
}
2017-08-22 10:02:05 -07:00
configure_logrotate() {
echo "=====> configure_logrotate"
2017-09-29 08:29:56 -07:00
2017-08-22 10:02:05 -07:00
sudo bash -c "cat > /etc/logrotate.d/oracles.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
2017-09-17 00:51:27 -07:00
}
EOF"
2017-08-22 10:02:05 -07:00
echo "<===== configure_logrotate"
}
2017-06-20 13:16:07 -07:00
# 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-09-29 08:29:56 -07:00
2017-06-20 13:16:07 -07:00
install_ntpd
install_haveged
allocate_swap
install_nodejs
pull_image_and_configs
2017-08-22 10:02:05 -07:00
use_deb_via_systemd
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-10-02 14:18:38 -07:00
echo "========== dev-mainnet/mining-node/install.sh finished =========="