-
-
Save kobigurk/a12dbb580507bbd4382d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !/bin/bash | |
# bash cluster <cluster_root> <number_of_clusters> <network_id> <runid> <local_IP> [[params]...] | |
# sets up a local ethereum network cluster of nodes | |
# - <cluster_root> is the root directory for the cluster, the nodes are set up | |
# - <number_of_clusters> is the number of clusters | |
# with datadir `<root>/01`, `<root>/02`, ... | |
# - new accounts are created for each node | |
# - they launch on port 30301, 30302, ... | |
# - they start rpc on port 8101, 8102, ... | |
# - by collecting the nodes nodeUrl, they get connected to each other | |
# - if enode has no IP, `<local_IP>` is substituted | |
# - if `<network_id>` is not 0, they will not connect to a default client, | |
# resulting in a private isolated network | |
# - the nodes log into `<root>/00.<runid>.log`, `<root>/01.<runid>.log`, ... | |
# - `<runid>` is just an arbitrary tag or index you can use to log multiple | |
# subsequent launches of the same cluster | |
# - The nodes launch in mining mode | |
# - the cluster can be killed with `killall geth` (FIXME: should record PIDs) | |
# and restarted from the same state | |
# - if you want to interact with the nodes, use rpc | |
# - you can supply additional params on the command line which will be passed | |
# to each node | |
root=$1 | |
mkdir -p $1 | |
shift | |
N=$1 | |
shift | |
network_id=$1 | |
shift | |
run_id=$1 | |
shift | |
local_ip=$1 | |
shift | |
if [ ! -f "$root/nodes" ]; then | |
for ((i=1;i<=N;++i)); do | |
id=`printf "%02d" $i` | |
echo "getting enode for instance $id ($i/$N)" | |
eth="geth -datadir $root/$id -logfile /dev/null -port 303$id -networkid $network_id" | |
cmd="$eth js <(echo 'console.log(admin.nodeInfo().NodeUrl)') " | |
echo $cmd | |
bash -c "$cmd" >> $root/nodes | |
echo "setting coinbase for instance $i:" | |
cmd="$eth -password <(echo $id) account new" | |
echo $cmd | |
bash -c "$cmd" | |
done | |
fi | |
bootnodes=`cat $root/nodes|tr '\n' ' '|perl -pe "s/\[\:\:\]/$local_ip/g"` | |
echo $bootnodes | tr ' ' '\n' | nl | |
for ((i=1;i<=N;++i)); do | |
id=`printf "%02d" $i` | |
eth="geth -unlock primary -password <(echo $id) -networkid $network_id -datadir $root/$id -logfile $root/$id.$run_id.log -loglevel 5 -mine -port 303$id -rpc -rpcport 81$id --bootnodes=\"$bootnodes\"" | |
cmd="$eth" | |
echo "launching miner $i/$N ---> tail -f $root/$id.$run_id.log" | |
echo $cmd $* | |
bash -c "$cmd $* &" | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !/bin/bash | |
# bash intelligence <destination_app_json_path> <number_of_clusters> <name_prefix> <ws_server> <ws_secret> | |
# sets up a eth-net-intelligence app.json for a local ethereum network cluster of nodes | |
# - <destination_app_json_path> is the target directory for the resulting app.json | |
# - <number_of_clusters> is the number of clusters | |
# - <name_prefix> is a prefix for the node names as will appear in the listing | |
# - <ws_server> is the eth-netstats server | |
# - <ws_secret> is the eth-netstats secret | |
dest=$1 | |
shift | |
N=$1 | |
shift | |
name_prefix=$1 | |
shift | |
ws_server=$1 | |
shift | |
ws_secret=$1 | |
shift | |
app_json_path=$dest/app.json | |
echo -e "[" > $app_json_path | |
for ((i=1;i<=N;++i)); do | |
id=`printf "%02d" $i` | |
single_template=" {\n \"name\" : \"eth-intelligence-$i\",\n \"cwd\" : \".\",\n \"script\" : \"app.js\",\n \"log_date_format\" : \"YYYY-MM-DD HH:mm Z\",\n \"merge_logs\" : false,\n \"watch\" : false,\n \"exec_interpreter\" : \"node\",\n \"exec_mode\" : \"fork_mode\",\n \"env\":\n {\n \"NODE_ENV\" : \"production\",\n \"RPC_HOST\" : \"localhost\",\n \"RPC_PORT\" : \"81$id\",\n \"INSTANCE_NAME\" : \"$name_prefix-$i\",\n \"WS_SERVER\" : \"$ws_server\",\n \"WS_SECRET\" : \"$ws_secret\",\n }\n }" | |
endline="" | |
if [ "$i" -ne "$N" ]; then | |
endline="," | |
fi | |
echo -e "$single_template$endline" >> $app_json_path | |
done | |
echo "]" >> $app_json_path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment