[ agent ] [ status ] - app status - 3
This commit is contained in:
@@ -3,6 +3,7 @@ package io.wdd.agent.executor;
|
|||||||
|
|
||||||
import io.wdd.agent.config.utils.AgentCommonThreadPool;
|
import io.wdd.agent.config.utils.AgentCommonThreadPool;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -14,6 +15,7 @@ import static java.util.stream.Collectors.groupingBy;
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Lazy
|
||||||
public class AppStatusExecutor {
|
public class AppStatusExecutor {
|
||||||
|
|
||||||
private static ArrayList<ArrayList<String>> APP_STATUS_CHECK_COMMAND;
|
private static ArrayList<ArrayList<String>> APP_STATUS_CHECK_COMMAND;
|
||||||
@@ -39,6 +41,7 @@ public class AppStatusExecutor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public HashMap<String, Set<String>> checkAppStatus(boolean allAppStatus){
|
public HashMap<String, Set<String>> checkAppStatus(boolean allAppStatus){
|
||||||
|
|
||||||
// check all app status
|
// check all app status
|
||||||
@@ -58,7 +61,8 @@ public class AppStatusExecutor {
|
|||||||
// deal with the app status future result
|
// deal with the app status future result
|
||||||
appStatusFuture -> {
|
appStatusFuture -> {
|
||||||
try {
|
try {
|
||||||
return appStatusFuture.get(5, TimeUnit.SECONDS);
|
return appStatusFuture.get(15, TimeUnit.SECONDS);
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package io.wdd.agent.executor;
|
|||||||
import io.wdd.agent.executor.config.CommandPipelineBuilder;
|
import io.wdd.agent.executor.config.CommandPipelineBuilder;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
@@ -28,25 +30,38 @@ public class CheckSingleAppStatusCallable implements Callable<String[]> {
|
|||||||
public String[] call() throws Exception {
|
public String[] call() throws Exception {
|
||||||
String[] result = new String[2];
|
String[] result = new String[2];
|
||||||
|
|
||||||
|
// appName is fixed here
|
||||||
|
result[1] = appName;
|
||||||
|
|
||||||
// set the specific app service name
|
// set the specific app service name
|
||||||
commandList.get(0).set(2, ALL_APP_NEED_TO_MONITOR_STATUS.get(appName));
|
commandList.get(0).set(2, ALL_APP_NEED_TO_MONITOR_STATUS.get(appName));
|
||||||
log.debug("current app [{}] status command are => {}", appName, commandList);
|
log.debug("current app [{}] status command are => {}", appName, commandList);
|
||||||
|
|
||||||
/* ProcessBuilder processBuilder = new ProcessBuilder(commandList);
|
// judge if the app is existed !
|
||||||
|
ProcessBuilder processBuilder = new ProcessBuilder(commandList.get(0));
|
||||||
Process process = processBuilder.start();
|
Process process = processBuilder.start();
|
||||||
|
boolean waitFor = process.waitFor(5, TimeUnit.SECONDS);
|
||||||
|
|
||||||
boolean waitFor = process.waitFor(20, TimeUnit.SECONDS);*/
|
if (ObjectUtils.isNotEmpty(waitFor)) {
|
||||||
|
// judge by error stream
|
||||||
|
String error = new BufferedReader(new InputStreamReader(process.getErrorStream())).readLine();
|
||||||
|
if (StringUtils.isNotEmpty(error)) {
|
||||||
|
// app not existed!
|
||||||
|
log.debug("app not installed !");
|
||||||
|
result[0] = "NotInstall";
|
||||||
|
} else {
|
||||||
|
log.debug("app existed! and then check the running status !");
|
||||||
|
// app existed! and then check the running status !
|
||||||
// get result from the command pipeline builder
|
// get result from the command pipeline builder
|
||||||
List<String> resultList = CommandPipelineBuilder.runGetResult(commandList);
|
List<String> resultList = CommandPipelineBuilder.runGetResult(commandList);
|
||||||
|
|
||||||
result[1] = appName;
|
|
||||||
|
|
||||||
if (ObjectUtils.isNotEmpty(resultList)) {
|
if (ObjectUtils.isNotEmpty(resultList)) {
|
||||||
log.debug("app status command has accomplished !");
|
log.debug("app status command has accomplished !");
|
||||||
|
|
||||||
String appStatusCommandResult = resultList.get(0);
|
String appStatusCommandResult = resultList.get(0);
|
||||||
|
|
||||||
|
Assert.notNull(appStatusCommandResult, "app status command result is null !");
|
||||||
|
|
||||||
if (appStatusCommandResult.startsWith("1")) {
|
if (appStatusCommandResult.startsWith("1")) {
|
||||||
result[0] = "Healthy";
|
result[0] = "Healthy";
|
||||||
} else if (appStatusCommandResult.startsWith("0")) {
|
} else if (appStatusCommandResult.startsWith("0")) {
|
||||||
@@ -55,8 +70,10 @@ public class CheckSingleAppStatusCallable implements Callable<String[]> {
|
|||||||
result[0] = "NotInstall";
|
result[0] = "NotInstall";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.debug("app [ {} ] status check result is => {} ", appName, resultList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.debug("app status check ok result is => [ {} ]", result);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package io.wdd.agent.executor.config;
|
|||||||
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.annotation.Lazy;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -13,6 +11,11 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://stackoverflow.com/questions/3776195/using-java-processbuilder-to-execute-a-piped-command
|
||||||
|
* https://www.baeldung.com/java-lang-processbuilder-api
|
||||||
|
* https://docs.oracle.com/javase/9/docs/api/java/lang/ProcessBuilder.html#startPipeline-java.util.List-
|
||||||
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class CommandPipelineBuilder {
|
public class CommandPipelineBuilder {
|
||||||
|
|
||||||
@@ -27,6 +30,11 @@ public class CommandPipelineBuilder {
|
|||||||
|
|
||||||
log.debug("command => [ {} ] , execute result is [ {} ]", commandList, resultList);
|
log.debug("command => [ {} ] , execute result is [ {} ]", commandList, resultList);
|
||||||
|
|
||||||
|
// error stream can't be got
|
||||||
|
// maybe this is the design patten of ProcessBuilder
|
||||||
|
/*List<String> error = new BufferedReader(new InputStreamReader(processList.get(lastCommandIndex).getErrorStream())).lines().collect(Collectors.toList());
|
||||||
|
log.debug("command => {} error is {}", commandList, error);*/
|
||||||
|
|
||||||
return resultList;
|
return resultList;
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -71,7 +79,8 @@ public class CommandPipelineBuilder {
|
|||||||
|
|
||||||
return ProcessBuilder.startPipeline(List.of(
|
return ProcessBuilder.startPipeline(List.of(
|
||||||
new ProcessBuilder(commandList1)
|
new ProcessBuilder(commandList1)
|
||||||
.inheritIO().redirectOutput(ProcessBuilder.Redirect.PIPE),
|
.inheritIO()
|
||||||
|
.redirectOutput(ProcessBuilder.Redirect.PIPE),
|
||||||
new ProcessBuilder(commandList2)
|
new ProcessBuilder(commandList2)
|
||||||
.redirectError(ProcessBuilder.Redirect.INHERIT)
|
.redirectError(ProcessBuilder.Redirect.INHERIT)
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -1,30 +1,37 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
echo start to update !
|
command_exists() {
|
||||||
apt-get update
|
command -v "$@" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
command_exists "docker info"
|
||||||
|
if [[ $? -ne 0 ]] ; then
|
||||||
|
echo "no"
|
||||||
|
else
|
||||||
|
echo "yes"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
echo "
|
dockerVersion="20.10.10"
|
||||||
|
|
||||||
echo start to install nginx
|
echo $dockerVersion | cut -d"." -f-2
|
||||||
apt-get install nginx -y
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo start to uninstall nginx
|
|
||||||
apt remove nginx -y
|
|
||||||
|
|
||||||
|
|
||||||
echo
|
export JAVA_OPTS="-Xms2048m -Xmx2048m -Dfile.encoding=utf-8 -Dspring.profiles.active=k3s -Dspring.cloud.nacos.config.group=k3s -Dspring.cloud.nacos.config.extension-configs[0].dataId=common-k3s.yaml -Dspring.cloud.nacos.config.extension-configs[0].group=k3s -Ddebug=false -Dlogging.level.io.wdd.server=info"
|
||||||
echo start to get ip info
|
export OctopusServerContainerName="octopus-server"
|
||||||
curl https://ipinfo.io
|
|
||||||
|
|
||||||
|
docker container stop ${OctopusServerContainerName}
|
||||||
echo
|
sleep 2
|
||||||
echo --- end ---
|
docker container rm ${OctopusServerContainerName}
|
||||||
|
docker image rmi docker.io/icederce/wdd-octopus-server:latest
|
||||||
|
|
||||||
|
|
||||||
systemctl status nginx.service | grep -c "active (running)"
|
systemctl status nginx.service | grep -c "active (running)"
|
||||||
|
|
||||||
|
docker logs --tail 500 -f ${ServerContainerName}
|
||||||
|
docker run -d \
|
||||||
|
-p 9999:9999 \
|
||||||
|
--name ${OctopusServerContainerName} \
|
||||||
|
--env JAVA_OPTS="${JAVA_OPTS}" \
|
||||||
|
docker.io/icederce/wdd-octopus-server:latest
|
||||||
Reference in New Issue
Block a user