@@ -1 +1 @@ | |||||
Subproject commit c770f544e9892b4cc2e937a336abf59a40fc198a | |||||
Subproject commit d55343ab297329f9476d7fa1494ebb4c9c5fd878 |
@@ -15,45 +15,9 @@ public class GatewayBooter { | |||||
public static void main(String[] args) { | public static void main(String[] args) { | ||||
try { | try { | ||||
writePID(); | |||||
GatewayServerBooter.main(args); | GatewayServerBooter.main(args); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
System.err.println("Error!!! --[" + e.getClass().getName() + "] " + e.getMessage()); | System.err.println("Error!!! --[" + e.getClass().getName() + "] " + e.getMessage()); | ||||
} | } | ||||
} | } | ||||
private static final void writePID() throws Exception { | |||||
URL url = GatewayBooter.class.getProtectionDomain().getCodeSource().getLocation(); | |||||
String currPath = java.net.URLDecoder.decode(url.getPath(), "UTF-8"); | |||||
if (currPath.contains("!/")) { | |||||
currPath = currPath.substring(5, currPath.indexOf("!/")); | |||||
} | |||||
if (currPath.endsWith(".jar")) { | |||||
currPath = currPath.substring(0, currPath.lastIndexOf("/") + 1); | |||||
} | |||||
System.out.printf("currentPath = %s \r\n", currPath); | |||||
File file = new File(currPath); | |||||
String homeDir = file.getParent(); | |||||
String pidFilePath = homeDir + File.separator + "bin" + File.separator + "PID.log"; | |||||
File pidFile = new File(pidFilePath); | |||||
if (!pidFile.exists()) { | |||||
File dir = pidFile.getParentFile(); | |||||
if (!dir.exists()) { | |||||
dir.mkdirs(); | |||||
} | |||||
pidFile.createNewFile(); | |||||
} | |||||
String name = ManagementFactory.getRuntimeMXBean().getName(); | |||||
String pid = name.split("@")[0]; | |||||
List<String> bootInfos = new ArrayList<>(); | |||||
bootInfos.add("JDChain gateway starts to boot ......\r\n"); | |||||
bootInfos.add(String.format("GW_BOOT_TIME = [%s] \r\n", new Date().toString())); | |||||
bootInfos.add(String.format("GW_BOOT_PID = [%s] \r\n", pid)); | |||||
try (FileOutputStream outputStream = new FileOutputStream(pidFile)) { | |||||
for (String bootInfo : bootInfos) { | |||||
outputStream.write(bootInfo.getBytes(StandardCharsets.UTF_8)); | |||||
} | |||||
outputStream.flush(); | |||||
} | |||||
} | |||||
} | } |
@@ -1,32 +1,65 @@ | |||||
#!/bin/bash | #!/bin/bash | ||||
#启动Home路径 | |||||
BOOT_HOME=$(cd `dirname $0`;cd ../; pwd) | |||||
#进程启动后PID.log所在路径 | |||||
PID_LOG=$BOOT_HOME/bin/PID.log | |||||
#从启动文件中读取PID | |||||
if [ -f "$PID_LOG" ]; then | |||||
# File exist | |||||
echo "Read PID From File:[$PID_LOG] ..." | |||||
PID_LINE=`sed -n '$p' $PID_LOG` | |||||
echo "Last Gateway Boot Info = $PID_LINE ..." | |||||
if [[ $PID_LINE == *GW_BOOT_PID* ]]; then | |||||
LOG_PID=$(echo $PID_LINE | cut -d "=" -f 2 | cut -d "[" -f 2 | cut -d "]" -f 1) | |||||
echo "Last Gateway Boot PID = $LOG_PID ..." | |||||
PID=`ps -ef | grep deploy-gateway- | grep $LOG_PID | grep -v grep | awk '{print $2}'` | |||||
#定义程序启动的Jar包前缀 | |||||
APP_JAR_PREFIX=deploy-gateway- | |||||
#获取当前的根目录 | |||||
APP_HOME=$(cd `dirname $0`;cd ../; pwd) | |||||
#System路径 | |||||
APP_LIB_PATH=$APP_HOME/lib | |||||
#获取Peer节点的启动Jar包 | |||||
APP_JAR=$(ls $APP_LIB_PATH | grep $APP_JAR_PREFIX) | |||||
#APP_JAR的具体路径 | |||||
APP_JAR_PATH=$APP_LIB_PATH/$APP_JAR | |||||
################################### | |||||
#(函数)判断程序是否已启动 | |||||
# | |||||
#说明: | |||||
#使用awk,分割出pid ($1部分),及Java程序名称($2部分) | |||||
################################### | |||||
#初始化psid变量(全局) | |||||
psid=0 | |||||
checkpid() { | |||||
psid=`ps -ef | grep $APP_JAR_PATH | grep -v grep | awk '{print $2}'` | |||||
} | |||||
################################### | |||||
#(函数)停止程序 | |||||
# | |||||
#说明: | |||||
#1. 首先调用checkpid函数,刷新$psid全局变量 | |||||
#2. 如果程序已经启动($psid不等于0),则开始执行停止,否则,提示程序未运行 | |||||
#3. 使用kill -9 pid命令进行强制杀死进程 | |||||
#4. 执行kill命令行紧接其后,马上查看上一句命令的返回值: $? | |||||
#5. 如果步骤4的结果$?等于0,则打印[OK],否则打印[Failed] | |||||
#注意:echo -n 表示打印字符后,不换行 | |||||
#注意: 在shell编程中,"$?" 表示上一句命令或者一个函数的返回值 | |||||
################################### | |||||
stop() { | |||||
checkpid | |||||
if [[ $psid -ne 0 ]]; then | |||||
echo "Stopping Gateway ......(pid=$psid) " | |||||
JAVA_CMD="kill -9 $psid" | |||||
sleep 1 | |||||
$JAVA_CMD | |||||
if [[ $? -eq 0 ]]; then | |||||
echo "[OK]" | |||||
else | |||||
echo "[Failed]" | |||||
fi | fi | ||||
#启动文件不存在则直接通过PS进行过滤 | |||||
else | |||||
PID=`ps -ef | grep $BOOT_HOME/lib/deploy-gateway- | grep -v grep | awk '{print $2}'` | |||||
fi | |||||
#通过Kill命令将进程杀死 | |||||
if [ -z "$PID" ]; then | |||||
echo "Unable to find gateway PID. stop aborted." | |||||
else | |||||
echo "Start to kill PID = $PID ..." | |||||
kill -9 $PID | |||||
echo "Gateway has been stopped ..." | |||||
fi | |||||
else | |||||
echo "================================" | |||||
echo "WARN: Gateway is not running" | |||||
echo "================================" | |||||
fi | |||||
} | |||||
#真正停止的处理流程 | |||||
stop |
@@ -1,19 +1,103 @@ | |||||
#!/bin/bash | #!/bin/bash | ||||
HOME=$(cd `dirname $0`;cd ../; pwd) | |||||
GATEWAY=$(ls $HOME/lib | grep deploy-gateway-) | |||||
PROC_INFO=$HOME/lib/$GATEWAY" -c "$HOME/config/gateway.conf | |||||
#echo $PROC_INFO | |||||
#get PID | |||||
PID=`ps -ef | grep "$PROC_INFO" | grep -v grep | awk '{print $2}'` | |||||
#echo $PID | |||||
if [[ ! -z $PID ]] | |||||
then | |||||
echo "process already exists,please check... If necessary, you should kill the process first." | |||||
exit | |||||
#设置Java命令 | |||||
JAVA_BIN=java | |||||
#定义程序启动的Jar包前缀 | |||||
APP_JAR_PREFIX=deploy-gateway- | |||||
#检查Java环境变量 | |||||
if [ ! -n "$JAVA_HOME" ]; then | |||||
echo "UnFound environment variable[JAVA_HOME], will use command[java]..." | |||||
else | |||||
JAVA_BIN=$JAVA_HOME/bin/java | |||||
fi | fi | ||||
if [ ! -n "$GATEWAY" ]; then | |||||
echo "GateWay Is Null !!!" | |||||
#获取当前的根目录 | |||||
APP_HOME=$(cd `dirname $0`;cd ../; pwd) | |||||
#Lib目录 | |||||
APP_LIB_PATH=$APP_HOME/lib | |||||
#节点输出日志路径 | |||||
LOG_OUT=$APP_HOME/bin/gw.out | |||||
#获取Peer节点的启动Jar包 | |||||
APP_JAR=$(ls $APP_LIB_PATH | grep $APP_JAR_PREFIX) | |||||
#Config配置路径 | |||||
CONFIG_PATH=$APP_HOME/config | |||||
#gateway.conf完整路径 | |||||
GATEWAY_CONFIG=$CONFIG_PATH/gateway.conf | |||||
#定义程序启动的参数 | |||||
JAVA_OPTS="-jar -server -Xms1024m -Xmx1024m" | |||||
#APP具体相关命令 | |||||
APP_CMD=$APP_LIB_PATH/$APP_JAR" -c "$GATEWAY_CONFIG | |||||
#APP_JAR的具体路径 | |||||
APP_JAR_PATH=$APP_LIB_PATH/$APP_JAR | |||||
#JAVA_CMD具体命令 | |||||
JAVA_CMD="$JAVA_BIN $JAVA_OPTS $APP_CMD" | |||||
################################### | |||||
#(函数)判断程序是否已启动 | |||||
# | |||||
#说明: | |||||
#使用awk,分割出pid ($1部分),及Java程序名称($2部分) | |||||
################################### | |||||
#初始化psid变量(全局) | |||||
psid=0 | |||||
checkpid() { | |||||
javaps=`ps -ef | grep $APP_JAR_PATH | grep -v grep | awk '{print $2}'` | |||||
if [[ -n "$javaps" ]]; then | |||||
psid=$javaps | |||||
else | |||||
psid=0 | |||||
fi | |||||
} | |||||
################################### | |||||
#(函数)打印系统环境参数 | |||||
################################### | |||||
info() { | |||||
echo "System Information:" | |||||
echo "****************************" | |||||
echo `uname -a` | |||||
echo | |||||
echo `$JAVA_BIN -version` | |||||
echo | |||||
echo "APP_HOME=$APP_HOME" | |||||
echo "APP_JAR=$APP_JAR" | |||||
echo "CONFIG_PATH=$CONFIG_PATH" | |||||
echo "APP_JAR_PATH=$APP_JAR_PATH" | |||||
echo | |||||
echo "JAVA_CMD=$JAVA_CMD" | |||||
echo "****************************" | |||||
} | |||||
#真正启动的处理流程 | |||||
checkpid | |||||
if [[ $psid -ne 0 ]]; then | |||||
echo "================================" | |||||
echo "warn: Gateway already started! (pid=$psid)" | |||||
echo "================================" | |||||
else | else | ||||
nohup java -jar -server -Djdchain.log=$HOME $PROC_INFO $* >$HOME/bin/gw.out 2>&1 & | |||||
echo "Starting Gateway ......" | |||||
nohup $JAVA_BIN $JAVA_OPTS $APP_CMD $* >$LOG_OUT 2>&1 & | |||||
JAVA_CMD="$JAVA_BIN $JAVA_OPTS $APP_CMD $*" | |||||
sleep 1 | |||||
checkpid | |||||
if [[ $psid -ne 0 ]]; then | |||||
echo "(pid=$psid) [OK]" | |||||
info | |||||
else | |||||
echo "[Failed]" | |||||
fi | |||||
fi | fi |
@@ -33,12 +33,8 @@ public class PeerBooter { | |||||
public static void main(String[] args) { | public static void main(String[] args) { | ||||
try { | try { | ||||
HomeContext homeContext = HomeBooter.createHomeContext(args); | HomeContext homeContext = HomeBooter.createHomeContext(args); | ||||
startPeer(homeContext); | startPeer(homeContext); | ||||
writePID(homeContext.getHomeDir()); | |||||
} catch (Exception e) { | } catch (Exception e) { | ||||
System.err.println("Error!!! --[" + e.getClass().getName() + "] " + e.getMessage()); | System.err.println("Error!!! --[" + e.getClass().getName() + "] " + e.getMessage()); | ||||
} | } | ||||
@@ -56,24 +52,4 @@ public class PeerBooter { | |||||
SYSTEM_MAIN_CLASS, home.getSystemClassLoader(), home.getStartingArgs() }; | SYSTEM_MAIN_CLASS, home.getSystemClassLoader(), home.getStartingArgs() }; | ||||
modularFactoryMethod.invoke(null, systemStartingArgs); | modularFactoryMethod.invoke(null, systemStartingArgs); | ||||
} | } | ||||
private static final void writePID(String homeDir) throws IOException { | |||||
String pidFilePath = homeDir + File.separator + "bin" + File.separator + "PID.log"; | |||||
File pidFile = new File(pidFilePath); | |||||
if (!pidFile.exists()) { | |||||
pidFile.createNewFile(); | |||||
} | |||||
String name = ManagementFactory.getRuntimeMXBean().getName(); | |||||
String pid = name.split("@")[0]; | |||||
List<String> bootInfos = new ArrayList<>(); | |||||
bootInfos.add("JDChain peer node starts to boot ......\r\n"); | |||||
bootInfos.add(String.format("PEER_BOOT_TIME = [%s] \r\n", new Date().toString())); | |||||
bootInfos.add(String.format("PEER_BOOT_PID = [%s] \r\n", pid)); | |||||
try (FileOutputStream outputStream = new FileOutputStream(pidFile)) { | |||||
for (String bootInfo : bootInfos) { | |||||
outputStream.write(bootInfo.getBytes(StandardCharsets.UTF_8)); | |||||
} | |||||
outputStream.flush(); | |||||
} | |||||
} | |||||
} | } |
@@ -1,32 +1,65 @@ | |||||
#!/bin/bash | #!/bin/bash | ||||
#启动Home路径 | |||||
BOOT_HOME=$(cd `dirname $0`;cd ../; pwd) | |||||
#进程启动后PID.log所在路径 | |||||
PID_LOG=$BOOT_HOME/bin/PID.log | |||||
#从启动文件中读取PID | |||||
if [ -f "$PID_LOG" ]; then | |||||
# File exist | |||||
echo "Read PID From File:[$PID_LOG] ..." | |||||
PID_LINE=`sed -n '$p' $PID_LOG` | |||||
echo "Last Peer Boot Info = $PID_LINE ..." | |||||
if [[ $PID_LINE == *PEER_BOOT_PID* ]]; then | |||||
LOG_PID=$(echo $PID_LINE | cut -d "=" -f 2 | cut -d "[" -f 2 | cut -d "]" -f 1) | |||||
echo "Last Peer Boot PID = $LOG_PID ..." | |||||
PID=`ps -ef | grep deploy-peer- | grep $LOG_PID | grep -v grep | awk '{print $2}'` | |||||
#定义程序启动的Jar包前缀 | |||||
APP_JAR_PREFIX=deploy-peer- | |||||
#获取当前的根目录 | |||||
APP_HOME=$(cd `dirname $0`;cd ../; pwd) | |||||
#System路径 | |||||
APP_SYSTEM_PATH=$APP_HOME/system | |||||
#获取Peer节点的启动Jar包 | |||||
APP_JAR=$(ls $APP_SYSTEM_PATH | grep $APP_JAR_PREFIX) | |||||
#APP_JAR的具体路径 | |||||
APP_JAR_PATH=$APP_SYSTEM_PATH/$APP_JAR | |||||
################################### | |||||
#(函数)判断程序是否已启动 | |||||
# | |||||
#说明: | |||||
#使用awk,分割出pid ($1部分),及Java程序名称($2部分) | |||||
################################### | |||||
#初始化psid变量(全局) | |||||
psid=0 | |||||
checkpid() { | |||||
psid=`ps -ef | grep $APP_JAR_PATH | grep -v grep | awk '{print $2}'` | |||||
} | |||||
################################### | |||||
#(函数)停止程序 | |||||
# | |||||
#说明: | |||||
#1. 首先调用checkpid函数,刷新$psid全局变量 | |||||
#2. 如果程序已经启动($psid不等于0),则开始执行停止,否则,提示程序未运行 | |||||
#3. 使用kill -9 pid命令进行强制杀死进程 | |||||
#4. 执行kill命令行紧接其后,马上查看上一句命令的返回值: $? | |||||
#5. 如果步骤4的结果$?等于0,则打印[OK],否则打印[Failed] | |||||
#注意:echo -n 表示打印字符后,不换行 | |||||
#注意: 在shell编程中,"$?" 表示上一句命令或者一个函数的返回值 | |||||
################################### | |||||
stop() { | |||||
checkpid | |||||
if [[ $psid -ne 0 ]]; then | |||||
echo "Stopping Peer ......(pid=$psid) " | |||||
JAVA_CMD="kill -9 $psid" | |||||
sleep 1 | |||||
$JAVA_CMD | |||||
if [[ $? -eq 0 ]]; then | |||||
echo "[OK]" | |||||
else | |||||
echo "[Failed]" | |||||
fi | fi | ||||
#启动文件不存在则直接通过PS进行过滤 | |||||
else | |||||
PID=`ps -ef | grep $BOOT_HOME/system/deploy-peer- | grep -v grep | awk '{print $2}'` | |||||
fi | |||||
#通过Kill命令将进程杀死 | |||||
if [ -z "$PID" ]; then | |||||
echo "Unable to find peer PID. stop aborted." | |||||
else | |||||
echo "Start to kill PID = $PID ..." | |||||
kill -9 $PID | |||||
echo "Peer has been stopped ..." | |||||
fi | |||||
else | |||||
echo "================================" | |||||
echo "WARN: Peer is not running" | |||||
echo "================================" | |||||
fi | |||||
} | |||||
#真正停止的处理流程 | |||||
stop |
@@ -1,19 +1,107 @@ | |||||
#!/bin/bash | #!/bin/bash | ||||
HOME=$(cd `dirname $0`;cd ../; pwd) | |||||
PEER=$(ls $HOME/system | grep deploy-peer-) | |||||
PROC_INFO=$HOME/system/$PEER" -home="$HOME" -c "$HOME/config/ledger-binding.conf" -p 7080" | |||||
#echo $PROC_INFO | |||||
#get PID | |||||
PID=`ps -ef | grep "$PROC_INFO" | grep -v grep | awk '{print $2}'` | |||||
#echo $PID | |||||
if [[ ! -z $PID ]] | |||||
then | |||||
echo "process already exists,please check... If necessary, you should kill the process first." | |||||
exit | |||||
#设置Java命令 | |||||
JAVA_BIN=java | |||||
#定义程序启动的Jar包前缀 | |||||
APP_JAR_PREFIX=deploy-peer- | |||||
#Peer节点Web端口 | |||||
#请运维根据实际环境进行调整 | |||||
WEB_PORT=7080 | |||||
#检查Java环境变量 | |||||
if [ ! -n "$JAVA_HOME" ]; then | |||||
echo "UnFound environment variable[JAVA_HOME], will use command[java]..." | |||||
else | |||||
JAVA_BIN=$JAVA_HOME/bin/java | |||||
fi | fi | ||||
if [ ! -n "$PEER" ]; then | |||||
echo "Peer Is Null !!!" | |||||
#获取当前的根目录 | |||||
APP_HOME=$(cd `dirname $0`;cd ../; pwd) | |||||
#System目录 | |||||
APP_SYSTEM_PATH=$APP_HOME/system | |||||
#节点输出日志路径 | |||||
LOG_OUT=$APP_HOME/bin/peer.out | |||||
#获取Peer节点的启动Jar包 | |||||
APP_JAR=$(ls $APP_SYSTEM_PATH | grep $APP_JAR_PREFIX) | |||||
#Config配置路径 | |||||
CONFIG_PATH=$APP_HOME/config | |||||
#ledger-binding.conf完整路径 | |||||
LEDGER_BINDING_CONFIG=$CONFIG_PATH/ledger-binding.conf | |||||
#定义程序启动的参数 | |||||
JAVA_OPTS="-jar -server -Xms2048m -Xmx2048m" | |||||
#APP具体相关命令 | |||||
APP_CMD=$APP_SYSTEM_PATH/$APP_JAR" -home="$APP_HOME" -c "$LEDGER_BINDING_CONFIG" -p "$WEB_PORT | |||||
#APP_JAR的具体路径 | |||||
APP_JAR_PATH=$APP_SYSTEM_PATH/$APP_JAR | |||||
#JAVA_CMD具体命令 | |||||
JAVA_CMD="$JAVA_BIN $JAVA_OPTS $APP_CMD" | |||||
################################### | |||||
#(函数)判断程序是否已启动 | |||||
# | |||||
#说明: | |||||
#使用awk,分割出pid ($1部分),及Java程序名称($2部分) | |||||
################################### | |||||
#初始化psid变量(全局) | |||||
psid=0 | |||||
checkpid() { | |||||
javaps=`ps -ef | grep $APP_JAR_PATH | grep -v grep | awk '{print $2}'` | |||||
if [[ -n "$javaps" ]]; then | |||||
psid=$javaps | |||||
else | |||||
psid=0 | |||||
fi | |||||
} | |||||
################################### | |||||
#(函数)打印系统环境参数 | |||||
################################### | |||||
info() { | |||||
echo "System Information:" | |||||
echo "****************************" | |||||
echo `uname -a` | |||||
echo | |||||
echo `$JAVA_BIN -version` | |||||
echo | |||||
echo "APP_HOME=$APP_HOME" | |||||
echo "APP_JAR=$APP_JAR" | |||||
echo "CONFIG_PATH=$CONFIG_PATH" | |||||
echo "APP_JAR_PATH=$APP_JAR_PATH" | |||||
echo | |||||
echo "JAVA_CMD=$JAVA_CMD" | |||||
echo "****************************" | |||||
} | |||||
#真正启动的处理流程 | |||||
checkpid | |||||
if [[ $psid -ne 0 ]]; then | |||||
echo "================================" | |||||
echo "warn: Peer already started! (pid=$psid)" | |||||
echo "================================" | |||||
else | else | ||||
nohup java -jar -server -Xmx1g -Xms1g -Djdchain.log=$HOME $PROC_INFO $* >$HOME/bin/peer.out 2>&1 & | |||||
echo "Starting Peer ......" | |||||
nohup $JAVA_BIN $JAVA_OPTS $APP_CMD $* >$LOG_OUT 2>&1 & | |||||
JAVA_CMD="$JAVA_BIN $JAVA_OPTS $APP_CMD $*" | |||||
sleep 1 | |||||
checkpid | |||||
if [[ $psid -ne 0 ]]; then | |||||
echo "(pid=$psid) [OK]" | |||||
info | |||||
else | |||||
echo "[Failed]" | |||||
fi | |||||
fi | fi |
@@ -1 +1 @@ | |||||
Subproject commit 2f8f48435e65d4f6598b1ede9c6a7021b10d2a53 | |||||
Subproject commit 3ffc3324c9fe20307cc36c07c361daa1f5d3f11e |
@@ -1 +1 @@ | |||||
Subproject commit f2660860f71850b4e70ae529fbdb8320623bcaff | |||||
Subproject commit 722663f988affc77cc5aec502da455afb3f7eec5 |