-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan
executable file
·133 lines (120 loc) · 3.8 KB
/
scan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
ETH_DIR=$(realpath $(dirname $0))
function beacon_scan_start() {
docker stop beacon-scan
docker rm beacon-scan
docker run -d --name beacon-scan -v $ETH_DIR/config:/app/config gobitfly/eth2-beaconchain-explorer:latest ./explorer --config /app/config/default.config.yml
docker logs -f beacon-scan
}
function build_it() {
get_light_chain
make_it
}
function get_light_chain(){
cd $ETH_DIR
rm -rf light-beaconchain-explorer
git clone https://github.com/dapplion/light-beaconchain-explorer
}
function make_it(){
cd $ETH_DIR/light-beaconchain-explorer
make linux
}
function start_it(){
cd $ETH_DIR/light-beaconchain-explorer
stop_it
sleep 5
cp ../gluon.chain.yml config/
echo start and save pid
export LOGGING_OUTPUT_LEVEL=debug
export FRONTEND_SERVER_PORT=8888
export FRONTEND_SERVER_HOST='0.0.0.0'
export CHAIN_NAME=gluon
export CHAIN_DISPLAY_NAME=Gluon
export CHAIN_GENESIS_TIMESTAMP=$(cat ../current.genesis.json | jq -r .config.shanghaiTime)
export CHAIN_CONFIG_PATH="./config/gluon.chain.yml"
export BEACONAPI_ENDPOINT="http://127.0.0.1:3500"
export DATABASE_ENGINE=sqlite
export DATABASE_SQLITE_FILE="./explorer-db.sqlite"
echo "CHAIN_GENESIS_TIMESTAMP=$CHAIN_GENESIS_TIMESTAMP"
nohup ./bin/explorer_linux_amd64 -config config/default.config.yml > beacon_scan.log 2>&1 &
echo $! > beacon_scan.pid
}
function stop_it(){
cd $ETH_DIR/light-beaconchain-explorer
echo stop
# if pid file exists, kill the process
if [[ -f beacon_scan.pid ]]; then
kill `cat beacon_scan.pid`
rm beacon_scan.pid
fi
rm -f explorer-db.sqlite*
rm -f beacon_scan.log
}
function docker_build_it() {
cd $ETH_DIR
# get_light_chain
cd $ETH_DIR/light-beaconchain-explorer
local KEY=SLOTS_PER_EPOCH
local FILE=../gluon.chain.yml
# read SLOTS_PER_EPOCH from config.yml and update gluon.chain.yml
local VALUE=$(grep $KEY ../config.yml | awk '{print $2}')
sed -i -e "s/.*$KEY.*/$KEY: $VALUE/" ${FILE}
local EXISTS=$(grep ${KEY} ${FILE})
echo EXISTS=$EXISTS
if [[ -z "$EXISTS" ]]; then
echo "adding ${KEY}: ${VALUE} to ${FILE}"
echo ${KEY}: ${VALUE} >>${FILE}
fi
cp ../gluon.chain.yml config/
docker build -t beacon-scan .
}
function docker_start_it(){
docker_stop_it
cd $ETH_DIR
local CHAIN_GENESIS_TIMESTAMP=$(cat current.genesis.json | jq -r .config.shanghaiTime)
local DOCKER_ENV="-e LOGGING_OUTPUT_LEVEL=debug"
DOCKER_ENV="$DOCKER_ENV -e FRONTEND_SERVER_PORT=8888"
DOCKER_ENV="$DOCKER_ENV -e FRONTEND_SERVER_HOST=0.0.0.0"
DOCKER_ENV="$DOCKER_ENV -e CHAIN_NAME=gluon"
DOCKER_ENV="$DOCKER_ENV -e CHAIN_DISPLAY_NAME=Gluon"
DOCKER_ENV="$DOCKER_ENV -e CHAIN_GENESIS_TIMESTAMP=$CHAIN_GENESIS_TIMESTAMP"
DOCKER_ENV="$DOCKER_ENV -e CHAIN_CONFIG_PATH=/app/config/gluon.chain.yml "
DOCKER_ENV="$DOCKER_ENV -e BEACONAPI_ENDPOINT=http://172.17.0.1:3500"
DOCKER_ENV="$DOCKER_ENV -e DATABASE_ENGINE=sqlite"
DOCKER_ENV="$DOCKER_ENV -e DATABASE_SQLITE_FILE=/app/beacon-data/explorer-db.sqlite"
docker run -d --name beacon-scan $DOCKER_ENV -p 8888:8888 -v $ETH_DIR/beacon-data:/app/beacon-data beacon-scan
}
function docker_stop_it(){
docker stop beacon-scan
docker rm beacon-scan
}
function clean_it(){
stop_it
rm -rf $ETH_DIR/beacon-data
}
function docker_it() {
echo "docker_it $1"
local OPERATION=$1
shift
case $OPERATION in
build) docker_build_it ;;
start) docker_start_it;;
stop) docker_stop_it;;
clean) clean_it;;
*) usage;;
esac
}
function usage() {
echo "$0 {build|start|stop|docker}"
echo "$0 docker {build|start|stop}"
exit 1
}
OPERATION=$1
shift
case $OPERATION in
build) build_it ;;
start) start_it;;
stop) stop_it;;
docker) docker_it $@;;
*) usage;;
esac