deployment-azure/TestTestNet/bootnode/install.sh

424 lines
12 KiB
Bash
Raw Normal View History

2017-06-30 11:48:28 -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"
2017-07-26 07:39:32 -07:00
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
2017-07-26 07:56:31 -07:00
sudo apt-get install -y logentries
2017-08-31 06:56:39 -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/dashboard.err
touch /home/${ADMIN_USERNAME}/logs/dashboard.out
2017-08-28 12:04:43 -07:00
touch /home/${ADMIN_USERNAME}/logs/parity.log
touch /home/${ADMIN_USERNAME}/logs/netstats_daemon.err
touch /home/${ADMIN_USERNAME}/logs/netstats_daemon.out
touch /home/${ADMIN_USERNAME}/logs/explorer.err
touch /home/${ADMIN_USERNAME}/logs/explorer.out
touch /home/${ADMIN_USERNAME}/logs/parity.err
touch /home/${ADMIN_USERNAME}/logs/parity.out
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}
[dashboard_err]
path = /home/${ADMIN_USERNAME}/logs/dashboard.err
2017-09-29 08:29:56 -07:00
destination = dev-mainnet/${EXT_IP}
[dashboard_out]
path = /home/${ADMIN_USERNAME}/logs/dashboard.out
2017-09-29 08:29:56 -07:00
destination = dev-mainnet/${EXT_IP}
2017-08-28 12:04:43 -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-28 12:04:43 -07:00
[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}
[explorer_err]
path = /home/${ADMIN_USERNAME}/logs/explorer.err
2017-09-29 08:29:56 -07:00
destination = dev-mainnet/${EXT_IP}
[explorer_out]
path = /home/${ADMIN_USERNAME}/logs/explorer.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}
EOF"
2017-07-26 07:56:31 -07:00
sudo apt-get install -y logentries-daemon
sudo service logentries start
echo "<===== start_logentries"
}
2017-10-19 04:01:17 -07:00
#start_logentries
# */
2017-10-02 14:18:38 -07:00
echo "========== dev-mainnet/bootnode/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:04:31 -07:00
echo "===== external ip: ${EXT_IP}"
2017-06-30 13:11:36 -07:00
echo "===== printenv:"
2017-06-20 13:16:07 -07:00
printenv
2017-06-30 13:11:36 -07:00
echo "===== env:"
env
echo "===== set:"
set
echo "===== declare -p:"
declare -p
2017-06-20 13:16:07 -07:00
2017-10-03 03:52:19 -07:00
INSTALL_CONFIG_REPO="https://raw.githubusercontent.com/oraclesorg/test-templates/dev-mainnet/TestTestNet/bootnode"
2017-10-24 06:36:11 -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"
2017-10-21 09:14:44 -07:00
BOOTNODES_TXT="https://raw.githubusercontent.com/oraclesorg/test-templates/dev-mainnet/TestTestNet/bootnodes.txt"
2017-10-24 06:36:11 -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-11-10 04:51:08 -08:00
PARITY_BIN_LOC="https://transfer.sh/PhhDc/parity"
2017-06-20 13:16:07 -07:00
echo "===== repo base path: ${INSTALL_CONFIG_REPO}"
# this should be provided through env by azure template
2017-10-02 14:18:38 -07:00
NETSTATS_SERVER="${NETSTATS_SERVER}"
2017-06-20 13:16:07 -07:00
NETSTATS_SECRET="${NETSTATS_SECRET}"
NODE_FULLNAME="${NODE_FULLNAME:-Bootnode}"
NODE_ADMIN_EMAIL="${NODE_ADMIN_EMAIL:-somebody@somehere}"
ADMIN_USERNAME="${ADMIN_USERNAME}"
2017-07-03 02:46:18 -07:00
export HOME="${HOME:-/home/${ADMIN_USERNAME}}"
2017-06-20 13:16:07 -07:00
prepare_homedir() {
echo "=====> prepare_homedir"
# ln -s "$(pwd)" "/home/${ADMIN_USERNAME}/script-dir"
cd "/home/${ADMIN_USERNAME}"
2017-06-30 14:01:16 -07:00
echo "Now changed directory to: $(pwd)"
2017-07-03 06:28:58 -07:00
mkdir -p logs
2017-08-28 12:04:43 -07:00
mkdir -p logs/old
2017-06-20 13:16:07 -07:00
echo "<===== prepare_homedir"
}
2017-11-10 03:04:34 -08:00
setup_ufw() {
echo "=====> prepare_homedir"
sudo sudo ufw enable
2017-11-10 04:56:08 -08:00
sudo ufw default deny incoming
2017-11-10 05:43:45 -08:00
sudo ufw allow 443
2017-11-10 05:20:34 -08:00
sudo ufw allow 8545
2017-11-10 03:04:34 -08:00
sudo ufw allow 22/tcp
sudo ufw allow 30303/tcp
sudo ufw allow 30303/udp
echo "<===== prepare_homedir"
}
2017-10-27 07:04:34 -07:00
increase_ulimit_n() {
2017-10-27 08:55:15 -07:00
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
2017-10-27 07:04:34 -07:00
}
2017-06-20 13:16:07 -07:00
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}"
2017-10-21 09:14:44 -07:00
curl -s -o "bootnodes.txt" "${BOOTNODES_TXT}"
2017-06-20 13:16:07 -07:00
curl -s -O "${INSTALL_CONFIG_REPO}/${NODE_TOML}"
2017-06-23 13:38:09 -07:00
sed -i "/\[network\]/a nat=\"extip:${EXT_IP}\"" ${NODE_TOML}
2017-10-25 06:42:42 -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-08-28 12:04:43 -07:00
cat >> ${NODE_TOML} <<EOF
[misc]
log_file = "/home/${ADMIN_USERNAME}/logs/parity.log"
EOF
2017-06-20 13:16:07 -07:00
mkdir -p parity/keys/OraclesPoA
echo "<===== pull_image_and_configs"
}
clone_dapps() {
echo "=====> 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"
}
2017-08-31 03:37:40 -07:00
start_pm2_via_systemd() {
echo "=====> start_pm2_via_systemd"
2017-10-03 07:06:02 -07:00
sudo npm install pm2 -g
sudo bash -c "cat > /etc/systemd/system/oracles-pm2.service <<EOF
2017-08-31 03:37:40 -07:00
[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-28 12:04:43 -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
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}",
2017-10-02 14:18:38 -07:00
"WS_SERVER" : "http://${NETSTATS_SERVER}:3000",
2017-08-28 12:04:43 -07:00
"WS_SECRET" : "${NETSTATS_SECRET}",
"VERBOSITY" : 2
}
}
]
EOL
cd ..
sudo bash -c "cat > /etc/systemd/system/oracles-netstats.service <<EOF
[Unit]
Description=oracles netstats service
2017-08-31 03:37:40 -07:00
After=oracles-pm2.service
2017-08-28 12:04:43 -07:00
[Service]
Type=oneshot
RemainAfterExit=true
User=${ADMIN_USERNAME}
Group=${ADMIN_USERNAME}
Environment=MYVAR=myval
WorkingDirectory=/home/${ADMIN_USERNAME}/eth-net-intelligence-api
2017-08-31 03:37:40 -07:00
ExecStart=/usr/bin/pm2 startOrRestart app.json
2017-08-28 12:04:43 -07:00
[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 06:36:11 -07:00
curl -LO "${PARITY_DEB_LOC}"
sudo dpkg -i "$(basename ${PARITY_DEB_LOC})"
2017-08-28 12:04:43 -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}
2017-11-10 04:51:08 -08:00
ExecStart=/usr/bin/parity --config=node.toml
2017-08-28 12:04:43 -07:00
Restart=always
[Install]
WantedBy=multi-user.target
EOF"
sudo systemctl enable oracles-parity
sudo systemctl start oracles-parity
echo "<===== use_deb_via_systemd"
}
2017-11-10 04:51:08 -08:00
use_bin_via_systemd() {
echo "=====> use_bin_via_systemd"
2017-11-10 05:19:42 -08:00
curl -o parity-nouncles -L "${PARITY_BIN_LOC}"
2017-11-10 05:43:45 -08:00
chmod +x parity-nouncles
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install -y libstdc++6
2017-11-10 04:51:08 -08: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}
2017-11-10 05:19:42 -08:00
ExecStart=/home/${ADMIN_USERNAME}/parity-nouncles --config=node.toml
2017-11-10 04:51:08 -08:00
Restart=always
[Install]
WantedBy=multi-user.target
EOF"
sudo systemctl enable oracles-parity
sudo systemctl start oracles-parity
echo "<===== use_bin_via_systemd"
}
2017-08-28 12:04:43 -07:00
configure_logrotate() {
echo "=====> configure_logrotate"
2017-09-29 08:29:56 -07:00
2017-11-01 11:37:34 -07:00
sudo bash -c "cat > /home/${ADMIN_USERNAME}/oracles-logrotate.conf << EOF
2017-08-28 12:04:43 -07:00
/home/${ADMIN_USERNAME}/logs/*.log {
rotate 10
size 200M
missingok
compress
copytruncate
dateext
dateformat %Y-%m-%d-%s
olddir old
}
2017-11-01 11:37:34 -07:00
2017-08-28 12:04:43 -07:00
/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:05 -07:00
}
EOF"
2017-11-01 11:37:34 -07:00
sudo bash -c "cat > /etc/cron.hourly/oracles-logrotate <<EOF
#!/bin/bash
2017-11-06 10:36:12 -08:00
/usr/sbin/logrotate /home/${ADMIN_USERNAME}/oracles-logrotate.conf
2017-11-01 11:37:34 -07:00
EOF"
sudo chmod 755 /etc/cron.hourly/oracles-logrotate
2017-08-28 12:04:43 -07:00
echo "<===== configure_logrotate"
}
2017-07-12 09:44:11 -07:00
download_initial_keys_script() {
echo "=====> download_initial_keys_script"
git clone https://github.com/oraclesorg/oracles-initial-keys
cd oracles-initial-keys
npm install
cd ..
echo "<===== download_initial_keys_script"
}
2017-06-20 13:16:07 -07:00
# MAIN
main () {
2017-07-07 09:50:47 -07:00
sudo apt-get update
2017-06-20 13:16:07 -07:00
prepare_homedir
2017-11-10 03:04:34 -08:00
setup_ufw
2017-10-27 07:04:34 -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
clone_dapps
2017-11-10 04:51:08 -08:00
#use_deb_via_systemd
use_bin_via_systemd
2017-09-29 08:29:56 -07:00
2017-08-31 03:37:40 -07:00
start_pm2_via_systemd
2017-08-28 12:04:43 -07:00
install_netstats_via_systemd
2017-08-28 12:04:43 -07:00
configure_logrotate
2017-07-12 09:44:11 -07:00
download_initial_keys_script
2017-06-20 13:16:07 -07:00
}
main
2017-10-02 14:18:38 -07:00
echo "========== dev-mainnet/bootnode/install.sh finished =========="