diff --git a/service-cli/service-cli-core/src/main/java/com/lanyuanxiaoyao/service/cli/core/HostInfo.java b/service-cli/service-cli-core/src/main/java/com/lanyuanxiaoyao/service/cli/core/HostInfo.java index 8cbac26..547cca4 100644 --- a/service-cli/service-cli-core/src/main/java/com/lanyuanxiaoyao/service/cli/core/HostInfo.java +++ b/service-cli/service-cli-core/src/main/java/com/lanyuanxiaoyao/service/cli/core/HostInfo.java @@ -53,6 +53,10 @@ public class HostInfo { this.password = password; } + public HostnameIp getHostnameIp() { + return new HostnameIp(host, ip); + } + @Override public String toString() { return "HostInfo{" + @@ -63,4 +67,30 @@ public class HostInfo { ", password='" + password + '\'' + '}'; } + + public static class HostnameIp { + private final String hostname; + private final String ip; + + private HostnameIp(String hostname, String ip) { + this.hostname = hostname; + this.ip = ip; + } + + public String getHostname() { + return hostname; + } + + public String getIp() { + return ip; + } + + @Override + public String toString() { + return "HostnameIp{" + + "hostname='" + hostname + '\'' + + ", ip='" + ip + '\'' + + '}'; + } + } } 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 61c8944..5b42be0 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 @@ -114,8 +114,8 @@ public class RunnerApplication implements ApplicationRunner { String deployScript = deployTemplate.render(MapUtil.builder() .put("hosts", deployInformationProperties.getHosts() .stream() - .map(HostInfo::getIp) - .sorted(Comparator.naturalOrder()) + .map(HostInfo::getHostnameIp) + .sorted((o1, o2) -> Comparator.naturalOrder().compare(o1.getIp(), o2.getIp())) .collect(Collectors.toList())) .put("selectedHosts", selectedHosts) .put("runtime", deployInformationProperties.getRuntime()) diff --git a/service-cli/service-cli-runner/src/main/resources/template/deploy.ftl b/service-cli/service-cli-runner/src/main/resources/template/deploy.ftl index 4c8c230..31b5195 100644 --- a/service-cli/service-cli-runner/src/main/resources/template/deploy.ftl +++ b/service-cli/service-cli-runner/src/main/resources/template/deploy.ftl @@ -14,12 +14,12 @@ security_username='${runtime.security.username}' security_darkcode='${runtime.security.darkcode}' <#list hosts as host> -host=${host} +host=${host.ip} +echo "${info.name} ${host.ip} ${host.hostname} $datetime" +ssh $host 'bash -s' < stop.sh ${runtime.jarPath}/${info.name}.jar +<#if selectedHosts?seq_contains(host.ip)> hostname=`ssh $host 'hostname'` hostname_full=`ssh $host 'hostname -f'` -echo "${info.name} $host $hostname $datetime" -ssh $host 'bash -s' < stop.sh ${runtime.jarPath}/${info.name}.jar -<#if selectedHosts?seq_contains(host)> ssh $host "mkdir -p ${runtime.jarPath};curl ftp://yyy:QeY\!68\)4nH1@132.121.122.15:2222/${info.sourceJar} -o ${runtime.jarPath}/${info.name}.jar" start_time=`date +%Y%m%d%H%M%S` 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?replace("_", ".")}=${environments[key]?string} -jar ${runtime.jarPath}/${info.name}.jar<#noparse> --datetime=${datetime} --hostname=${hostname} --deploy.datetime=${datetime} --deploy.ip=${host} --deploy.hostname=${hostname} --deploy.hostname-full=${hostname_full} --deploy.start-time=${start_time} --logging.parent=${log_path} --loki.url=${loki_url} --spring.cloud.zookeeper.connect-string=${zk_url} --spring.security.meta.authority='${security_authority}' --spring.security.meta.username='${security_username}' --spring.security.meta.darkcode='${security_darkcode}' <#list arguments?keys as key>--${key?replace("_", ".")}=${arguments[key]?string} > /dev/null 2>&1 &"