diff --git a/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/RunnerApplication.java b/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/RunnerApplication.java index d4f0087..a80d553 100644 --- a/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/RunnerApplication.java +++ b/service-cli/service-cli-runner/src/main/java/com/lanyuanxiaoyao/service/cli/runner/RunnerApplication.java @@ -193,9 +193,14 @@ public class RunnerApplication implements ApplicationRunner { Files.write(logScriptFile, logScript.getBytes()); } - ClassPathResource stopFile = new ClassPathResource("script/stop.sh"); - String stopScript = new String(IoUtil.readBytes(stopFile.getInputStream())); - Files.write(Paths.get(root.toString(), "stop.sh"), stopScript.getBytes()); + Template stopTemplate = engine.getTemplate("cloud/stop-script.ftl"); + String stopScript = stopTemplate.render(MapUtil.builder() + .put("currentPath", absolutRootPath) + .put("runtime", runtimeInfo) + .build()); + Path stopScriptFile = Paths.get(root.toString(), "stop.sh"); + Files.deleteIfExists(stopScriptFile); + Files.write(stopScriptFile, stopScript.getBytes()); MutableMap> groups = Maps.mutable.empty(); for (ServiceInfoWrapper service : serviceInfoList) { @@ -278,6 +283,7 @@ public class RunnerApplication implements ApplicationRunner { } private void generateUploader(Path root) throws IOException { + Files.createDirectories(root); String absolutRootPath = root.toAbsolutePath().toString(); logger.info("Current path: {}", absolutRootPath); @@ -300,10 +306,13 @@ public class RunnerApplication implements ApplicationRunner { Files.deleteIfExists(updateScriptFile); Files.write(updateScriptFile, updateScript.getBytes()); - ClassPathResource stopFile = new ClassPathResource("script/stop.sh"); - String stopScript = new String(IoUtil.readBytes(stopFile.getInputStream())); + Template stopTemplate = engine.getTemplate("cloud/stop-script.ftl"); + String stopScript = stopTemplate.render(MapUtil.builder() + .put("currentPath", absolutRootPath) + .put("runtime", runtimeInfo) + .build()); // 一个魔法操作 - stopScript = stopScript.replaceAll("\\$1", "service-uploader.jar"); + stopScript = stopScript.replaceAll("application_name=\".*\"", "application_name=\"service-uploader.jar\""); Files.write(Paths.get(root.toString(), "stop.sh"), stopScript.getBytes()); } diff --git a/service-cli/service-cli-runner/src/main/resources/application-b12.yml b/service-cli/service-cli-runner/src/main/resources/application-b12.yml index a57ae88..82c2389 100644 --- a/service-cli/service-cli-runner/src/main/resources/application-b12.yml +++ b/service-cli/service-cli-runner/src/main/resources/application-b12.yml @@ -6,8 +6,8 @@ deploy: user: datalake # 应用jar包 jar-path: /data/datalake/jars - # 主机jdk - jdk-path: /opt/jdk8u252-b09/bin/java + # 主机jdk根目录 + jdk-path: /opt/jdk8u252-b09 # 应用日志 log-path: /data/datalake/logs # 应用配置 diff --git a/service-cli/service-cli-runner/src/main/resources/application-b5.yml b/service-cli/service-cli-runner/src/main/resources/application-b5.yml index 134018b..eb5756d 100644 --- a/service-cli/service-cli-runner/src/main/resources/application-b5.yml +++ b/service-cli/service-cli-runner/src/main/resources/application-b5.yml @@ -3,7 +3,7 @@ deploy: signature: b5 user: datalake jar-path: /apps/datalake/hudi/jars - jdk-path: /opt/jdk1.8.0_162/bin/java + jdk-path: /opt/jdk1.8.0_162 log-path: /apps/datalake/hudi/logs conf-path: /apps/datalake/hudi/conf data-path: /apps/datalake/hudi/data diff --git a/service-cli/service-cli-runner/src/main/resources/template/cloud/deploy.ftl b/service-cli/service-cli-runner/src/main/resources/template/cloud/deploy.ftl index 4047886..96a9a7f 100644 --- a/service-cli/service-cli-runner/src/main/resources/template/cloud/deploy.ftl +++ b/service-cli/service-cli-runner/src/main/resources/template/cloud/deploy.ftl @@ -13,7 +13,7 @@ hostname_full=`ssh $host 'hostname -f'` <#-- 获取当前时间 --> start_time=`date +%Y%m%d%H%M%S` ssh $host "mkdir -p ${runtime.jarPath};curl ${runtime.downloadUrl}/${info.sourceJar} -o ${runtime.jarPath}/${info.name}.jar" -ssh $host "export JASYPT_ENCRYPTOR_PASSWORD='r#(R,P\"Dp^A47>WSn:Wn].gs/+\"v:q_Q*An~zF*g-@j@jtSTv5H/,S-3:R?r9R}.';nohup ${runtime.jdkPath} <#list environments?keys as key>-D${key}=${environments[key]?string} -jar ${runtime.jarPath}/${info.name}.jar <#noparse>--deploy.datetime=${datetime} --deploy.ip=${host} --deploy.hostname=${hostname} --deploy.hostname-full=${hostname_full} --deploy.start-time=${start_time} --hudi-service.signature=${runtime.signature} --logging.parent=${runtime.logPath} --loki.url=${runtime.loki.servicePushUrl} --spring.cloud.zookeeper.connect-string=${runtime.zkUrl} --spring.security.meta.authority='${runtime.security.authority}' --spring.security.meta.username='${runtime.security.username}' --spring.security.meta.darkcode='${runtime.security.darkcode}' --yarn-cluster.sync-clusters=${runtime.yarn.syncClusters} --yarn-cluster.compaction-clusters=${runtime.yarn.compactionClusters} <#list arguments?keys as key>--${key}=${arguments[key]?string} > /dev/null 2>&1 &" +ssh $host "export JASYPT_ENCRYPTOR_PASSWORD='r#(R,P\"Dp^A47>WSn:Wn].gs/+\"v:q_Q*An~zF*g-@j@jtSTv5H/,S-3:R?r9R}.';nohup ${runtime.jdkPath}/bin/java <#list environments?keys as key>-D${key}=${environments[key]?string} -jar ${runtime.jarPath}/${info.name}.jar <#noparse>--deploy.datetime=${datetime} --deploy.ip=${host} --deploy.hostname=${hostname} --deploy.hostname-full=${hostname_full} --deploy.start-time=${start_time} --hudi-service.signature=${runtime.signature} --logging.parent=${runtime.logPath} --loki.url=${runtime.loki.servicePushUrl} --spring.cloud.zookeeper.connect-string=${runtime.zkUrl} --spring.security.meta.authority='${runtime.security.authority}' --spring.security.meta.username='${runtime.security.username}' --spring.security.meta.darkcode='${runtime.security.darkcode}' --yarn-cluster.sync-clusters=${runtime.yarn.syncClusters} --yarn-cluster.compaction-clusters=${runtime.yarn.compactionClusters} <#list arguments?keys as key>--${key}=${arguments[key]?string} > /dev/null 2>&1 &" echo '' diff --git a/service-cli/service-cli-runner/src/main/resources/script/stop.sh b/service-cli/service-cli-runner/src/main/resources/template/cloud/stop-script.ftl similarity index 51% rename from service-cli/service-cli-runner/src/main/resources/script/stop.sh rename to service-cli/service-cli-runner/src/main/resources/template/cloud/stop-script.ftl index b11ec64..8381b03 100644 --- a/service-cli/service-cli-runner/src/main/resources/script/stop.sh +++ b/service-cli/service-cli-runner/src/main/resources/template/cloud/stop-script.ftl @@ -4,14 +4,14 @@ original_command="$0" application_name="$1" function get_pid() { - ID=$(ps -ef | grep "$application_name" | grep -v grep | grep -v $original_command | awk '{ print $2 }') + ID=$(ps ef | grep "$application_name" | grep -v grep | grep -v $original_command | awk '{ print $2 }') if [[ -z "$ID" ]]; then - ID=$(ps -C java -f --width 1000 | grep "$application_name" | grep -v grep | grep -v $original_command | awk '{print $2}') + ID=$(ps aux | grep "$application_name" | grep -v grep | grep -v $original_command | awk '{print $2}') if [[ -z "$ID" ]]; then - ID=$(ps aux | grep "$application_name" | grep -v grep | grep -v $original_command | awk '{print $2}') + ID=$(${runtime.jdkPath}/bin/jps -lmvV | grep "$application_name" | awk '{print $1}') fi fi - echo ${ID} + echo $ID } pid=$(get_pid) @@ -22,7 +22,7 @@ if [[ -z "$pid" ]]; then fi echo "Stopping $pid..." -kill ${pid} +kill $pid LOOPS=0 while (true); do @@ -33,8 +33,8 @@ while (true); do fi LOOPS=$(($LOOPS+1)) if [[ $(($LOOPS%15)) -eq 0 ]]; then - echo "Wait timeout, try to force kill ${pid}..." - kill -9 ${pid} + echo "Wait timeout, try to force kill $pid..." + kill -9 $pid fi sleep 1s done \ No newline at end of file diff --git a/service-cli/service-cli-runner/src/main/resources/template/command/cli.ftl b/service-cli/service-cli-runner/src/main/resources/template/command/cli.ftl index 7b63fe7..c64576e 100644 --- a/service-cli/service-cli-runner/src/main/resources/template/command/cli.ftl +++ b/service-cli/service-cli-runner/src/main/resources/template/command/cli.ftl @@ -1,4 +1,4 @@ #!/bin/bash mkdir -p ${runtime.jarPath} export JASYPT_ENCRYPTOR_PASSWORD='r#(R,P\"Dp^A47>WSn:Wn].gs/+\"v:q_Q*An~zF*g-@j@jtSTv5H/,S-3:R?r9R}.' -${runtime.jdkPath} <#noparse>-Ddeploy.datetime=$(date +%Y%m%d%H%M%S) -Ddeploy.hostname=$(hostname) -Ddeploy.hostname-full=$(hostname -f) -Ddeploy.start-time=$(date +%Y%m%d%H%M%S) -Dlogging.parent=${runtime.logPath} -Dloki.url=${runtime.loki.servicePushUrl} -Dspring.cloud.zookeeper.connect-string=${runtime.zkUrl} -Dyarn-cluster.sync-clusters=${runtime.yarn.syncClusters} -Dyarn-cluster.compaction-clusters=${runtime.yarn.compactionClusters} -jar ${runtime.jarPath}/service-command.jar<#if directly> $@ +${runtime.jdkPath}/bin/java <#noparse>-Ddeploy.datetime=$(date +%Y%m%d%H%M%S) -Ddeploy.hostname=$(hostname) -Ddeploy.hostname-full=$(hostname -f) -Ddeploy.start-time=$(date +%Y%m%d%H%M%S) -Dlogging.parent=${runtime.logPath} -Dloki.url=${runtime.loki.servicePushUrl} -Dspring.cloud.zookeeper.connect-string=${runtime.zkUrl} -Dyarn-cluster.sync-clusters=${runtime.yarn.syncClusters} -Dyarn-cluster.compaction-clusters=${runtime.yarn.compactionClusters} -jar ${runtime.jarPath}/service-command.jar<#if directly> $@ diff --git a/service-cli/service-cli-runner/src/main/resources/template/uploader/start.ftl b/service-cli/service-cli-runner/src/main/resources/template/uploader/start.ftl index ce40772..149f98f 100644 --- a/service-cli/service-cli-runner/src/main/resources/template/uploader/start.ftl +++ b/service-cli/service-cli-runner/src/main/resources/template/uploader/start.ftl @@ -1,4 +1,4 @@ #!/bin/bash mkdir -p ${runtime.jarPath} export JASYPT_ENCRYPTOR_PASSWORD='r#(R,P"Dp^A47>WSn:Wn].gs/+"v:q_Q*An~zF*g-@j@jtSTv5H/,S-3:R?r9R}.' -nohup ${runtime.jdkPath} -jar ${runtime.jarPath}/service-uploader.jar <#noparse>--deploy.datetime=$(date +%Y%m%d%H%M%S) --deploy.hostname=$(hostname) --deploy.hostname-full=$(hostname -f) --deploy.start-time=$(date +%Y%m%d%H%M%S) --logging.parent=${runtime.logPath} --loki.url=${runtime.loki.servicePushUrl} --spring.cloud.zookeeper.connect-string=${runtime.zkUrl} --uploader.backend=local --uploader.tmp-dir=${runtime.dataPath}/uploader --spring.security.meta.authority='${runtime.security.authority}' --spring.security.meta.username='${runtime.security.username}' --spring.security.meta.darkcode='${runtime.security.darkcode}' > /dev/null 2>&1 & +nohup ${runtime.jdkPath}/bin/java -jar ${runtime.jarPath}/service-uploader.jar <#noparse>--deploy.datetime=$(date +%Y%m%d%H%M%S) --deploy.hostname=$(hostname) --deploy.hostname-full=$(hostname -f) --deploy.start-time=$(date +%Y%m%d%H%M%S) --logging.parent=${runtime.logPath} --loki.url=${runtime.loki.servicePushUrl} --spring.cloud.zookeeper.connect-string=${runtime.zkUrl} --uploader.backend=local --uploader.tmp-dir=${runtime.dataPath}/uploader --spring.security.meta.authority='${runtime.security.authority}' --spring.security.meta.username='${runtime.security.username}' --spring.security.meta.darkcode='${runtime.security.darkcode}' > /dev/null 2>&1 &