Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rupshabagchi committed Jan 26, 2017
0 parents commit 09fc6d6
Show file tree
Hide file tree
Showing 3,691 changed files with 856,848 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Scripts to set ethereum private network with docker and netstats
10 changes: 10 additions & 0 deletions eth-net-intelligence-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.DS_Store
app.json
*/**/.DS_Store
node_modules
npm-debug.log
config.js
*~
*.swp
*.pem
.node-xmlhttprequest-*
13 changes: 13 additions & 0 deletions eth-net-intelligence-api/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: node_js
node_js:
- "0.12"
env:
global:
- secure: Qdkmi13nqcXskABBhbuGZmRakh4orOW1dalkSCyUbzGuYf0OdYF8ttNVuJa0WSWI4KhNXhtz2p3I8dM95wL++LCVqXFmIvZtX8Nca36KlNxIPNXPjn0odayh+c4pgrhrbz8TDmDXl9IPuZmNz8HHtN7xmIn6YDcm13wA3gTmfwo=
- RPC_HOST=localhost
- RPC_PORT=8545
- LISTENING_PORT=30303
- INSTANCE_NAME="Travis Node"
- CONTACT_DETAILS="[email protected]"
- WS_SERVER="wss://rpc.ethstats.net"
- NODE_ENV="production"
61 changes: 61 additions & 0 deletions eth-net-intelligence-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
## Dockerfile for eth-net-intelligence-api (build from git).
##
## Build via:
#
# `docker build -t ethnetintel:latest .`
#
## Run via:
#
# `docker run -v <path to app.json>:/home/ethnetintel/eth-net-intelligence-api/app.json ethnetintel:latest`
#
## Make sure, to mount your configured 'app.json' into the container at
## '/home/ethnetintel/eth-net-intelligence-api/app.json', e.g.
## '-v /path/to/app.json:/home/ethnetintel/eth-net-intelligence-api/app.json'
##
## Note: if you actually want to monitor a client, you'll need to make sure it can be reached from this container.
## The best way in my opinion is to start this container with all client '-p' port settings and then
# share its network with the client. This way you can redeploy the client at will and just leave 'ethnetintel' running. E.g. with
## the python client 'pyethapp':
##
#
# `docker run -d --name ethnetintel \
# -v /home/user/app.json:/home/ethnetintel/eth-net-intelligence-api/app.json \
# -p 0.0.0.0:30303:30303 \
# -p 0.0.0.0:30303:30303/udp \
# ethnetintel:latest`
#
# `docker run -d --name pyethapp \
# --net=container:ethnetintel \
# -v /path/to/data:/data \
# pyethapp:latest`
#
## If you now want to deploy a new client version, just redo the second step.


FROM debian

RUN apt-get update &&\
apt-get install -y curl git-core &&\
curl -sL https://deb.nodesource.com/setup | bash - &&\
apt-get update &&\
apt-get install -y nodejs

RUN apt-get update &&\
apt-get install -y build-essential

RUN adduser ethnetintel

RUN cd /home/ethnetintel &&\
git clone https://github.com/cubedro/eth-net-intelligence-api &&\
cd eth-net-intelligence-api &&\
npm install &&\
npm install -g pm2

RUN echo '#!/bin/bash\nset -e\n\ncd /home/ethnetintel/eth-net-intelligence-api\n/usr/bin/pm2 start ./app.json\ntail -f \
/home/ethnetintel/.pm2/logs/node-app-out-0.log' > /home/ethnetintel/startscript.sh

RUN chmod +x /home/ethnetintel/startscript.sh &&\
chown -R ethnetintel. /home/ethnetintel

USER ethnetintel
ENTRYPOINT ["/home/ethnetintel/startscript.sh"]
675 changes: 675 additions & 0 deletions eth-net-intelligence-api/LICENSE

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions eth-net-intelligence-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Ethereum Network Intelligence API
============
[![Build Status][travis-image]][travis-url] [![dependency status][dep-image]][dep-url]

