-
Notifications
You must be signed in to change notification settings - Fork 371
/
deploy_tron.sh
179 lines (153 loc) · 4.63 KB
/
deploy_tron.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
# default config
APP="FullNode"
PROJECT="java-tron"
WORK_SPACE=$PWD
NET="mainnet"
BRANCH="master"
DB="keep"
RPC_PORT=50051
TRUST_NODE="127.0.0.1:50051"
# compute default heap size
# total=`cat /proc/meminfo |grep MemTotal |awk -F ' ' '{print $2}'`
# HEAP_SIZE=`echo "$total/1024/1024*0.8" | bc |awk -F. '{print $1"g"}'`
while [ -n "$1" ] ;do
case "$1" in
--net)
NET=$2
shift 2
;;
--app)
APP=$2
shift 2
;;
--db)
DB=$2
shift 2
;;
--work_space)
WORK_SPACE=$2
shift 2
;;
--commitid)
COMMITID=$2
shift 2
;;
--branch)
BRANCH=$2
shift 2
;;
--trust-node)
TRUST_NODE=$2
shift 2
;;
--rpc-port)
RPC_PORT=$2
shift 2
;;
--heap-size)
HEAP_SIZE=$2
shift 2
;;
*)
;;
esac
done
if [ -z $HEAP_SIZE ]; then
if [ "$(uname)" == "Darwin" ]; then
total=`top -l 1 | head -n 10 | grep PhysMem | awk -F " " '{a=substr($2,0,length($2)-1);b=substr($6,0,length($6)-1);if(match($2,/[0-9]+G/)) a=a*1024;if(match($6,/[0-9]+G/)) b=b*1024;print a+b}'`
HEAP_SIZE=`echo "$total/1024*0.8" | bc |awk -F. '{print $1"g"}'`
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
total=`cat /proc/meminfo |grep MemTotal |awk -F ' ' '{print $2}'`
HEAP_SIZE=`echo "$total/1024/1024*0.8" | bc |awk -F. '{print $1"g"}'`
fi
fi
JAR_NAME=$APP
BIN_PATH="$WORK_SPACE/$APP"
CONF_PATH=""
echo 'download code from git repository'
if [ ! -e $BIN_PATH ]; then
mkdir -p $BIN_PATH
cd $BIN_PATH
git clone https://github.com/tronprotocol/$PROJECT
fi
cd $BIN_PATH
if [ $NET == "mainnet" ]; then
wget https://raw.githubusercontent.com/tronprotocol/TronDeployment/master/main_net_config.conf -O main_net_config.conf
RELEASE=`curl --silent "https://api.github.com/repos/tronprotocol/java-tron/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'`
CONF_PATH=$BIN_PATH/main_net_config.conf
elif [ $NET == "testnet" ]; then
wget https://raw.githubusercontent.com/tronprotocol/TronDeployment/master/test_net_config.conf -O test_net_config.conf
CONF_PATH=$BIN_PATH/test_net_config.conf
fi
if [ -n $RPC_PORT ]; then
sed "s/port = 50051/port = $RPC_PORT/g" $CONF_PATH > tmp
cat tmp > $CONF_PATH
fi
# checkout branch or commitid
if [ -n "$BRANCH" ]; then
cd $BIN_PATH/$PROJECT && git fetch && git checkout $BRANCH; git reset --hard origin/$BRANCH
fi
if [ -n "$COMMITID" ]; then
cd $BIN_PATH/$PROJECT && git fetch && git checkout $COMMITID
fi
if [ -n "$RELEASE" ]; then
cd $BIN_PATH/$PROJECT && git fetch && git checkout tags/$RELEASE -b release
BRANCH='release'
fi
if [ $DB == "remove" ]; then
rm -rf $BIN_PATH/output-directory
echo "remove db success"
elif [ $DB == "backup" ]; then
tar -czf $BIN_PATH/output-directory-$GIT_COMMIT-$NET.tar.gz $BIN_PATH/output-directory
rm -rf $BIN_PATH/output-directory
echo "backup db success"
fi
cd $BIN_PATH/$PROJECT && ./gradlew build -x test
cp $BIN_PATH/$PROJECT/build/libs/$JAR_NAME.jar $BIN_PATH
if [ $APP == "SolidityNode" ]; then
START_OPT="--trust-node $TRUST_NODE"
elif [ $APP == "FullNode" ]; then
START_OPT=""
fi
JVM_OPT="-Xmx$HEAP_SIZE -XX:+HeapDumpOnOutOfMemoryError"
count=1
while [ $count -le 360 ]; do
pid=`ps -ef |grep $JAR_NAME.jar | grep java | grep -v grep |awk '{print $2}'`
if [ -n "$pid" ]; then
kill -15 $pid
echo "kill -15 java-tron, counter $count"
sleep 5
else
echo "$APP killed"
break
fi
count=$[$count+1]
if [ $count -ge 360 ]; then
echo "deploy failure because of kill process fails!"
exit 1
fi
done
echo "starting $APP"
cd $BIN_PATH
nohup java $JVM_OPT -jar $JAR_NAME.jar -c $CONF_PATH $START_OPT >> start.log 2>&1 &
pid=`ps ax |grep $JAR_NAME.jar |grep -v grep | awk '{print $1}'`
echo $pid
if [ -z $pid ]; then
echo "run $JAR_NAME failed, please check your parameters"
exit 2
fi
echo "process : nohup java $JVM_OPT -jar $JAR_NAME.jar $START_OPT -c $CONF_PATH >> start.log 2>&1 &"
echo "pid : $pid"
echo "application: $APP"
echo "tron net : $NET"
echo "deploy path: $BIN_PATH"
echo "git commit : "`cd $BIN_PATH/$PROJECT; git rev-parse HEAD`
echo "git branch : $BRANCH"
echo "db path : $BIN_PATH/output-directory"
echo "log path : $BIN_PATH/logs"
echo "heap-size : $HEAP_SIZE"
echo "grpc port : $RPC_PORT"
if [ $APP == "SolidityNode" ]; then
echo "trust-node : $TRUST_NODE"
fi