[agent] test boot up
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
FROM icederce/eclipse-temurin-11-jre-focal
|
FROM icederce/eclipse-temurin-11-jre-focal
|
||||||
|
|
||||||
# Set environment variables
|
# Set environment variables
|
||||||
ENV TZ=Asia/Shanghai JAVA_OPTS="-Xms2028m -Xmx2048m" ServerName="" serverIpPbV4="" serverIpInV4="" serverIpPbV6="" serverIpInV6="" location="" provider="" managePort="" cpuBrand="" cpuCore="" memoryTotal="" diskTotal="" diskUsage="" osInfo="" osKernelInfo="" tcpControl="" virtualization="" ioSpeed=""
|
ENV TZ=Asia/Shanghai ServerName="" serverIpPbV4="" serverIpInV4="" serverIpPbV6="" serverIpInV6="" location="" provider="" managePort="" cpuBrand="" cpuCore="" memoryTotal="" diskTotal="" diskUsage="" osInfo="" osKernelInfo="" tcpControl="" virtualization="" ioSpeed="" JAVA_OPTS="-Xms2028m -Xmx2048m"
|
||||||
|
|
||||||
# Set time zone
|
# Set time zone
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -12,83 +14,100 @@ import java.util.Date;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@SuperBuilder(toBuilder = true)
|
@SuperBuilder(toBuilder = true)
|
||||||
|
@Configuration
|
||||||
public class ServerInfo {
|
public class ServerInfo {
|
||||||
|
|
||||||
|
@Value("${serverName}")
|
||||||
private String serverName;
|
private String serverName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* server public ipv4
|
* server public ipv4
|
||||||
*/
|
*/
|
||||||
|
@Value("${serverIpPbV4}")
|
||||||
private String serverIpPbV4;
|
private String serverIpPbV4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* server inner ipv4
|
* server inner ipv4
|
||||||
*/
|
*/
|
||||||
|
@Value("${serverIpInV4}")
|
||||||
private String serverIpInV4;
|
private String serverIpInV4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* server public ipv6
|
* server public ipv6
|
||||||
*/
|
*/
|
||||||
|
@Value("${serverIpPbV6}")
|
||||||
private String serverIpPbV6;
|
private String serverIpPbV6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* server inner ipv6
|
* server inner ipv6
|
||||||
*/
|
*/
|
||||||
|
@Value("${serverIpInV6}")
|
||||||
private String serverIpInV6;
|
private String serverIpInV6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Value("${location}")
|
||||||
private String location;
|
private String location;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Value("${provider}")
|
||||||
private String provider;
|
private String provider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* split by ,
|
* split by ,
|
||||||
*/
|
*/
|
||||||
|
@Value("${managePort}")
|
||||||
private String managePort;
|
private String managePort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Value("${cpuCore}")
|
||||||
private Integer cpuCore;
|
private Integer cpuCore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Value("${cpuBrand}")
|
||||||
private String cpuBrand;
|
private String cpuBrand;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Value("${osInfo}")
|
||||||
private String osInfo;
|
private String osInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Value("${osKernelInfo}")
|
||||||
private String osKernelInfo;
|
private String osKernelInfo;
|
||||||
|
|
||||||
|
@Value("${tcpControl}")
|
||||||
private String tcpControl;
|
private String tcpControl;
|
||||||
|
|
||||||
|
@Value("${virtualization}")
|
||||||
private String virtualization;
|
private String virtualization;
|
||||||
|
|
||||||
|
@Value("${ioSpeed}")
|
||||||
private String ioSpeed;
|
private String ioSpeed;
|
||||||
|
|
||||||
|
@Value("${memoryTotal}")
|
||||||
private String memoryTotal;
|
private String memoryTotal;
|
||||||
|
|
||||||
|
@Value("${diskTotal}")
|
||||||
private String diskTotal;
|
private String diskTotal;
|
||||||
|
|
||||||
|
@Value("${diskUsage}")
|
||||||
private String diskUsage;
|
private String diskUsage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Value("${serverIpPbV4}")
|
||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -727,6 +727,62 @@ print_GoIOTest() {
|
|||||||
FunctionEnd
|
FunctionEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_virt(){
|
||||||
|
command_exists "dmesg" && virtualx="$(dmesg 2>/dev/null)"
|
||||||
|
if command_exists "dmidecode"; then
|
||||||
|
sys_manu="$(dmidecode -s system-manufacturer 2>/dev/null)"
|
||||||
|
sys_product="$(dmidecode -s system-product-name 2>/dev/null)"
|
||||||
|
sys_ver="$(dmidecode -s system-version 2>/dev/null)"
|
||||||
|
else
|
||||||
|
sys_manu=""
|
||||||
|
sys_product=""
|
||||||
|
sys_ver=""
|
||||||
|
fi
|
||||||
|
if grep -qa docker /proc/1/cgroup; then
|
||||||
|
virt="Docker"
|
||||||
|
elif grep -qa lxc /proc/1/cgroup; then
|
||||||
|
virt="LXC"
|
||||||
|
elif grep -qa container=lxc /proc/1/environ; then
|
||||||
|
virt="LXC"
|
||||||
|
elif [[ -f /proc/user_beancounters ]]; then
|
||||||
|
virt="OpenVZ"
|
||||||
|
elif [[ "${virtualx}" == *kvm-clock* ]]; then
|
||||||
|
virt="KVM"
|
||||||
|
elif [[ "${sys_product}" == *KVM* ]]; then
|
||||||
|
virt="KVM"
|
||||||
|
elif [[ "${cname}" == *KVM* ]]; then
|
||||||
|
virt="KVM"
|
||||||
|
elif [[ "${cname}" == *QEMU* ]]; then
|
||||||
|
virt="KVM"
|
||||||
|
elif [[ "${virtualx}" == *"VMware Virtual Platform"* ]]; then
|
||||||
|
virt="VMware"
|
||||||
|
elif [[ "${sys_product}" == *"VMware Virtual Platform"* ]]; then
|
||||||
|
virt="VMware"
|
||||||
|
elif [[ "${virtualx}" == *"Parallels Software International"* ]]; then
|
||||||
|
virt="Parallels"
|
||||||
|
elif [[ "${virtualx}" == *VirtualBox* ]]; then
|
||||||
|
virt="VirtualBox"
|
||||||
|
elif [[ -e /proc/xen ]]; then
|
||||||
|
if grep -q "control_d" "/proc/xen/capabilities" 2>/dev/null; then
|
||||||
|
virt="Xen-Dom0"
|
||||||
|
else
|
||||||
|
virt="Xen-DomU"
|
||||||
|
fi
|
||||||
|
elif [ -f "/sys/hypervisor/type" ] && grep -q "xen" "/sys/hypervisor/type"; then
|
||||||
|
virt="Xen"
|
||||||
|
elif [[ "${sys_manu}" == *"Microsoft Corporation"* ]]; then
|
||||||
|
if [[ "${sys_product}" == *"Virtual Machine"* ]]; then
|
||||||
|
if [[ "${sys_ver}" == *"7.0"* || "${sys_ver}" == *"Hyper-V" ]]; then
|
||||||
|
virt="Hyper-V"
|
||||||
|
else
|
||||||
|
virt="Microsoft Virtual Machine"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
virt="Dedicated"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
GetIpv4Info() {
|
GetIpv4Info() {
|
||||||
org="$(wget -q -T10 -O- ipinfo.io/org)"
|
org="$(wget -q -T10 -O- ipinfo.io/org)"
|
||||||
city="$(wget -q -T10 -O- ipinfo.io/city)"
|
city="$(wget -q -T10 -O- ipinfo.io/city)"
|
||||||
@@ -802,6 +858,9 @@ generateSystemInfo() {
|
|||||||
FunctionSuccess
|
FunctionSuccess
|
||||||
GetIpv4Info
|
GetIpv4Info
|
||||||
FunctionSuccess
|
FunctionSuccess
|
||||||
|
check_virt
|
||||||
|
FunctionSuccess
|
||||||
|
|
||||||
|
|
||||||
ServerName="$(cat /etc/hostname)"
|
ServerName="$(cat /etc/hostname)"
|
||||||
serverIpPbV4="$public_ipv4"
|
serverIpPbV4="$public_ipv4"
|
||||||
@@ -810,7 +869,7 @@ generateSystemInfo() {
|
|||||||
serverIpInV6=""
|
serverIpInV6=""
|
||||||
location="$city $region $country"
|
location="$city $region $country"
|
||||||
provider="$org"
|
provider="$org"
|
||||||
managePort="netstat -ntulp | grep sshd | grep -w tcp | awk '{print$4}' | cut -d":" -f2"
|
managePort="$(netstat -ntulp | grep sshd | grep -w tcp | awk '{print$4}' | cut -d":" -f2)"
|
||||||
cpuCore="$cname"
|
cpuCore="$cname"
|
||||||
cpuBrand="$cores @ $freq MHz"
|
cpuBrand="$cores @ $freq MHz"
|
||||||
memoryTotal="$tram"
|
memoryTotal="$tram"
|
||||||
@@ -832,6 +891,27 @@ deployOctopusAgent() {
|
|||||||
# get the latest version of Octopus agent
|
# get the latest version of Octopus agent
|
||||||
# poll the start up shell
|
# poll the start up shell
|
||||||
|
|
||||||
|
echo "docker run -d \
|
||||||
|
-e ServerName="${ServerName}" \
|
||||||
|
-e serverIpPbV4="$serverIpPbV4" \
|
||||||
|
-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" \
|
||||||
|
icederce/wdd-octopus-agent:latest"
|
||||||
|
|
||||||
docker run -d \
|
docker run -d \
|
||||||
-e ServerName="${ServerName}" \
|
-e ServerName="${ServerName}" \
|
||||||
-e serverIpPbV4="$serverIpPbV4" \
|
-e serverIpPbV4="$serverIpPbV4" \
|
||||||
|
|||||||
@@ -2,24 +2,29 @@ package io.wdd.agent.initial.bootup.reference;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import io.wdd.agent.initial.beans.ServerInfo;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class collectSystemInfo {
|
@Slf4j
|
||||||
|
public class collectSystemInfo implements ApplicationContextAware {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
Environment environment;
|
Environment environment;
|
||||||
|
|
||||||
|
private ApplicationContext context;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public void initialReadingEnvironment(){
|
public void initialReadingEnvironment(){
|
||||||
@@ -33,8 +38,26 @@ public class collectSystemInfo {
|
|||||||
|
|
||||||
Properties props =System.getProperties();
|
Properties props =System.getProperties();
|
||||||
|
|
||||||
|
System.out.println("props = " + props);
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
Map<String, String> getenv = System.getenv();
|
||||||
|
|
||||||
|
System.out.println("getenv = " + getenv);
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
System.out.println("environment = " + environment);
|
||||||
|
|
||||||
|
InetAddress loopbackAddress = InetAddress.getLoopbackAddress();
|
||||||
|
|
||||||
|
System.out.println("loopbackAddress = " + loopbackAddress);
|
||||||
|
|
||||||
InetAddress ip = InetAddress.getLocalHost();
|
InetAddress ip = InetAddress.getLocalHost();
|
||||||
String localName = ip.getHostName();
|
String localName = ip.getHostName();
|
||||||
|
|
||||||
|
System.out.println("ip = " + ip);
|
||||||
|
|
||||||
String osName = System.getProperty("os.name");
|
String osName = System.getProperty("os.name");
|
||||||
String userName = System.getProperty("user.name");
|
String userName = System.getProperty("user.name");
|
||||||
String osVersion = System.getProperty("os.version");
|
String osVersion = System.getProperty("os.version");
|
||||||
@@ -47,10 +70,27 @@ public class collectSystemInfo {
|
|||||||
System.out.println("主机系统:" + osName);
|
System.out.println("主机系统:" + osName);
|
||||||
System.out.println("系统版本:" + osVersion);
|
System.out.println("系统版本:" + osVersion);
|
||||||
System.out.println("系统架构:" + osArch);
|
System.out.println("系统架构:" + osArch);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
private void getInjectServerInfo(){
|
||||||
|
|
||||||
|
log.info("getInjectServerInfo");
|
||||||
|
|
||||||
|
ServerInfo serverInfo = (ServerInfo) context.getBean("serverInfo");
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("serverInfo = " + serverInfo);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
|
this.context = applicationContext;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user