forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
work.sh
executable file
·67 lines (55 loc) · 1.74 KB
/
work.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
#!/bin/bash
# Function: to start, stop and restart java-tron.
# Usage: bash work.sh start|stop|restart.
# Note: modify the paths and private key to your own.
# Auther: haoyouqiang
# Since: 2018/5/27
# Version: 1.0
if [ $# -ne 1 ]; then
echo "Usage: bash work.sh start|stop|restart."
exit 1
fi
# Increase memory limit that JVM can use to avoid OOM error:
# 80% of your physical memory may be a proper ceiling that JVM can use.
# By default there, JVM initializes with 1g memory and can use 32g at most.
JVM_OPTIONS="-Xms1g -Xmx32g"
JAR_FILE_PATH="./build/libs/java-tron.jar"
PID_FILE_PATH="java-tron.pid"
LOG_FILE_PATH="java-tron.log"
CONF_FILE_PATH="./build/resources/main/config.conf"
PRIVATE_KEY="650950B193DDDDB35B6E48912DD28F7AB0E7140C1BFDEFD493348F02295BD812"
case "${1}" in
start)
# Already running
if [ -f ${PID_FILE_PATH} ]; then
pid=$(cat ${PID_FILE_PATH})
if $(ps -p ${pid} > /dev/null); then
echo "Already running [PID: ${pid}], you can stop it and retry."
exit 1
fi
fi
nohup java ${JVM_OPTIONS} \
-jar ${JAR_FILE_PATH} \
-p ${PRIVATE_KEY} --witness \
-c ${CONF_FILE_PATH} \
> ${LOG_FILE_PATH} 2>&1 \
& echo $! > ${PID_FILE_PATH}
if [ $? -eq 0 ]; then
echo "Succeeded to start java-tron."
else
echo "Failed to start java-tron."
fi
;;
stop)
kill $(cat ${PID_FILE_PATH})
if [ $? -eq 0 ]; then
rm ${PID_FILE_PATH}
echo "Succeeded to stop java-tron."
else
echo "Failed to stop java-tron."
fi
;;
restart)
${0} stop && sleep 1 && ${0} start
;;
esac