This is the backend service which runs along with ethereum and tracks the network status, fetches information through JSON-RPC and connects through WebSockets to [eth-netstats](https://github.com/cubedro/eth-netstats) to feed information. For full install instructions please read the [wiki](https://github.com/ethereum/wiki/wiki/Network-Status).


## Prerequisite
* eth, geth or pyethapp
* node
* npm


## Installation on an Ubuntu EC2 Instance

Fetch and run the build shell. This will install everything you need: latest ethereum - CLI from develop branch (you can choose between eth or geth), node.js, npm & pm2.

```bash
bash <(curl https://raw.githubusercontent.com/cubedro/eth-net-intelligence-api/master/bin/build.sh)
```
## Installation as docker container (optional)

There is a `Dockerfile` in the root directory of the repository. Please read through the header of said file for
instructions on how to build/run/setup. Configuration instructions below still apply.

## Configuration

Configure the app modifying [processes.json](/eth-net-intelligence-api/blob/master/processes.json). Note that you have to modify the backup processes.json file located in `./bin/processes.json` (to allow you to set your env vars without being rewritten when updating).

```json
"env":
{
"NODE_ENV" : "production", // tell the client we're in production environment
"RPC_HOST" : "localhost", // eth JSON-RPC host
"RPC_PORT" : "8545", // eth JSON-RPC port
"LISTENING_PORT" : "30303", // eth listening port (only used for display)
"INSTANCE_NAME" : "", // whatever you wish to name your node
"CONTACT_DETAILS" : "", // add your contact details here if you wish (email/skype)
"WS_SERVER" : "wss://rpc.ethstats.net", // path to eth-netstats WebSockets api server
"WS_SECRET" : "see http://forum.ethereum.org/discussion/2112/how-to-add-yourself-to-the-stats-dashboard-its-not-automatic", // WebSockets api server secret used for login
"VERBOSITY" : 2 // Set the verbosity (0 = silent, 1 = error, warn, 2 = error, warn, info, success, 3 = all logs)
}
```

## Run

Run it using pm2:

```bash
cd ~/bin
pm2 start processes.json
```

## Updating

To update the API client use the following command:

```bash
~/bin/www/bin/update.sh
```

It will stop the current netstats client processes, automatically detect your ethereum implementation and version, update it to the latest develop build, update netstats client and reload the processes.

[travis-image]: https://travis-ci.org/cubedro/eth-net-intelligence-api.svg
[travis-url]: https://travis-ci.org/cubedro/eth-net-intelligence-api
[dep-image]: https://david-dm.org/cubedro/eth-net-intelligence-api.svg
[dep-url]: https://david-dm.org/cubedro/eth-net-intelligence-api
32 changes: 32 additions & 0 deletions eth-net-intelligence-api/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

var nodeModel = require('./lib/node');

var node = new nodeModel();

var gracefulShutdown = function() {
console.log('');
console.error("xxx", "sys", "Received kill signal, shutting down gracefully.");

node.stop();
console.info("xxx", "sys", "Closed node watcher");

setTimeout(function(){
console.info("xxx", "sys", "Closed out remaining connections.");
process.exit(0);
}, 1000);
}

// listen for TERM signal .e.g. kill
process.on('SIGTERM', gracefulShutdown);

// listen for INT signal e.g. Ctrl-C
process.on('SIGINT', gracefulShutdown);

// listen for shutdown signal from pm2
process.on('message', function(msg) {
if (msg == 'shutdown')
gracefulShutdown();
});

module.exports = node;
24 changes: 24 additions & 0 deletions eth-net-intelligence-api/app.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"name" : "node-app",
"script" : "app.js",
"log_date_format" : "YYYY-MM-DD HH:mm Z",
"merge_logs" : false,
"watch" : false,
"max_restarts" : 10,
"exec_interpreter" : "node",
"exec_mode" : "fork_mode",
"env":
{
"NODE_ENV" : "production",
"RPC_HOST" : "localhost",
"RPC_PORT" : "8545",
"LISTENING_PORT" : "30303",
"INSTANCE_NAME" : "",
"CONTACT_DETAILS" : "",
"WS_SERVER" : "wss://rpc.ethstats.net",
"WS_SECRET" : "see http://forum.ethereum.org/discussion/2112/how-to-add-yourself-to-the-stats-dashboard-its-not-automatic",
"VERBOSITY" : 2
}
}
]
85 changes: 85 additions & 0 deletions eth-net-intelligence-api/bin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

