swarm/cmd: add cleanlog, cleanbzz, update-src, remote-update-scripts, remote-update-bin, remote-run

This commit is contained in:
zelig 2016-06-22 15:07:26 +02:00
parent 0e23886184
commit c6205b2244
4 changed files with 87 additions and 14 deletions

9
swarm/cmd/swarm/env.sh Normal file
View file

@ -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

View file

@ -17,13 +17,13 @@ shift
# ls -l $GETH # ls -l $GETH
# geth CLI params e.g., (dd=04, run=09) # 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 datadir=$root/data/$id # /tmp/eth/04
log=$root/log/$id.$datetag.log # /tmp/eth/04.09.log log=$root/log/$id.$datetag.log # /tmp/eth/04.09.log
linklog=$root/log/$id.log # /tmp/eth/04.09.log linklog=$root/log/$id.log # /tmp/eth/04.09.log
password=$id # 04 password=$id # 04
port=303$id # 34504 port=303$id # 34504
bzzport=322$id # 32204 bzzport=322$id # 3 2204
rpcport=302$id # 3204 rpcport=302$id # 3204
mkdir -p $root/data mkdir -p $root/data
@ -43,8 +43,8 @@ if [ ! -d "$keystoredir" ]; then
# note that the account key will be stored also separately outside # note that the account key will be stored also separately outside
# datadir # datadir
# this way you can safely clear the data directory and still keep your key # this way you can safely clear the data directory and still keep your key
# under `<rootdir>/keystore/dd # under <rootdir>/keystore/dd
# LS=`ls $datadir/keystore` # LS=$(ls $datadir/keystore)
# echo $LS # echo $LS
while [ ! -d "$keystoredir" ]; do while [ ! -d "$keystoredir" ]; do
echo "." echo "."
@ -57,13 +57,6 @@ if [ ! -d "$keystoredir" ]; then
cp -R "$datadir/keystore/" $root/keystore/$id cp -R "$datadir/keystore/" $root/keystore/$id
fi 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 # query node's enode url
if [ $ip_addr="" ]; then if [ $ip_addr="" ]; then
pattern='\d+\.\d+\.\d+\.\d+' pattern='\d+\.\d+\.\d+\.\d+'

2
swarm/cmd/swarm/swarm Executable file
View file

@ -0,0 +1,2 @@
#!/bin/bash
bash ~/bin/swarm.sh $SWARM_DIR $SWARM_NETWORK_ID $*

View file

@ -45,7 +45,7 @@ function attach {
shift shift
echo "attaching console to instance $id" echo "attaching console to instance $id"
cmd="$GETH $* attach ipc:$root/$network_id/data/$id/geth.ipc" cmd="$GETH $* attach ipc:$root/$network_id/data/$id/geth.ipc"
# echo $cmd echo $cmd
eval $cmd eval $cmd
} }
@ -58,6 +58,30 @@ function log {
eval $cmd 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 { function less {
id=$1 id=$1
shift shift
@ -319,6 +343,37 @@ function netstatconf {
echo "]" >> $conf 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 case $cmd in
"info" ) "info" )
info $*;; info $*;;
@ -352,11 +407,25 @@ case $cmd in
cluster $*;; cluster $*;;
"attach" ) "attach" )
attach $*;; attach $*;;
"cleanbzz" )
cleanbzz $*;;
"cleanlog" )
cleanlog $*;;
"log" ) "log" )
log $*;; log $*;;
"less" ) "less" )
less $*;; less $*;;
"remote-update-scripts" )
remote-update-scripts $*;;
"remote-update-bin" )
remote-update-bin $*;;
"update-src" )
update-src $*;;
"remote-run" )
remote-run $*;;
"netstatconf" ) "netstatconf" )
netstatconf $*;; netstatconf $*;;
"netstatrun" )
netstatrun $*;;
esac esac