-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_eos.sh
123 lines (105 loc) · 3.05 KB
/
run_eos.sh
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
#!/bin/sh
source $(dirname "$0")/prompt_input_yN/prompt_input_yN.sh
eosiocheck()
{
if [ "${EOSIO_ROOT}" = "" ] \
|| [ "${EOSIO_CROOT}" = "" ] \
|| [ "${EOSIO_URL}" = "" ]; then
printf "error: an environment variable is null, check your eosioconf\n"
return 1
fi
if [ ! -f "${cleos}" ] \
|| [ ! -f "${nodeos}" ]; then
printf "error: a binary was not found in ${EOSIO_ROOT}, check your eosioconf\n"
return 1
fi
}
eosioconf()
{
if [ $# -lt 3 ]; then
printf "usage: eosioconf eosio_root chain_root api_url\n"
printf "e.g. eosioconf /usr/local ~/eos_localnet http://127.0.0.1:8888\n\n"
printf "eosio_root: ${EOSIO_ROOT}\n"
printf "chain_root: ${EOSIO_CROOT}\n"
printf "api_url: ${EOSIO_URL}\n"
return 1
fi
export EOSIO_ROOT=$1 ; shift
export EOSIO_CROOT=$1 ; shift
export EOSIO_URL=$1 ; shift
export cleos=$(find ${EOSIO_ROOT} -type f -iname cleos)
export eosiocpp=$(find ${EOSIO_ROOT} -type f -iname eosio-cpp)
export eosioabi=$(find ${EOSIO_ROOT} -type f -iname eosio-abigen)
export nodeos=$(find ${EOSIO_ROOT} -type f -iname nodeos)
}
eosiocpp()
{
eosiocheck || return 1
${eosiocpp} $@
}
eosioabi()
{
eosiocheck || return 1
${eosioabi} $@
}
cleos()
{
eosiocheck || return 1
${cleos} \
--url ${EOSIO_URL} \
$@
}
nodeos()
{
eosiocheck || return 1
mkdir -p ${EOSIO_CROOT}/{config,data,log}
if [ -f "${EOSIO_CROOT}/data/pid" ]; then
PID=$(cat ${EOSIO_CROOT}/data/pid)
if [ -d "/proc/${PID}" ]; then
ps ef ${PID}
printf '\n'
if prompt_input_yN "nodeos seems to be running, kill it?"; then
nodeos_kill ${PID}
else
tail -f ${EOSIO_CROOT}/log/lastlog
return 1
fi
else
rm -f ${EOSIO_CROOT}/data/pid
fi
fi
if [ -d ${EOSIO_CROOT}/data/blocks ]; then
prompt_input_yN "clean blocks" && rm -rf ${EOSIO_CROOT}/data/blocks
fi
if prompt_input_yN "replay"; then
REPLAY=--replay
prompt_input_yN "hard-replay" && HREPLAY=--hard-replay || HREPLAY=
else
REPLAY=
HREPLAY=
fi
[ -f ${EOSIO_CROOT}/data/blocks/blocks.log ] && GENESIS= || GENESIS=--genesis-json="${EOSIO_CROOT}/config/genesis.json"
DATE=$(date +'%Y_%m_%d_%H_%M_%S')
nohup ${nodeos} \
--data-dir="${EOSIO_CROOT}/data" \
--config="${EOSIO_CROOT}/config/config.ini" \
${GENESIS} \
${REPLAY} \
${HREPLAY} \
$@ \
< /dev/null \
2>&1 \
> ${EOSIO_CROOT}/log/${DATE}.log \
&
[ -L ${EOSIO_CROOT}/log/lastlog ] && unlink ${EOSIO_CROOT}/log/lastlog
ln -s ${EOSIO_CROOT}/log/${DATE}.log ${EOSIO_CROOT}/log/lastlog
printf "$!" > ${EOSIO_CROOT}/data/pid
chmod -w ${EOSIO_CROOT}/data/pid
tail -f ${EOSIO_CROOT}/log/lastlog
}
nodeos_kill()
{
PID=${1} ; shift
kill -0 ${PID} && kill -2 ${PID} && rm -f ${EOSIO_CROOT}/data/pid
wait ${PID}
}