# setup colors
red=`tput setaf 1`
green=`tput setaf 2`
cyan=`tput setaf 6`
bold=`tput bold`
reset=`tput sgr0`

heading()
{
echo
echo "${cyan}==>${reset}${bold} $1${reset}"
}

success()
{
echo
echo "${green}==>${bold} $1${reset}"
}

error()
{
echo
echo "${red}==>${bold} Error: $1${reset}"
}

heading "You're about to install ethereum."
echo "Please choose one of the following:"
echo "1. eth"
echo "2. geth"
while true; do
read -p "Choose the implementation: " imp
case $imp in
[1]* ) ethtype="eth"; break;;
[2]* ) ethtype="geth"; break;;
* ) echo "Please answer 1 or 2.";;
esac
done

heading "Installing" $ethtype

cd ~

[ ! -d "bin" ] && mkdir bin
[ ! -d "logs" ] && mkdir logs

# update packages
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get install -y software-properties-common

# add ethereum repos
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo add-apt-repository -y ppa:ethereum/ethereum-dev
sudo apt-get update -y

# install ethereum & install dependencies
sudo apt-get install -y build-essential git unzip wget nodejs npm ntp cloud-utils $ethtype

# add node symlink if it doesn't exist
[[ ! -f /usr/bin/node ]] && sudo ln -s /usr/bin/nodejs /usr/bin/node

# set up time update cronjob
sudo bash -c "cat > /etc/cron.hourly/ntpdate << EOF
#!/bin/sh
pm2 flush
sudo service ntp stop
sudo ntpdate -s ntp.ubuntu.com
sudo service ntp start
EOF"

sudo chmod 755 /etc/cron.hourly/ntpdate

# add node service
cd ~/bin

[ ! -d "www" ] && git clone https://github.com/cubedro/eth-net-intelligence-api www
cd www
git pull

[[ ! -f ~/bin/processes.json ]] && cp -b ./processes-ec2.json ./../processes.json

sudo npm install
sudo npm install pm2 -g
34 changes: 34 additions & 0 deletions eth-net-intelligence-api/bin/eth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

trap "exit" INT

if [[ -f $(which ec2metadata 2>/dev/null) ]]
then
# If ec2 instance then get ips from ec2metadata
LOCALIP=$(ec2metadata --local-ipv4)
IP=$(ec2metadata --public-ipv4)
else
# Else get IPs from ifconfig and dig
LOCALIP=$(ifconfig | grep 'inet ' | grep -v '127.0.0.1' | head -n1 | awk '{print $2}' | cut -d':' -f2)
IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
fi

echo "Local IP: $LOCALIP"
echo "Public IP: $IP"

if [[ -f $(which geth 2>/dev/null) ]]
then
echo "Starting geth"
echo geth --rpc --bootnodes "enode://09fbeec0d047e9a37e63f60f8618aa9df0e49271f3fadb2c070dc09e2099b95827b63a8b837c6fd01d0802d457dd83e3bd48bd3e6509f8209ed90dabbc30e3d3@52.16.188.185:30303" --nat "extip:$IP"
geth --rpc --bootnodes "enode://09fbeec0d047e9a37e63f60f8618aa9df0e49271f3fadb2c070dc09e2099b95827b63a8b837c6fd01d0802d457dd83e3bd48bd3e6509f8209ed90dabbc30e3d3@52.16.188.185:30303" --nat "extip:$IP"

elif [[ -f $(which eth 2>/dev/null) ]]
then
echo "Starting eth"
echo eth --bootstrap --peers 50 --remote 52.16.188.185:30303 --mining off --json-rpc -v 3 --public-ip $IP --listen-ip $LOCALIP --master $1
eth --bootstrap --peers 50 --remote 52.16.188.185:30303 --mining off --json-rpc -v 3 --public-ip $IP --listen-ip $LOCALIP --master $1

else
echo "Ethereum was not found!"
exit 1;
fi
Loading

0 comments on commit 09fc6d6

Please sign in to comment.