diff --git a/swarm/cmd/swarm/env.sh b/swarm/cmd/swarm/env.sh new file mode 100644 index 0000000000..634f316fb7 --- /dev/null +++ b/swarm/cmd/swarm/env.sh @@ -0,0 +1,9 @@ +export GOPATH=~/go +export PATH=~/bin:$GOPATH/bin:$PATH + +if [ -f ~/.bash_aliases ]; then + . ~/.bash_aliases +fi + +export NVM_DIR="/home/ubuntu/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm \ No newline at end of file diff --git a/swarm/cmd/swarm/gethup.sh b/swarm/cmd/swarm/gethup.sh index dcf2391d95..8d8925cd62 100644 --- a/swarm/cmd/swarm/gethup.sh +++ b/swarm/cmd/swarm/gethup.sh @@ -17,13 +17,13 @@ shift # ls -l $GETH # geth CLI params e.g., (dd=04, run=09) -datetag=`date "+%c%y%m%d-%H%M%S"|cut -d ' ' -f 5` +datetag=`date "+%Y-%m-%d-%H:%M:%S"` datadir=$root/data/$id # /tmp/eth/04 log=$root/log/$id.$datetag.log # /tmp/eth/04.09.log linklog=$root/log/$id.log # /tmp/eth/04.09.log password=$id # 04 port=303$id # 34504 -bzzport=322$id # 32204 +bzzport=322$id # 3 2204 rpcport=302$id # 3204 mkdir -p $root/data @@ -43,8 +43,8 @@ if [ ! -d "$keystoredir" ]; then # note that the account key will be stored also separately outside # datadir # this way you can safely clear the data directory and still keep your key - # under `/keystore/dd - # LS=`ls $datadir/keystore` + # under /keystore/dd + # LS=$(ls $datadir/keystore) # echo $LS while [ ! -d "$keystoredir" ]; do echo "." @@ -57,13 +57,6 @@ if [ ! -d "$keystoredir" ]; then cp -R "$datadir/keystore/" $root/keystore/$id fi -# # mkdir -p $datadir/keystore -# if [ ! -d "$datadir/keystore" ]; then -# echo "copying keys $root/keystore/$id $datadir/keystore" -# cp -R $root/keystore/$id/keystore/ $datadir/keystore/ -# fi - - # query node's enode url if [ $ip_addr="" ]; then pattern='\d+\.\d+\.\d+\.\d+' diff --git a/swarm/cmd/swarm/swarm b/swarm/cmd/swarm/swarm new file mode 100755 index 0000000000..5289aba5a3 --- /dev/null +++ b/swarm/cmd/swarm/swarm @@ -0,0 +1,2 @@ +#!/bin/bash +bash ~/bin/swarm.sh $SWARM_DIR $SWARM_NETWORK_ID $* \ No newline at end of file diff --git a/swarm/cmd/swarm/swarm.sh b/swarm/cmd/swarm/swarm.sh index 8e3e2bb9c1..4ca75c82a5 100644 --- a/swarm/cmd/swarm/swarm.sh +++ b/swarm/cmd/swarm/swarm.sh @@ -44,8 +44,8 @@ function attach { id=$1 shift echo "attaching console to instance $id" - cmd="$GETH $* attach ipc:$root/$network_id/data/$id/geth.ipc" - # echo $cmd + cmd="$GETH $* attach ipc:$root/$network_id/data/$id/geth.ipc" + echo $cmd eval $cmd } @@ -58,6 +58,30 @@ function log { eval $cmd } +function cleanlog { + id=$1 + shift + if [ $id = "all" ]; then + echo "remove logs for all instances" + rm -rf "$root/$network_id/log/" + else + echo "remove logs for instance $id" + rm -rf $root/$network_id/log/$id* + fi +} + +function cleanbzz { + id=$1 + shift + if [ $id = "all" ]; then + echo "remove bzz data for all instances" + rm -rf $root/$network_id/data/*/bzz + else + echo "remove bzz data for instance $id" + rm -rf "$root/$network_id/data/$id" + fi +} + function less { id=$1 shift @@ -319,6 +343,37 @@ function netstatconf { echo "]" >> $conf } +function remote-update-scripts { + scriptdir=$1 + remotes=$2 + cd $GETH_DIR + for remote in `cat $remotes|grep -v '^#'`; do echo "updating scripts on $remote..."; ssh $remote mkdir -p bin && scp -r $scriptdir/* $remote:bin/; done +} + +function remote-update-bin { + remote-update-scripts ~/bin $remotes + for remote in `cat $remotes|grep -v '^#'`; do echo "updating binary on $remote..."; scp -r $GETH_DIR/geth $remote:bin/; done +} + +function remote-run { + remotes=$1 + shift + for remote in `cat $remotes|grep -v '^#'`; do echo "running on $remote..."; ssh $remote ". ~/bin/env.sh; $*"; done +} + +function update-src { + branch=$1 + echo "cd $GETH_DIR && git remote update && git reset --hard $branch" + (cd $GETH_DIR && git remote update && git reset --hard $branch) +} + +function netstatrun { + cd ~/eth-net-intelligence-api + pm2 kill + pm2 start $root/$network_id/*.netstat.json +} + + case $cmd in "info" ) info $*;; @@ -352,11 +407,25 @@ case $cmd in cluster $*;; "attach" ) attach $*;; + "cleanbzz" ) + cleanbzz $*;; + "cleanlog" ) + cleanlog $*;; "log" ) log $*;; "less" ) less $*;; - "netstatconf" ) + "remote-update-scripts" ) + remote-update-scripts $*;; + "remote-update-bin" ) + remote-update-bin $*;; + "update-src" ) + update-src $*;; + "remote-run" ) + remote-run $*;; + "netstatconf" ) netstatconf $*;; + "netstatrun" ) + netstatrun $*;; esac