[ project ] accomplish linux-agent boot up environment
This commit is contained in:
@@ -4,7 +4,7 @@ import com.google.common.io.ByteStreams;
|
||||
import io.wdd.agent.excuetor.redis.StreamSender;
|
||||
import io.wdd.agent.excuetor.thread.DaemonLogThread;
|
||||
import io.wdd.agent.excuetor.thread.LogToStreamSender;
|
||||
import io.wdd.agent.excuetor.thread.LogToSysOut;
|
||||
import io.wdd.common.handler.MyRuntimeException;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -12,6 +12,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
@@ -22,28 +23,48 @@ public class CommandExecutor {
|
||||
@Resource
|
||||
StreamSender streamSender;
|
||||
|
||||
public void execute(String streamKey, String... command) throws IOException, InterruptedException, ExecutionException {
|
||||
|
||||
public void execute(String streamKey, List<String> command) {
|
||||
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command);
|
||||
|
||||
// processBuilder.redirectErrorStream(true);
|
||||
// processBuilder.inheritIO();
|
||||
processBuilder.directory(new File(System.getProperty("user.home")));
|
||||
Process process = processBuilder.start();
|
||||
|
||||
LogToStreamSender toStreamSender = new LogToStreamSender(streamKey, process.getInputStream(), streamSender::send);
|
||||
|
||||
// LogToSysOut(process.getInputStream(), System.out::println);
|
||||
|
||||
// a command shell don't understand how long it actually take
|
||||
int processResult = process.waitFor();
|
||||
System.out.println("processResult = " + processResult);
|
||||
|
||||
Future<?> future = DaemonLogThread.start(toStreamSender);
|
||||
|
||||
System.out.println("future.get() = " + future.get());
|
||||
this.processExecute(streamKey, processBuilder);
|
||||
}
|
||||
|
||||
public void execute(String streamKey, String... command) {
|
||||
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command);
|
||||
|
||||
this.processExecute(streamKey, processBuilder);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void processExecute(String streamKey, ProcessBuilder processBuilder){
|
||||
|
||||
processBuilder.redirectErrorStream(true);
|
||||
processBuilder.inheritIO();
|
||||
processBuilder.directory(new File(System.getProperty("user.home")));
|
||||
|
||||
Process process = null;
|
||||
try {
|
||||
process = processBuilder.start();
|
||||
|
||||
LogToStreamSender toStreamSender = new LogToStreamSender(streamKey, process.getInputStream(), streamSender::send);
|
||||
|
||||
// a command shell don't understand how long it actually take
|
||||
int processResult = process.waitFor();
|
||||
|
||||
System.out.println("processResult = " + processResult);
|
||||
|
||||
DaemonLogThread.start(toStreamSender);
|
||||
|
||||
|
||||
} catch (IOException | InterruptedException e) {
|
||||
|
||||
throw new MyRuntimeException("{} + {}", e.getCause(), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private ByteBuffer cvToByteBuffer(InputStream inputStream) throws IOException {
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package io.wdd.agent.excuetor.web;
|
||||
|
||||
|
||||
import io.wdd.agent.excuetor.shell.CommandExecutor;
|
||||
import io.wdd.common.beans.response.R;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("testExecutor")
|
||||
public class TestCommandExecutorController {
|
||||
|
||||
@Resource
|
||||
CommandExecutor commandExecutor;
|
||||
|
||||
|
||||
@PostMapping("comand")
|
||||
public R<String> testFor(
|
||||
@RequestParam(value = "streamKey") String streamKey,
|
||||
@RequestParam(value = "command") List<String> command
|
||||
){
|
||||
commandExecutor.execute(streamKey, command);
|
||||
|
||||
return R.ok(streamKey);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
docker run -d \
|
||||
-e ServerName: "${ServerName}" \
|
||||
-e serverIpPbV4: "$serverIspPbV4" \
|
||||
-e serverIpInV4: "$serverIpInV4" \
|
||||
-e serverIpPbV6: "$serverIpPbV6" \
|
||||
-e serverIpInV6: "$serverIpInV6" \
|
||||
-e location: "$location" \
|
||||
-e provider: "$provider" \
|
||||
-e managePort: "$managePort" \
|
||||
-e cpuBrand: "$cpuBrand" \
|
||||
-e cpuCore: "$cpuCore" \
|
||||
-e memoryTotal: "$memoryTotal" \
|
||||
-e diskTotal: "$diskTotal" \
|
||||
-e diskUsage: "$diskUsage" \
|
||||
-e osInfo: "$osInfo" \
|
||||
-e osKernelInfo: "$osKernelInfo" \
|
||||
-e tcpControl: "$tcpControl" \
|
||||
-e virtualization: "$virtualization" \
|
||||
-e ioSpeed: "$ioSpeed" \
|
||||
--env serverName="${ServerName}" \
|
||||
--env serverIpPbV4="$serverIspPbV4" \
|
||||
--env serverIpInV4="$serverIpInV4" \
|
||||
--env serverIpPbV6="$serverIpPbV6" \
|
||||
--env serverIpInV6= "$serverIpInV6" \
|
||||
--env location="$location" \
|
||||
--env provider="$provider" \
|
||||
--env managePort= "$managePort" \
|
||||
--env cpuBrand="$cpuBrand" \
|
||||
--env cpuCore="$cpuCore" \
|
||||
--env memoryTotal="$memoryTotal" \
|
||||
--env diskTotal="$diskTotal" \
|
||||
--env diskUsage="$diskUsage" \
|
||||
--env osInfo="$osInfo" \
|
||||
--env osKernelInfo="$osKernelInfo" \
|
||||
--env tcpControl="$tcpControl" \
|
||||
--env virtualization="$virtualization" \
|
||||
--env ioSpeed="$ioSpeed" \
|
||||
--privileged \
|
||||
--net=host \
|
||||
--pid=host \
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
docker container stop octopus-agent-ubuntu && docker container rm octopus-agent-ubuntu
|
||||
|
||||
docker run \
|
||||
-d \
|
||||
--privileged \
|
||||
--net=host \
|
||||
--pid=host \
|
||||
--ipc=host \
|
||||
--volume /:/host \
|
||||
--name=octopus-agent-ubuntu \
|
||||
octopus-agent-ubuntu:latest \
|
||||
|
||||
docker logs --tail -f octopus-agent-ubuntu
|
||||
|
||||
docker run \
|
||||
-d \
|
||||
-it \
|
||||
--env serverName="UbuntuStation" \
|
||||
--env serverIpPbV4="112.12312.1.1" \
|
||||
--env serverIpInV4="10.250.0.20" \
|
||||
--env serverIpPbV6="" \
|
||||
--env serverIpInV6="" \
|
||||
--env location="Chengdu" \
|
||||
--env provider="Lenovo" \
|
||||
--env managePort="22" \
|
||||
--env cpuBrand="i7 8700" \
|
||||
--env cpuCore="6" \
|
||||
--env memoryTotal="8 GB" \
|
||||
--env diskTotal="1 TB" \
|
||||
--env diskUsage="200 GB" \
|
||||
--env osInfo="Ubuntu 20.04.04" \
|
||||
--env osKernelInfo="5.10" \
|
||||
--env tcpControl="bbr" \
|
||||
--env virtualization="dedicated" \
|
||||
--env ioSpeed="150 MB/s" \
|
||||
--privileged \
|
||||
--net=host \
|
||||
--pid=host \
|
||||
--ipc=host \
|
||||
--volume /:/host \
|
||||
--name=octopus-agent-ubuntu \
|
||||
octopus-agent-ubuntu:latest \
|
||||
# chroot /host && /bin/bash
|
||||
/bin/bash
|
||||
|
||||
|
||||
@@ -1161,7 +1161,8 @@ main() {
|
||||
# modifySystemConfig_Kubernetes
|
||||
|
||||
# 安装宇宙第一shell的zsh
|
||||
InstallZSH cn || return $?
|
||||
# InstallZSH cn || return $?
|
||||
modifyZSH cn
|
||||
|
||||
# 使用chrony进行NTP时间同步--包含下面的设置
|
||||
# TimeSyncToAliByChrony || return $?
|
||||
|
||||
@@ -8,30 +8,24 @@ import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@SpringBootTest
|
||||
//@SpringBootTest
|
||||
public class InitRabbitMQTest {
|
||||
|
||||
@Resource
|
||||
CommandExecutor commandExecutor;
|
||||
|
||||
|
||||
@Test
|
||||
// @Test
|
||||
void testInitSendInfo() {
|
||||
|
||||
String homeDirectory = System.getProperty("user.home");
|
||||
try {
|
||||
String format = String.format("C:\\program files\\powershell\\7\\pwsh.exe /c dir %s | findstr \"Desktop\"", homeDirectory);
|
||||
|
||||
commandExecutor.execute("sasda",
|
||||
"C:\\program files\\powershell\\7\\pwsh.exe",
|
||||
"pwd");
|
||||
String format = String.format("C:\\program files\\powershell\\7\\pwsh.exe /c dir %s | findstr \"Desktop\"", homeDirectory);
|
||||
|
||||
commandExecutor.execute("sasda",
|
||||
"C:\\program files\\powershell\\7\\pwsh.exe",
|
||||
"pwd");
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user