diff --git a/.gitignore b/.gitignore index 8c1f6c6..219007b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,6 @@ /manager.key /WebContent/ /runnable -cmconfig.json* +/cmconfig.json* /build/ */build/* \ No newline at end of file diff --git a/WebContent/.keep b/WebContent/.keep new file mode 100644 index 0000000..e69de29 diff --git a/build.gradle b/build.gradle index e53d4ae..e4b400b 100644 --- a/build.gradle +++ b/build.gradle @@ -36,9 +36,11 @@ dependencies { implementation 'io.prometheus:simpleclient_httpserver:0.12.0' testImplementation 'junit:junit:4.13.2' } + compileJava { - options.compilerArgs<<"-Xlint:unchecked" + options.compilerArgs << "-Xlint:unchecked" } + jar { String libs = '' configurations.runtimeClasspath.each { @@ -54,8 +56,18 @@ jar { tasks.processResources.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE) +task prepareWebContent(type: Exec) { + if (System.properties['os.name'].toString().toLowerCase().contains('windows')) { + commandLine "rmdir", ".\\WebContent\\ide" + commandLine "mklink", "/j", "..\\..\\agent-frontend", ".\\WebContent\\ide" + } else { + commandLine "rm", "./WebContent/ide" + commandLine "ln", "-s", "../../agent-frontend", "./WebContent/ide" + } +} + task copyScript(type: Copy) { - from("../script/") { + from("./script/") { include 'cmstart.sh' include 'cmstop.sh' include 'cmconfig.json.template' @@ -142,7 +154,7 @@ task copyKeys(type: Copy) { into "./build/output/keys" } -task buildBDServerZip(type: Zip, dependsOn: [ ":agent-backend:copyWebContent", +task buildBDServerZip(type: Zip, dependsOn: [":agent-backend:copyWebContent", ":agent-backend:copyBDWareProjectDir", ":agent-backend:copyScript", ":agent-backend:copyJar", ":agent-backend:copyLibs", ":agent-backend:copyKeys"]) { from './build/output/' @@ -151,7 +163,7 @@ task buildBDServerZip(type: Zip, dependsOn: [ ":agent-backend:copyWebContent", destinationDirectory = file('build/') } -task buildBDServerZipLite(type: Zip, dependsOn: [ ":agent-backend:copyWebContent", +task buildBDServerZipLite(type: Zip, dependsOn: [":agent-backend:copyWebContent", ":agent-backend:copyBDWareProjectDir", ":agent-backend:copyScript", ":agent-backend:copyJar", ":agent-backend:copyLibs", ":agent-backend:copyKeys"]) { from('./build/output/') { diff --git a/script/cmconfig.json.template b/script/cmconfig.json.template new file mode 100644 index 0000000..b9f06e1 --- /dev/null +++ b/script/cmconfig.json.template @@ -0,0 +1,15 @@ +{ + "ip": "127.0.0.1", + "servicePort": 21030, + "isLAN" : true, + "disableDoRepo": false, + "doipPort": 21032, + "doipCertPath": "", + "doipUserHandle": "", + "doipLhsAddress": "", + "withBdledgerServer": false, + "withBdledgerClient": "", + "enableEventPersistence": false, + "enableSsl": "./ssl/chained.pem:./ssl/domain.pem", + "textFileSuffixes": ".yjs,.json,.txt,.css,.js,.html,.md,.conf,.csv" +} \ No newline at end of file diff --git a/script/cmstart.sh b/script/cmstart.sh new file mode 100755 index 0000000..1ceda2a --- /dev/null +++ b/script/cmstart.sh @@ -0,0 +1,26 @@ +#!/bin/bash +if [ ! -d "log/" ]; then + mkdir "log" +fi + +bash ./cmstop.sh + +time=$(date "+%Y_%m_%d_%H:%M:%S") + +if [ -f "./log/cm.log" ]; then + echo "move log ./log/cm_${time}.log" + mv ./log/cm.log "./log/cm_${time}.log" +fi + +if [ -f "./log/cm.err" ]; then + mv ./log/cm.err "./log/cm_${time}.err" +fi + +# ps -ef | grep java | grep bdserver | grep CM | awk '{print $2}' | xargs kill -9 + +java -Dfile.encoding=UTF-8 -Djava.library.path="./dynamicLibrary" -cp "./libs/*:bdagent.jar" org.bdware.server.CMHttpServer 1>./log/cm.log 2>./log/cm.err & +#-Xmx3550m -Xms3550m -Xmn2g +#-XX:+UseConcMarkSweepGC -XX:CMSFullGCsBeforeCompaction=5 +# 以下可启用https/wss,其中,./ssl/xxx.pfx为ssl证书的路径,:后面的123456是密码。 +# java -Dfile.encoding=UTF-8 -cp "./libs/*:bdagent.jar" org.bdware.server.CMHttpServer -service-port=8080 -enable-ssl=./ssl/xxx.pfx:123456 -do-repo-ip=127.0.0.1 -do-repo-port=18099 1 > ./log/cm.log 2> ./log/cm.err & +echo $! >./PID diff --git a/script/cmstop.sh b/script/cmstop.sh new file mode 100755 index 0000000..bf0b5e5 --- /dev/null +++ b/script/cmstop.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +if [ -a "./PID" ]; then + ls /proc/$(cat PID)/cmdline + if [ $? -eq 0 ]; then + kill -9 $(cat PID) + echo "shutdown old contract manager" + fi + rm ./PID +fi diff --git a/script/killContracts.sh b/script/killContracts.sh new file mode 100644 index 0000000..5e9a112 --- /dev/null +++ b/script/killContracts.sh @@ -0,0 +1,9 @@ +#!/bin/bash +if [ -a './CMI' ]; then + ps -ef | grep java | grep yjs | grep $(cat CMI) | awk '{print $2}' | xargs kill -9 +fi + +if [ $# -gt 0 ]; then + echo $1 + ps -ef | grep java | grep yjs | grep $1 | awk '{print $2}' | xargs kill -9 +fi diff --git a/src/main/java/org/bdware/server/http/CMHttpHandler.java b/src/main/java/org/bdware/server/http/CMHttpHandler.java index 6450fe6..e39af50 100644 --- a/src/main/java/org/bdware/server/http/CMHttpHandler.java +++ b/src/main/java/org/bdware/server/http/CMHttpHandler.java @@ -73,7 +73,8 @@ public class CMHttpHandler extends SimpleChannelInboundHandler { new HttpFileAction(), new BDIndexerAction(), LedgerActions.instance, - new CMLogAction(), new TemporyTestAction()) { + new CMLogAction(), + new TemporyTestAction()) { @Override public boolean checkPermission(Action a, JsonObject arg, long per) { boolean flag = a.httpAccess(); @@ -103,16 +104,12 @@ public class CMHttpHandler extends SimpleChannelInboundHandler { } TimeDBUtil.instance.put( CMTables.LocalNodeLogDB.toString(), - "{\"action\":\"" - + action - + "\",\"pubKey\":\"" - + pubkey - + "\",\"status\":\"" - + status - + "\",\"date\":" - + System.currentTimeMillis() - + "}"); - + String.format( + "{\"action\":\"%s\",\"pubKey\":\"%s\",\"status\":\"%s\",\"date\":%d}", + action, + pubkey, + status, + System.currentTimeMillis())); return flag && flag2; } };