diff --git a/app.json b/app.json new file mode 100644 index 0000000..c0d4e41 --- /dev/null +++ b/app.json @@ -0,0 +1,21 @@ +[ + { + "name" : "node-app", + "cwd" : "/home/ubuntu/bin/www/", + "script" : "app.js", + "log_date_format" : "YYYY-MM-DD HH:mm Z", + "merge_logs" : false, + "watch" : false, + "exec_interpreter" : "node", + "exec_mode" : "fork_mode", + "env": + { + "NODE_ENV" : "production", + "RPC_HOST" : "localhost", + "RPC_PORT" : "8080", + "INSTANCE_NAME" : "", + "WS_SERVER" : "wss://eth-netstats.herokuapp.com", + "WS_SECRET" : "eth-net-stats-has-a-secret", + } + } +] \ No newline at end of file diff --git a/bin/build.sh b/bin/build.sh old mode 100644 new mode 100755 index 1739962..8624f10 --- a/bin/build.sh +++ b/bin/build.sh @@ -1,6 +1,32 @@ -#!/bin/sh +#!/bin/bash -echo "You're about to install ethereum. Please choose one of the following:" +# 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 @@ -12,7 +38,7 @@ while true; do esac done -echo "Installing" $ethtype +heading "Installing" $ethtype cd ~ @@ -52,7 +78,7 @@ cd ~/bin cd www git pull -[[ ! -f ~/bin/processes.json ]] && cp -b ./processes.json ./.. +[[ ! -f ~/bin/processes.json ]] && cp -b ./processes-ec2.json ./../processes.json npm install sudo npm install pm2 -g diff --git a/bin/eth.sh b/bin/eth.sh old mode 100644 new mode 100755 diff --git a/bin/update.sh b/bin/update.sh new file mode 100755 index 0000000..5949cc5 --- /dev/null +++ b/bin/update.sh @@ -0,0 +1,71 @@ +#!/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 "Updating ethereum" + +# figure out what we have to update +if [[ -f /usr/bin/geth ]]; +then + ethtype="geth" + success "Found geth" +else + if [[ -f /usr/bin/geth ]]; + then + ethtype="eth" + success "Found eth" + else + error "Couldn't find ethereum" + exit 0 + fi +fi + +heading "Stopping processes" +pm2 kill + +heading "Removing ethereum" +sudo apt-get remove $eth -y + +heading "Updating repos" +sudo apt-get clean +sudo add-apt-repository -y ppa:ethereum/ethereum +sudo add-apt-repository -y ppa:ethereum/ethereum-dev +sudo apt-get update -y +sudo apt-get upgrade -y + +heading "Installing ethereum" +sudo apt-get install -y $eth + +heading "Updating eth-netstats client" +cd ~/bin/www +git pull +sudo npm update +cd .. + +success "Ethereum was updated successfully" + +heading "Restarting processes" +pm2 start processes.json diff --git a/lib/node.js b/lib/node.js index 1ca91ec..83c676a 100644 --- a/lib/node.js +++ b/lib/node.js @@ -112,7 +112,7 @@ function Node() console.warn('We are scheduling a reconnect operation', opts); }) .on('node-pong', function(data) { - var latency = (new Date()).getTime() - self._latency; + var latency = Math.ceil(((new Date()).getTime() - self._latency)/2); socket.emit('latency', { id: self.id, latency: latency }); }) .on('data', function incoming(data) { @@ -346,7 +346,7 @@ Node.prototype.getStats = function() } this.stats.mining = web3.eth.mining; - this.stats.gasPrice = web3.eth.gasPrice.toString(10); + this.stats.gasPrice = web3.toBigNumber(web3.eth.gasPrice).toString(10); this.stats.listening = web3.net.listening; } diff --git a/processes.json b/processes-ec2.json similarity index 100% rename from processes.json rename to processes-ec2.json