feat(launcher): 增加批量执行ssh命令脚本
This commit is contained in:
@@ -187,8 +187,8 @@ public class RunnerApplication implements ApplicationRunner {
|
|||||||
MapUtil.builder()
|
MapUtil.builder()
|
||||||
.put("currentPath", absolutRootPath)
|
.put("currentPath", absolutRootPath)
|
||||||
.put("hosts", hostInfoList
|
.put("hosts", hostInfoList
|
||||||
.collect(HostInfoWrapper::getIp)
|
.collect(HostInfoWrapper::getHostnameIp)
|
||||||
.toSortedList(Comparator.naturalOrder()))
|
.toSortedList((o1, o2) -> Comparator.<String>naturalOrder().compare(o1.getIp(), o2.getIp())))
|
||||||
.put("runtime", runtimeInfo)
|
.put("runtime", runtimeInfo)
|
||||||
.put("info", serviceInfo)
|
.put("info", serviceInfo)
|
||||||
.put("arguments", serviceInfo.getArguments())
|
.put("arguments", serviceInfo.getArguments())
|
||||||
@@ -204,8 +204,8 @@ public class RunnerApplication implements ApplicationRunner {
|
|||||||
MapUtil.builder()
|
MapUtil.builder()
|
||||||
.put("currentPath", absolutRootPath)
|
.put("currentPath", absolutRootPath)
|
||||||
.put("hosts", hostInfoList
|
.put("hosts", hostInfoList
|
||||||
.collect(HostInfoWrapper::getIp)
|
.collect(HostInfoWrapper::getHostnameIp)
|
||||||
.toSortedList(Comparator.naturalOrder()))
|
.toSortedList((o1, o2) -> Comparator.<String>naturalOrder().compare(o1.getIp(), o2.getIp())))
|
||||||
.put("selectedHosts", selectedHosts)
|
.put("selectedHosts", selectedHosts)
|
||||||
.put("runtime", runtimeInfo)
|
.put("runtime", runtimeInfo)
|
||||||
.put("info", serviceInfo)
|
.put("info", serviceInfo)
|
||||||
@@ -228,6 +228,18 @@ public class RunnerApplication implements ApplicationRunner {
|
|||||||
Paths.get(root.toString(), "stop.sh")
|
Paths.get(root.toString(), "stop.sh")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
generateTemplate(
|
||||||
|
"cloud/ssh-script.ftl",
|
||||||
|
MapUtil.builder()
|
||||||
|
.put("currentPath", absolutRootPath)
|
||||||
|
.put("hosts", hostInfoList
|
||||||
|
.collect(HostInfoWrapper::getHostnameIp)
|
||||||
|
.toSortedList((o1, o2) -> Comparator.<String>naturalOrder().compare(o1.getIp(), o2.getIp())))
|
||||||
|
.put("runtime", runtimeInfo)
|
||||||
|
.build(),
|
||||||
|
Paths.get(root.toString(), "ssh.sh")
|
||||||
|
);
|
||||||
|
|
||||||
MutableMap<String, MutableList<ServiceInfoWrapper>> groups = Maps.mutable.empty();
|
MutableMap<String, MutableList<ServiceInfoWrapper>> groups = Maps.mutable.empty();
|
||||||
for (ServiceInfoWrapper service : serviceInfoList) {
|
for (ServiceInfoWrapper service : serviceInfoList) {
|
||||||
service.getGroups().add(0, "all");
|
service.getGroups().add(0, "all");
|
||||||
|
|||||||
@@ -13,5 +13,5 @@ for host in <#noparse>${hosts[@]}</#noparse>
|
|||||||
do
|
do
|
||||||
hostname=`ssh $host 'echo $HOSTNAME'`
|
hostname=`ssh $host 'echo $HOSTNAME'`
|
||||||
echo "$host $hostname"
|
echo "$host $hostname"
|
||||||
ssh $host "cat ${runtime.logPath}/${info.name}.log" > ${currentPath}/logs/${info.name}/$hostname.log
|
scp $host:${runtime.logPath}/${info.name}.log ${currentPath}/logs/${info.name}/$hostname.log
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
command=$@
|
||||||
|
|
||||||
|
hosts=(
|
||||||
|
<#list hosts as host>
|
||||||
|
${host.ip}
|
||||||
|
</#list>
|
||||||
|
)
|
||||||
|
|
||||||
|
for host in <#noparse>${hosts[@]}</#noparse>
|
||||||
|
do
|
||||||
|
hostname=`ssh $host 'echo $HOSTNAME'`
|
||||||
|
echo "$host $hostname"
|
||||||
|
ssh $host $command
|
||||||
|
done
|
||||||
@@ -1,14 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
hosts=(
|
|
||||||
<#list hosts as host>
|
<#list hosts as host>
|
||||||
${host}
|
host=${host.ip}
|
||||||
</#list>
|
echo "${info.name} ${host.ip} ${host.hostname} $datetime"
|
||||||
)
|
|
||||||
|
|
||||||
for host in <#noparse>${hosts[@]}</#noparse>
|
|
||||||
do
|
|
||||||
hostname=`ssh $host 'echo $HOSTNAME'`
|
|
||||||
echo "$host $hostname"
|
|
||||||
ssh $host 'bash -s' < ${currentPath}/stop.sh ${runtime.jarPath}/${info.name}.jar
|
ssh $host 'bash -s' < ${currentPath}/stop.sh ${runtime.jarPath}/${info.name}.jar
|
||||||
done
|
</#list>
|
||||||
|
|||||||
Reference in New Issue
Block a user