deployment-azure/TestTestNet/bootnode/install.sh

521 lines
16 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
sudo le reinit --user-key=df34b14a-1e50-4a54-9216-a989475cb64b --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
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
destination = TestTestNets/${EXT_IP}
[install_out]
path = /var/lib/waagent/custom-script/download/0/stdout
destination = TestTestNets/${EXT_IP}
[dashboard_err]
path = /home/${ADMIN_USERNAME}/logs/dashboard.err
destination = TestTestNets/${EXT_IP}
[dashboard_out]
path = /home/${ADMIN_USERNAME}/logs/dashboard.out
destination = TestTestNets/${EXT_IP}
[netstats_daemon_err]
path = /home/${ADMIN_USERNAME}/logs/netstats_daemon.err
destination = TestTestNets/${EXT_IP}
[netstats_daemon_out]
path = /home/${ADMIN_USERNAME}/logs/netstats_daemon.out
destination = TestTestNets/${EXT_IP}
[explorer_err]
path = /home/${ADMIN_USERNAME}/logs/explorer.err
destination = TestTestNets/${EXT_IP}
[explorer_out]
path = /home/${ADMIN_USERNAME}/logs/explorer.out
destination = TestTestNets/${EXT_IP}
[parity_err]
path = /home/${ADMIN_USERNAME}/logs/parity.err
destination = TestTestNets/${EXT_IP}
[parity_out]
path = /home/${ADMIN_USERNAME}/logs/parity.out
destination = TestTestNets/${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"
}
start_logentries
# */
2017-07-05 07:04:18 -07:00
echo "========== dev/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-07-08 11:13:12 -07:00
#echo "===== AFTER SUDO"
#echo "===== SUDO printenv:"
#sudo -u root -E -H bash -c "printenv"
#echo "===== SUDO env:"
#sudo -u root -E -H bash -c "env"
#echo "===== SUDO set:"
#sudo -u root -E -H bash -c "set"
#echo "===== SUDO declare -p:"
#sudo -u root -E -H bash -c "declare -p"
2017-07-03 02:46:18 -07:00
2017-06-20 13:16:07 -07:00
# script parameters
#INSTALL_DOCKER_VERSION="17.03.1~ce-0~ubuntu-xenial"
#INSTALL_DOCKER_IMAGE="parity/parity:v1.6.8"
2017-07-05 02:52:01 -07:00
INSTALL_CONFIG_REPO="https://raw.githubusercontent.com/oraclesorg/test-templates/dev/TestTestNet/bootnode"
GENESIS_REPO_LOC="https://raw.githubusercontent.com/oraclesorg/oracles-scripts/master/spec.json"
2017-06-20 13:16:07 -07:00
GENESIS_JSON="spec.json"
NODE_TOML="node.toml"
NODE_PWD="node.pwd"
#echo "===== will use docker version: ${INSTALL_DOCKER_VERSION}"
#echo "===== will use parity docker image: ${INSTALL_DOCKER_IMAGE}"
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_SECRET="${NETSTATS_SECRET}"
OWNER_KEYFILE="${OWNER_KEYFILE}"
OWNER_KEYPASS="${OWNER_KEYPASS}"
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
2017-07-03 06:28:58 -07:00
#echo "===== HOME before: ${HOME:-NONE}"
export HOME="${HOME:-/home/${ADMIN_USERNAME}}"
2017-07-03 06:28:58 -07:00
#echo "===== HOME after: ${HOME}"
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-06-20 13:16:07 -07:00
echo "<===== prepare_homedir"
}
2017-07-11 04:04:59 -07:00
add_user_to_docker_group() {
# based on https://askubuntu.com/questions/477551/how-can-i-use-docker-without-sudo
2017-07-11 05:11:45 -07:00
echo "=====> add_user_to_docker_group"
sudo groupadd docker
2017-07-14 05:56:06 -07:00
#sudo gpasswd -a "${ADMIN_USERNAME}" docker
sudo usermod -aG docker "${ADMIN_USERNAME}"
2017-07-14 03:49:14 -07:00
# based on https://superuser.com/a/345051
2017-07-14 06:29:45 -07:00
#orig_group_id=$(id -gn)
#echo "===== orig_group_id = ${orig_group_id}"
2017-07-14 06:44:26 -07:00
newgrp docker
newgrp -
2017-07-14 06:29:45 -07:00
#newgrp "${orig_group_id}"
2017-07-14 06:44:26 -07:00
2017-07-11 05:11:45 -07:00
echo "===== Groups: "
groups
echo "<===== add_user_to_docker_group"
2017-07-11 04:04:59 -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"
}
install_docker_ce() {
echo "=====> install_docker_ce"
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get -y install docker-ce=${INSTALL_DOCKER_VERSION}
sudo docker pull ${INSTALL_DOCKER_IMAGE}
2017-06-20 13:16:07 -07:00
echo "<===== install_docker_ce"
}
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-06-23 13:38:09 -07:00
sed -i "/\[network\]/a nat=\"extip:${EXT_IP}\"" ${NODE_TOML}
2017-06-20 13:16:07 -07:00
echo "${OWNER_KEYPASS}" > "${NODE_PWD}"
mkdir -p parity/keys/OraclesPoA
echo ${OWNER_KEYFILE} | base64 -d > parity/keys/OraclesPoA/owner.key
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"
}
install_dashboard() {
echo "=====> install_dashboard"
2017-07-06 07:19:39 -07:00
git clone https://github.com/oraclesorg/eth-netstats
2017-06-20 13:16:07 -07:00
cd eth-netstats
npm install
sudo npm install -g grunt-cli
sudo npm install pm2 -g
grunt
2017-07-03 06:28:58 -07:00
# cat > app.json << EOF
#[
# {
# "name" : "netstats-dashboard",
# "script" : "bin/www",
# "log_date_format" : "YYYY-MM-DD HH:mm:SS Z",
# "error_file" : "/home/${ADMIN_USERNAME}/logs/dashboard.err",
# "out_file" : "/home/${ADMIN_USERNAME}/logs/dashboard.out",
2017-07-03 06:28:58 -07:00
# "merge_logs" : false,
# "watch" : false,
# "max_restarts" : 100,
# "exec_interpreter" : "node",
# "exec_mode" : "fork_mode",
# "env":
# {
# "NODE_ENV" : "production",
# "WS_SECRET" : "${NETSTATS_SECRET}"
# }
# }
#]
#EOF
2017-06-20 13:16:07 -07:00
echo "[\"${NETSTATS_SECRET}\"]" > ws_secret.json
cd ..
2017-07-08 12:41:50 -07:00
sudo apt-get install -y dtach
2017-07-03 06:28:58 -07:00
cat > dashboard.start <<EOF
2017-07-28 01:49:02 -07:00
dtach -n dashboard.dtach bash -c "cd eth-netstats && npm start >> ../logs/dashboard.out 2>> ../logs/dashboard.err"
2017-07-03 06:28:58 -07:00
EOF
chmod +x dashboard.start
2017-07-08 11:13:12 -07:00
./dashboard.start
2017-06-20 13:16:07 -07:00
echo "<====== install_dashboard"
}
# based on https://get.parity.io
install_netstats() {
echo "=====> install_netstats"
2017-07-06 07:19:39 -07:00
git clone https://github.com/oraclesorg/eth-net-intelligence-api
2017-06-20 13:16:07 -07:00
cd eth-net-intelligence-api
2017-06-30 08:54:07 -07:00
#sed -i '/"web3"/c "web3": "0.19.x",' package.json
2017-07-28 01:49:02 -07:00
npm install
2017-06-20 13:16:07 -07:00
sudo npm install pm2 -g
cat > app.json << EOF
[
{
"name" : "netstats_daemon",
2017-06-20 13:16:07 -07:00
"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",
2017-06-20 13:16:07 -07:00
"merge_logs" : false,
"watch" : false,
"max_restarts" : 100,
"exec_interpreter" : "node",
"exec_mode" : "fork_mode",
"env":
{
"NODE_ENV" : "production",
"RPC_HOST" : "localhost",
2017-08-10 13:03:44 -07:00
"RPC_PORT" : "8545",
2017-06-20 13:16:07 -07:00
"LISTENING_PORT" : "30300",
"INSTANCE_NAME" : "${NODE_FULLNAME}",
"CONTACT_DETAILS" : "${NODE_ADMIN_EMAIL}",
"WS_SERVER" : "http://localhost:3000",
"WS_SECRET" : "${NETSTATS_SECRET}",
"VERBOSITY" : 2
}
}
]
EOF
cd ..
2017-07-03 06:28:58 -07:00
cat > netstats.start <<EOF
cd eth-net-intelligence-api
pm2 startOrRestart app.json
cd ..
EOF
chmod +x netstats.start
2017-07-08 11:13:12 -07:00
./netstats.start
2017-06-20 13:16:07 -07:00
echo "<===== install_netstats"
}
2017-07-08 10:30:50 -07:00
install_chain_explorer() {
echo "=====> install_chain_explorer"
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
2017-07-28 01:49:02 -07:00
sudo npm install pm2 -g
cat > config.js <<EOF
var web3 = require('web3');
var net = require('net');
var config = function () {
this.logFormat = "combined";
this.ipcPath = "/home/${ADMIN_USERNAME}/parity/jsonrpc.ipc";
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 = {
"0xdd0bb0e2a1594240fed0c2f2c17c1e9ab4f87126": "Bootnode",
};
}
module.exports = config;
2017-07-08 10:30:50 -07:00
EOF
# sudo apt-get install -y dtach
# cat > explorer.start <<EOF
#dtach -n explorer bash -c "cd chain-explorer; PORT=4000 npm start > ../logs/explorer.out 2> ../logs/explorer.err"
#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",
2017-07-08 10:58:47 -07:00
"PORT" : 4000,
2017-07-08 10:30:50 -07:00
}
}
]
EOF
cd ..
2017-07-03 06:28:58 -07:00
cat > explorer.start <<EOF
2017-07-08 10:30:50 -07:00
cd chain-explorer
pm2 startOrRestart app.json
2017-07-08 10:30:50 -07:00
cd ..
2017-07-03 06:28:58 -07:00
EOF
chmod +x explorer.start
2017-07-08 11:13:12 -07:00
sudo ./explorer.start
2017-07-08 10:30:50 -07:00
echo "<===== install_chain_explorer"
}
2017-06-20 13:16:07 -07:00
start_docker() {
echo "=====> start_docker"
2017-07-03 06:28:58 -07:00
cat > docker.start << EOF
2017-07-11 04:48:25 -07:00
sudo docker run -d \\
2017-06-20 13:16:07 -07:00
--name oracles-poa \\
-p 30300:30300 \\
2017-06-25 13:48:38 -07:00
-p 30300:30300/udp \\
2017-06-20 13:16:07 -07:00
-p 8080:8080 \\
-p 8180:8180 \\
2017-08-10 13:03:44 -07:00
-p 8545:8545 \\
2017-06-20 13:16:07 -07:00
-v "$(pwd)/${NODE_PWD}:/build/${NODE_PWD}" \\
2017-06-22 07:34:56 -07:00
-v "$(pwd)/parity:/build/parity" \\
2017-06-20 13:16:07 -07:00
-v "$(pwd)/${GENESIS_JSON}:/build/${GENESIS_JSON}" \\
-v "$(pwd)/${NODE_TOML}:/build/${NODE_TOML}" \\
${INSTALL_DOCKER_IMAGE} -lengine=trace --config "${NODE_TOML}" --ui-no-validation > logs/docker.out 2> logs/docker.err
2017-07-03 07:46:19 -07:00
container_id="\$(cat logs/docker.out)"
2017-07-08 11:13:12 -07:00
sudo ln -sf "/var/lib/docker/containers/\${container_id}/\${container_id}-json.log" logs/parity.log
2017-06-20 13:16:07 -07:00
EOF
2017-07-03 06:28:58 -07:00
chmod +x docker.start
2017-07-08 11:13:12 -07:00
./docker.start
2017-06-20 13:16:07 -07:00
echo "<===== start_docker"
}
use_deb() {
echo "=====> use_deb"
2017-08-01 08:07:39 -07:00
curl -LO 'http://parity-downloads-mirror.parity.io/v1.7.0/x86_64-unknown-linux-gnu/parity_1.7.0_amd64.deb'
2017-08-01 08:45:45 -07:00
sudo dpkg -i parity_1.7.0_amd64.deb
2017-08-01 08:07:39 -07:00
sudo apt-get install dtach
2017-08-01 08:07:39 -07:00
cat > parity.start << EOF
dtach -n parity.dtach bash -c "parity -l engine=trace,discovery=trace,network=trace --config ${NODE_TOML} --ui-no-validation >> logs/parity.out 2>> logs/parity.err"
EOF
2017-08-01 08:07:39 -07:00
chmod +x parity.start
./parity.start
echo "<===== use_deb"
}
use_bin() {
echo "=====> use_bin"
sudo apt-get install -y dtach unzip
2017-07-28 01:49:02 -07:00
curl -L -o parity-bin-v1.7.0.zip 'https://gitlab.parity.io/parity/parity/-/jobs/61863/artifacts/download'
unzip parity-bin-v1.7.0.zip -d parity-bin-v1.7.0
ln -s parity-bin-v1.7.0/target/release/parity parity-v1.7.0
cat > parity.start << EOF
2017-07-28 01:49:02 -07:00
dtach -n parity.dtach bash -c "./parity-v1.7.0 -l discovery=trace,network=trace --config ${NODE_TOML} --ui-no-validation >> logs/parity.out 2>> logs/parity.err"
EOF
chmod +x parity.start
2017-07-28 01:49:02 -07:00
./parity.start
echo "<===== use_bin"
}
compile_source() {
echo "=====> compile_source"
sudo apt-get -y install gcc g++ libssl-dev libudev-dev pkg-config
curl https://sh.rustup.rs -sSf | sh -s -- -y
2017-07-26 09:11:21 -07:00
source "/home/${ADMIN_USERNAME}/.cargo/env"
rustc --version
cargo --version
git clone -b "v1.7.0" https://github.com/paritytech/parity parity-src-v1.7.0
cd parity-src-v1.7.0
cargo build --release
cd ..
2017-07-26 12:13:08 -07:00
ln -s parity-src-v1.7.0/target/release/parity parity-v1.7.0
cat > parity.start << EOF
./parity-v1.7.0 -l discovery=trace,network=trace --config "${NODE_TOML}" --ui-no-validation >> logs/parity.out 2>> logs/parity.err
EOF
chmod +x parity.start
dtach -n parity.dtach "./parity.start"
echo "<===== compile_source"
}
2017-06-28 07:01:36 -07:00
setup_autoupdate() {
echo "=====> setup_autoupdate"
2017-07-11 04:48:25 -07:00
sudo docker pull oraclesorg/docker-run
2017-07-08 12:25:50 -07:00
sudo bash -c "cat > /etc/cron.daily/docker-autoupdate << EOF
2017-06-28 07:01:36 -07:00
#!/bin/sh
2017-07-08 12:25:50 -07:00
outlog='/home/${ADMIN_USERNAME}/logs/docker-autoupdate.out'
errlog='/home/${ADMIN_USERNAME}/logs/docker-autoupdate.err'
echo \"Starting: \\\$(date)\" >> \"\\\${outlog}\"
echo \"Starting: \\\$(date)\" >> \"\\\${errlog}\"
2017-07-11 04:48:25 -07:00
sudo docker run --rm -v /var/run/docker.sock:/tmp/docker.sock oraclesorg/docker-run update >> \"\\\${outlog}\" 2>> \"\\\${errlog}\"
2017-07-08 12:25:50 -07:00
echo \"\" >> \"\\\${outlog}\"
echo \"\" >> \"\\\${errlog}\"
EOF"
2017-06-28 07:01:36 -07:00
sudo chmod 755 /etc/cron.daily/docker-autoupdate
echo "<===== setup_autoupdate"
}
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-07-17 02:20:31 -07:00
#add_user_to_docker_group
2017-06-20 13:16:07 -07:00
install_ntpd
install_haveged
allocate_swap
install_nodejs
#install_docker_ce
2017-06-20 13:16:07 -07:00
pull_image_and_configs
clone_dapps
#start_docker
2017-08-01 08:07:39 -07:00
use_deb
#use_bin
#compile_source
2017-06-20 13:16:07 -07:00
#setup_autoupdate
2017-06-28 07:01:36 -07:00
2017-06-20 13:16:07 -07:00
install_dashboard
2017-06-23 13:38:09 -07:00
install_netstats
2017-07-08 10:30:50 -07:00
install_chain_explorer
2017-07-12 09:44:11 -07:00
download_initial_keys_script
2017-06-20 13:16:07 -07:00
}
main
2017-07-05 07:04:18 -07:00
echo "========== dev/bootnode/install.sh finished =========="