Merge remote-tracking branch 'origin/main' into main
This commit is contained in:
4
.github/workflows/build-push-docker.yml
vendored
4
.github/workflows/build-push-docker.yml
vendored
@@ -128,9 +128,9 @@ jobs:
|
||||
echo "--------------------------------------"
|
||||
cd ./agent/target
|
||||
ls
|
||||
date --date='TZ="Asia/Shanghai"' --rfc-3339=seconds | cut -d"+" -f1 | sed "s/ /-/g" | sed "s/:/-/g"
|
||||
echo "current time is $(date --rfc-3339=seconds | cut -d"+" -f1 | sed "s/ /-/g" | sed "s/:/-/g")"
|
||||
echo "start to copy target jar"
|
||||
cp ./agent-*.jar ./octopus-agent-$(date --date='TZ="Asia/Shanghai"' --rfc-3339=seconds | cut -d"+" -f1 | sed "s/ /-/g" | sed "s/:/-/g").jar
|
||||
cp ./agent-*.jar ./octopus-agent-$(date --rfc-3339=seconds | cut -d"+" -f1 | sed "s/ /-/g" | sed "s/:/-/g").jar
|
||||
cd /home/runner/work/ProjectOctopus/ProjectOctopus
|
||||
echo "--------------------------------------"
|
||||
cat /proc/cpuinfo
|
||||
|
||||
@@ -35,7 +35,7 @@ public class CommandExecutor {
|
||||
/**
|
||||
* handle command from octopus server
|
||||
*
|
||||
* @param executionMessage get from EXECUTOR_HANDLER
|
||||
* @param executionMessage get from EXECUTOR_HANDLERju
|
||||
*/
|
||||
public void execute(ExecutionMessage executionMessage) {
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.wdd.rpc.execute.service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.wdd.common.beans.executor.ExecutionMessage;
|
||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
||||
@@ -18,6 +20,8 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
|
||||
@Resource
|
||||
ToAgentMessageSender messageSender;
|
||||
|
||||
@Resource
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
public String SendCommandToAgent(String topicName, String command) {
|
||||
@@ -34,11 +38,22 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
|
||||
|
||||
OctopusMessage octopusMessage = this.generateOctopusMessage(topicName, type, commandList);
|
||||
|
||||
ExecutionMessage executionMessage = (ExecutionMessage) octopusMessage.getContent();
|
||||
|
||||
String executionMsg;
|
||||
|
||||
try {
|
||||
|
||||
executionMsg = objectMapper.writeValueAsString(executionMessage);
|
||||
octopusMessage.setContent(executionMsg);
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
messageSender.send(octopusMessage);
|
||||
|
||||
ExecutionMessage content = (ExecutionMessage) octopusMessage.getContent();
|
||||
|
||||
return content.getResultKey();
|
||||
return executionMessage.getResultKey();
|
||||
}
|
||||
|
||||
|
||||
@@ -53,15 +68,16 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
|
||||
|
||||
private OctopusMessage generateOctopusMessage(String topicName, String type, List<String> commandList){
|
||||
|
||||
ExecutionMessage executionMessage = generateExecutionMessage(
|
||||
type,
|
||||
commandList,
|
||||
generateCommandResultKey(topicName)
|
||||
);
|
||||
|
||||
return OctopusMessage.builder()
|
||||
.type(OctopusMessageType.EXECUTOR)
|
||||
.init_time(LocalDateTime.now())
|
||||
.content(generateExecutionMessage(
|
||||
type,
|
||||
commandList,
|
||||
generateCommandResultKey(topicName)
|
||||
))
|
||||
.content(executionMessage)
|
||||
.uuid(topicName)
|
||||
.build();
|
||||
}
|
||||
@@ -78,7 +94,7 @@ public class CoreExecutionServiceImpl implements CoreExecutionService {
|
||||
|
||||
private String generateCommandResultKey(String topicName) {
|
||||
|
||||
String TimeString = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
String TimeString = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss"));
|
||||
|
||||
return topicName + "-" + TimeString;
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@ public class AcceptAgentInitInfo {
|
||||
if (!checkAgentAlreadyRegister(agentQueueTopic)) {
|
||||
// 3. save the agent info into database
|
||||
// backend fixed thread daemon to operate the database ensuring the operation is correct !
|
||||
log.info("[AGENT INIT] - agent not exist ! start to register !");
|
||||
if (!databaseOperator.saveInitOctopusAgentInfo(serverInfoVO)) {
|
||||
throw new MyRuntimeException("database save agent info error !");
|
||||
}
|
||||
|
||||
@@ -40,8 +40,10 @@ public class OctopusMessageHandlerServer {
|
||||
|
||||
// todo what to do after received the result
|
||||
|
||||
// log info ?
|
||||
// update the database
|
||||
// handle the result
|
||||
// collect all message from agent and log to somewhere
|
||||
|
||||
// 1. send some info to the specific topic name
|
||||
// 2. judge from which agent the message are
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,9 +53,13 @@ public class ToAgentMessageSender {
|
||||
|
||||
public void send(OctopusMessage octopusMessage) {
|
||||
|
||||
log.info("OctopusMessage {} send to agent {}",octopusMessage, octopusMessage.getUuid());
|
||||
log.info("OctopusMessage {} send to agent {}", octopusMessage, octopusMessage.getUuid());
|
||||
|
||||
|
||||
rabbitTemplate.convertAndSend(
|
||||
initRabbitMQConfig.OCTOPUS_EXCHANGE,
|
||||
octopusMessage.getUuid()+"*",
|
||||
writeData(octopusMessage));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import io.wdd.server.beans.vo.ServerInfoVO;
|
||||
import io.wdd.server.coreService.CoreServerService;
|
||||
import io.wdd.server.service.*;
|
||||
import io.wdd.server.utils.EntityUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
@@ -24,6 +25,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class CoreServerServiceImpl implements CoreServerService {
|
||||
|
||||
@Resource
|
||||
|
||||
20
server/src/main/resources/application-local.yml
Normal file
20
server/src/main/resources/application-local.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
spring:
|
||||
application:
|
||||
name: octopus-server
|
||||
profiles:
|
||||
active: local
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
group: local
|
||||
config-retry-time: 3000
|
||||
file-extension: yaml
|
||||
max-retry: 3
|
||||
# server-addr: 43.154.83.213:21060
|
||||
# server-addr: 140.238.52.228:21060
|
||||
server-addr: https://nacos.107421.xyz:443
|
||||
timeout: 5000
|
||||
config-long-poll-timeout: 5000
|
||||
extension-configs:
|
||||
- group: local
|
||||
data-id: common-local.yaml
|
||||
@@ -1,12 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
containerId=$(docker ps | grep octopus-agent | awk '{print$1}')
|
||||
|
||||
docker container stop $(containerId) && docker container rm $(containerId)
|
||||
|
||||
echo "y
|
||||
" | docker container prune
|
||||
|
||||
docker image rmi octopus-agent-ubuntu:latest -y
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
##### environment variables ######
|
||||
|
||||
RepoSourcePath=https://raw.githubusercontent.com/zeaslity/ProjectOctopus/main/source/src/main/java/io/wdd/source/shell
|
||||
|
||||
JAVA_OPTS="-Xms128m -Xmx512m -Dfile.encoding=utf-8 --spring.profiles.active=k3s --spring.cloud.nacos.config.group=k3s --spring.cloud.nacos.config.extension-configs[0].dataId=common-k3s.yaml --spring.cloud.nacos.config.extension-configs[0].group=k3s"
|
||||
|
||||
DependLibFiles=(
|
||||
wdd-lib-file.sh
|
||||
wdd-lib-log.sh
|
||||
@@ -11,6 +13,10 @@ DependLibFiles=(
|
||||
wdd-lib-sys.sh
|
||||
)
|
||||
|
||||
|
||||
OctopusAgentUrl=https://happybirthday.107421.xyz/octopus-agent/
|
||||
|
||||
RepoSourcePath=https://raw.githubusercontent.com/zeaslity/ProjectOctopus/main/source/src/main/java/io/wdd/source/shell
|
||||
OctopusAgentPath=/octopus-agent/shell
|
||||
##### environment variables ######
|
||||
|
||||
@@ -186,20 +192,30 @@ DownloadAllFile() {
|
||||
|
||||
FunctionStart
|
||||
|
||||
colorEcho $RED "[CLEAN_UP] clean the old octopus agent staff !"
|
||||
rm -rf $OctopusAgentPath/lib
|
||||
rm -rf $OctopusAgentPath/
|
||||
|
||||
mkdir -p $OctopusAgentPath
|
||||
mkdir -p $OctopusAgentPath/lib
|
||||
|
||||
echo "start to download all needed lib shell"
|
||||
for libfile in ${DependLibFiles[*]}; do
|
||||
echo "lib file is $libfile"
|
||||
wget "$RepoSourcePath/lib/$libfile" -O $OctopusAgentPath/lib/$libfile
|
||||
|
||||
colorEcho $BLUE "lib file is $libfile"
|
||||
wget "$RepoSourcePath/lib/$libfile" -Oq $OctopusAgentPath/lib/$libfile
|
||||
FunctionSuccess
|
||||
|
||||
done
|
||||
|
||||
colorEcho $BLUE "start to download octopus agent !"
|
||||
# check for latest version
|
||||
# download the lasted jar
|
||||
wget https://happybirthday.107421.xyz/octopus-agent/octopus-agent-2022-12-21-16-00-00.jar -O /octopus-agent/agent.jar
|
||||
cd $OctopusAgentPath
|
||||
colorEcho $BLUE "start to load wdd-lib-os.sh"
|
||||
. ./lib/wdd-lib-os.sh
|
||||
CheckAndDownloadLatestVersion
|
||||
|
||||
|
||||
FunctionSuccess
|
||||
FunctionEnd
|
||||
@@ -265,28 +281,38 @@ InstallJDKPackage() {
|
||||
}
|
||||
|
||||
systemdAgent(){
|
||||
local JAVA_OPTS="-Xms128m -Xmx256m"
|
||||
|
||||
# https://www.baeldung.com/linux/run-java-application-as-service
|
||||
|
||||
cat >/etc/systemd/system/octopus-agent.service <<EOF
|
||||
[Unit]
|
||||
Description=Octopus Agent
|
||||
Description=Octopus Agent Service
|
||||
Documentation=https://octopus.107421.xyz/
|
||||
After=network.target
|
||||
After=syslog.target network.target
|
||||
|
||||
[Service]
|
||||
PermissionsStartOnly=true
|
||||
LimitNOFILE=1048576
|
||||
LimitNPROC=65535
|
||||
SuccessExitStatus=143
|
||||
SyslogIdentifier=octopus-agent
|
||||
User=root
|
||||
Type=simple
|
||||
WorkingDirectory=/octopus-agent
|
||||
EnvironmentFile=/etc/environment.d/octopus-agent.conf
|
||||
ExecStart=java -jar /octopus-agent/agent.jar ${JAVA_OPTS}
|
||||
ExecReload=source /etc/environment
|
||||
Restart=on-failure
|
||||
ExecStop=/bin/kill -15 \$MAINPID
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# https://www.benzhu.xyz/linux12/
|
||||
cat >/etc/rsyslog.d/octopus-agent.conf <<EOF
|
||||
if \$programname == 'octopus-agent' then /var/log/octopus-agent.log
|
||||
& stop
|
||||
EOF
|
||||
|
||||
rsyslogd -N1 -f /etc/rsyslog.d/octopus-agent.conf
|
||||
|
||||
systemctl restart rsyslog
|
||||
}
|
||||
|
||||
## 为了本脚本能够满足Ubuntu系统,做出设当的更改
|
||||
@@ -326,10 +352,125 @@ BootUPAgent(){
|
||||
systemctl enable octopus-agent.service
|
||||
systemctl start octopus-agent.service
|
||||
|
||||
#
|
||||
# systemctl restart octopus-agent.service
|
||||
# systemctl status octopus-agent.service -l
|
||||
#tail -f 500 /var/log/octopus-agent.log
|
||||
|
||||
FunctionSuccess
|
||||
FunctionEnd
|
||||
}
|
||||
|
||||
|
||||
InstallZSH() {
|
||||
FunctionStart
|
||||
|
||||
ZSH_SOURCE="us"
|
||||
|
||||
if [[ "$1" -ne " " ]]; then
|
||||
ZSH_SOURCE="$1"
|
||||
echo "zsh install source = ${ZSH_SOURCE}"
|
||||
fi
|
||||
|
||||
colorEcho ${BLUE} "开始安装宇宙第一shell工具zsh……"
|
||||
echo ""
|
||||
installDemandSoftwares zsh git || return $?
|
||||
# 脚本会自动更换默认的shell
|
||||
if [[ "${ZSH_SOURCE}" -eq "cn" ]]; then
|
||||
echo y | REMOTE=https://gitee.com/mirrors/oh-my-zsh.git sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"
|
||||
else
|
||||
echo y | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
||||
fi
|
||||
#echo y | sh -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/robbyrussell/oh-my-zsh@master/tools/install.sh)"
|
||||
echo ""
|
||||
modifyZSH ${ZSH_SOURCE}
|
||||
if [[ $? -eq 0 ]]; then
|
||||
colorEcho ${BLUE} "开始修改默认shell为zsh……"
|
||||
for i in {6..1..-1}; do
|
||||
colorEcho ${BLUE} "倒计时开始 ->> $i 秒 <<-,准备切换shell,上文的日志输出将会消失!!"
|
||||
sleep 2
|
||||
done
|
||||
chsh -s /bin/zsh
|
||||
zsh
|
||||
else
|
||||
colorEcho ${RED} "zsh 安装失败,大概率是已经安装!!小概率是无法连接GitHub服务器~~"
|
||||
fi
|
||||
FunctionEnd
|
||||
}
|
||||
|
||||
modifyZSH() {
|
||||
FunctionStart
|
||||
|
||||
ZSH_SOURCE="us"
|
||||
|
||||
if [[ "$1" -ne " " ]]; then
|
||||
ZSH_SOURCE="$1"
|
||||
echo "zsh install source = ${ZSH_SOURCE}"
|
||||
fi
|
||||
|
||||
colorEcho ${GREEN} "zsh应该已经安装成功!!!"
|
||||
colorEcho ${BLUE} "开始修改zsh的相关配置信息,使其更加好用…………"
|
||||
echo ""
|
||||
cat >~/oh-my-zsh-plugins-list.txt <<EOF
|
||||
https://cdn.jsdelivr.net/gh/ohmyzsh/ohmyzsh/plugins/command-not-found/command-not-found.plugin.zsh
|
||||
https://cdn.jsdelivr.net/gh/ohmyzsh/ohmyzsh/plugins/autojump/autojump.plugin.zsh
|
||||
https://cdn.jsdelivr.net/gh/ohmyzsh/ohmyzsh/plugins/themes/themes.plugin.zsh
|
||||
EOF
|
||||
colorEcho ${BLUE} "正在下载zsh的一些好用的插件:"
|
||||
echo ""
|
||||
|
||||
if [[ "${ZSH_SOURCE}" -eq "cn" ]]; then
|
||||
colorEcho ${BLUE} "开始从 Gitee 下载 自动补全 插件…………"
|
||||
git clone https://gitee.com/githubClone/zsh-autosuggestions.git ~/.oh-my-zsh/plugins/zsh-autosuggestions
|
||||
else
|
||||
colorEcho ${BLUE} "开始从 GitHub 下载 自动补全 插件…………"
|
||||
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/plugins/zsh-autosuggestions
|
||||
fi
|
||||
FunctionSuccess
|
||||
|
||||
if [[ "${ZSH_SOURCE}" -eq "cn" ]]; then
|
||||
colorEcho ${BLUE} "开始从 Gitee 下载 命令高亮 插件…………"
|
||||
git clone https://gitee.com/mo2/zsh-syntax-highlighting.git ~/.oh-my-zsh/plugins/zsh-syntax-highlighting
|
||||
else
|
||||
colorEcho ${BLUE} "开始从 GitHub 下载 命令高亮 插件…………"
|
||||
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/plugins/zsh-syntax-highlighting
|
||||
fi
|
||||
FunctionSuccess
|
||||
|
||||
colorEcho ${BLUE} "开始从JSDeliver下载插件…………"
|
||||
wget -c -i ~/oh-my-zsh-plugins-list.txt -P ~/.oh-my-zsh/plugins/
|
||||
FunctionSuccess
|
||||
|
||||
colorEcho ${GREEN} "插件已经下载完毕,现在开始修改zsh的配置文件…………"
|
||||
echo ""
|
||||
colorEcho ${BLUE} "开始修改zsh的主题为 agnoster !!"
|
||||
sed -i "s/robbyrussell/agnoster/g" ~/.zshrc
|
||||
sed -i 's/^# DISABLE_AUTO_UPDATE="true"/DISABLE_AUTO_UPDATE="true"/g' ~/.zshrc
|
||||
sed -i 's/plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting command-not-found z themes)/g' ~/.zshrc
|
||||
echo ""
|
||||
colorEcho ${GREEN} "请检查当前zsh的插件开启情况:"
|
||||
colorEcho ${GREEN} "------------------------------------------"
|
||||
cat ~/.zshrc | grep "plugins=" | grep -v "\#"
|
||||
cat ~/.zshrc | grep "plugins=" | grep -v "\#"
|
||||
cat ~/.zshrc | grep "plugins=" | grep -v "\#"
|
||||
colorEcho ${GREEN} "------------------------------------------"
|
||||
|
||||
echo ""
|
||||
echo "----------------------------------------------------"
|
||||
echo "这里的错误输出无需在意"
|
||||
source /root/.zshrc
|
||||
echo "这里的错误输出无需在意"
|
||||
echo "----------------------------------------------------"
|
||||
echo ""
|
||||
colorEcho ${GREEN} "zsh 安装成功,已更换主题,禁止更新,尽情享用~~~"
|
||||
FunctionSuccess
|
||||
colorEcho ${PURPLE} "宇宙第一shell的zsh已经安装成功了!!!"
|
||||
colorEcho ${GREEN} "宇宙第一shell的zsh已经安装成功了!!!"
|
||||
colorEcho ${BLUE} "宇宙第一shell的zsh已经安装成功了!!!"
|
||||
FunctionSuccess
|
||||
}
|
||||
|
||||
|
||||
main(){
|
||||
|
||||
check_root
|
||||
@@ -343,6 +484,8 @@ main(){
|
||||
|
||||
DownloadAllFile
|
||||
|
||||
InstallZSH "us"
|
||||
|
||||
BootUPAgent
|
||||
|
||||
}
|
||||
|
||||
26
source/src/main/java/io/wdd/source/shell/agent-restart.sh
Normal file
26
source/src/main/java/io/wdd/source/shell/agent-restart.sh
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
. /octopus-agent/shell/lib/wdd-lib-log.sh
|
||||
. /octopus-agent/shell/lib/wdd-lib-sys.sh
|
||||
|
||||
|
||||
log "[Octopus Agent Restart !]"
|
||||
|
||||
FunctionStart
|
||||
|
||||
log "prepare the env"
|
||||
chmod +x /octopus-agent/shell/lib/wdd-lib-env.sh
|
||||
|
||||
/octopus-agent/shell/lib/wdd-lib-env.sh
|
||||
systemctl stop octopus-agent.service
|
||||
log "sleep for 5s waiting for agent shutdown !"
|
||||
sleep 5
|
||||
|
||||
log "restart octopus agent ! $(date)"
|
||||
systemctl start octopus-agent.service
|
||||
|
||||
FunctionSuccess
|
||||
FunctionEnd
|
||||
|
||||
|
||||
23
source/src/main/java/io/wdd/source/shell/agent-update.sh
Normal file
23
source/src/main/java/io/wdd/source/shell/agent-update.sh
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
. /octopus-agent/shell/lib/wdd-lib-log.sh
|
||||
. /octopus-agent/shell/lib/wdd-lib-sys.sh
|
||||
. /octopus-agent/shell/lib/wdd-lib-os.sh
|
||||
|
||||
|
||||
RepoSourcePath=https://raw.githubusercontent.com/zeaslity/ProjectOctopus/main/source/src/main/java/io/wdd/source/shell
|
||||
|
||||
|
||||
CheckAndDownloadLatestVersion
|
||||
|
||||
if [[ ! -f /octopus-agent/shell/agent-reboot.sh ]]; then\
|
||||
warn "agent-bootup.sh not exist! start to download !"
|
||||
cd /octopus-agent/shell
|
||||
wget $RepoSourcePath/agent-reboot.sh
|
||||
fi
|
||||
|
||||
|
||||
log "start to reboot the octopus agent !"
|
||||
chmod +x /octopus-agent/shell/agent-reboot.sh
|
||||
/octopus-agent/shell/agent-reboot.sh
|
||||
@@ -1,11 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
#. /octopus-agent/shell/lib/wdd-lib-log.sh
|
||||
#. /octopus-agent/shell/lib/wdd-lib-sys.sh
|
||||
. /octopus-agent/shell/lib/wdd-lib-log.sh
|
||||
. /octopus-agent/shell/lib/wdd-lib-sys.sh
|
||||
|
||||
. ./wdd-lib-log.sh
|
||||
. ./wdd-lib-sys.sh
|
||||
#. .wdd-lib-log.sh
|
||||
#. .wdd-lib-sys.sh
|
||||
|
||||
|
||||
hostArchVersion=""
|
||||
@@ -262,27 +262,27 @@ if [[ $(cat /etc/hostname | cut -d"-" -f 3 | grep -c '^[0-9][0-9]') -gt 0 ]]; th
|
||||
else
|
||||
machineNumber=99
|
||||
fi
|
||||
cat >>/etc/environment<<EOF
|
||||
export serverName="${city}-${hostArch}-${machineNumber}"
|
||||
export serverIpPbV4="$public_ipv4"
|
||||
export serverIpInV4=""
|
||||
export serverIpPbV6=""
|
||||
export serverIpInV6=""
|
||||
export location="$city $region $country"
|
||||
export provider="$org"
|
||||
export managePort="$(netstat -ntulp | grep sshd | grep -w tcp | awk '{print$4}' | cut -d":" -f2)"
|
||||
export cpuCore="$cores @ $freq MHz"
|
||||
export cpuBrand="$cpuName"
|
||||
export memoryTotal="$tram"
|
||||
export diskTotal="$disk_total_size"
|
||||
export diskUsage="$disk_used_size"
|
||||
export archInfo="$arch ($lbit Bit)"
|
||||
export osInfo="$opsy"
|
||||
export osKernelInfo="$kern"
|
||||
export tcpControl="$tcpctrl"
|
||||
export virtualization="$virt"
|
||||
export ioSpeed="$ioavg MB/s"
|
||||
export machineId="$(cat /etc/machine-id)"
|
||||
cat >/etc/environment.d/octopus-agent.conf<<EOF
|
||||
serverName=${city}-${hostArch}-${machineNumber}
|
||||
serverIpPbV4=$public_ipv4
|
||||
serverIpInV4=
|
||||
serverIpPbV6=
|
||||
serverIpInV6=
|
||||
location="$city $region $country"
|
||||
provider=$org
|
||||
managePort=$(netstat -ntulp | grep sshd | grep -w tcp | awk '{print$4}' | cut -d":" -f2)
|
||||
cpuCore="$cores @ $freq MHz"
|
||||
cpuBrand="$cpuName"
|
||||
memoryTotal=$tram
|
||||
diskTotal=$disk_total_size
|
||||
diskUsage=$disk_used_size
|
||||
archInfo="$arch ($lbit Bit)"
|
||||
osInfo="$opsy"
|
||||
osKernelInfo=$kern
|
||||
tcpControl=$tcpctrl
|
||||
virtualization=$virt
|
||||
ioSpeed="$ioavg MB/s"
|
||||
machineId=$(cat /etc/machine-id)
|
||||
EOF
|
||||
|
||||
log "env collect complete!"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
# Load Generic Libraries
|
||||
. /octopus-agent/shell/lib/wdd-lib-log.sh
|
||||
. /octopus-agent/shell/lib/wdd-lib-log.shwdd-lib-log.sh
|
||||
|
||||
# Functions
|
||||
|
||||
|
||||
@@ -1,112 +1,30 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Library for logging functions
|
||||
|
||||
# Constants
|
||||
RESET='\033[0m'
|
||||
RED='\033[38;5;1m'
|
||||
GREEN='\033[38;5;2m'
|
||||
YELLOW='\033[38;5;3m'
|
||||
MAGENTA='\033[38;5;5m'
|
||||
CYAN='\033[38;5;6m'
|
||||
|
||||
# Functions
|
||||
. /octopus-agent/shell/lib/wdd-lib-log.sh
|
||||
|
||||
########################
|
||||
# Print to STDERR
|
||||
# Arguments:
|
||||
# Message to print
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
stderr_print() {
|
||||
# 'is_boolean_yes' is defined in libvalidations.sh, but depends on this file so we cannot source it
|
||||
local bool="${BITNAMI_QUIET:-false}"
|
||||
# comparison is performed without regard to the case of alphabetic characters
|
||||
shopt -s nocasematch
|
||||
if ! [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]]; then
|
||||
printf "%b\\n" "${*}" >&2
|
||||
fi
|
||||
}
|
||||
OctopusAgentUrl=https://happybirthday.107421.xyz/octopus-agent/
|
||||
|
||||
########################
|
||||
# Log message
|
||||
# Arguments:
|
||||
# Message to log
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
log() {
|
||||
stderr_print "${CYAN}${MODULE:-} ${MAGENTA}$(date "+%Y-%m-%d %H:%M:%S.%2N ")${RESET}${*}"
|
||||
}
|
||||
########################
|
||||
# Log an 'info' message
|
||||
# Arguments:
|
||||
# Message to log
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
info() {
|
||||
log "${GREEN}INFO ${RESET} ==> ${*}"
|
||||
}
|
||||
########################
|
||||
# Log message
|
||||
# Arguments:
|
||||
# Message to log
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
warn() {
|
||||
log "${YELLOW}WARN ${RESET} ==> ${*}"
|
||||
}
|
||||
########################
|
||||
# Log an 'error' message
|
||||
# Arguments:
|
||||
# Message to log
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
error() {
|
||||
log "${RED}ERROR${RESET} ==> ${*}"
|
||||
}
|
||||
########################
|
||||
# Log a 'debug' message
|
||||
# Globals:
|
||||
# BITNAMI_DEBUG
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
debug() {
|
||||
# 'is_boolean_yes' is defined in libvalidations.sh, but depends on this file so we cannot source it
|
||||
local bool="${BITNAMI_DEBUG:-true}"
|
||||
# comparison is performed without regard to the case of alphabetic characters
|
||||
shopt -s nocasematch
|
||||
if [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]]; then
|
||||
log "${MAGENTA}DEBUG${RESET} ==> ${*}"
|
||||
fi
|
||||
}
|
||||
|
||||
########################
|
||||
# Indent a string
|
||||
# Arguments:
|
||||
# $1 - string
|
||||
# $2 - number of indentation characters (default: 4)
|
||||
# $3 - indentation character (default: " ")
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
indent() {
|
||||
local string="${1:-}"
|
||||
local num="${2:?missing num}"
|
||||
local char="${3:-" "}"
|
||||
# Build the indentation unit string
|
||||
local indent_unit=""
|
||||
for ((i = 0; i < num; i++)); do
|
||||
indent_unit="${indent_unit}${char}"
|
||||
done
|
||||
# shellcheck disable=SC2001
|
||||
# Complex regex, see https://github.com/koalaman/shellcheck/wiki/SC2001#exceptions
|
||||
echo "$string" | sed "s/^/${indent_unit}/"
|
||||
CheckAndDownloadLatestVersion(){
|
||||
|
||||
log "checking for the latest version"
|
||||
local latestVersion=$(curl $OctopusAgentUrl | grep -v h1 | grep "a href=" | awk '{print$2}' |cut -d">" -f2 | cut -d"<" -f1)
|
||||
|
||||
log "octopus agent latest version is => [ $latestVersion ]"
|
||||
|
||||
rm -rf /octopus-agent/*.jar
|
||||
cd /octopus-agent
|
||||
|
||||
log "start to download the latest version !"
|
||||
|
||||
wget "$OctopusAgentUrl$latestVersion"
|
||||
cp "$latestVersion" agent.jar
|
||||
|
||||
log ""
|
||||
echo ""
|
||||
log "----------------------------------------------"
|
||||
ls /octopus-agent/ | grep jar
|
||||
log "----------------------------------------------"
|
||||
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
. /octopus-agent/shell/lib/wdd-lib-log.sh
|
||||
|
||||
|
||||
|
||||
# 判断命令是否存在
|
||||
command_exists() {
|
||||
command -v "$@" >/dev/null 2>&1
|
||||
@@ -95,23 +92,65 @@ check_sys() {
|
||||
return 0
|
||||
}
|
||||
|
||||
RED="31m" ## 姨妈红
|
||||
GREEN="32m" ## 水鸭青
|
||||
YELLOW="33m" ## 鸭屎黄
|
||||
PURPLE="35m" ## 基佬紫
|
||||
BLUE="36m" ## 天依蓝
|
||||
BlinkGreen="32;5m" ##闪烁的绿色
|
||||
BlinkRed="31;5m" ##闪烁的红色
|
||||
BackRed="41m" ## 背景红色
|
||||
SplitLine="----------------------" #会被sys函数中的方法重写
|
||||
|
||||
######## 颜色函数方法很精妙 ############
|
||||
colorEcho() {
|
||||
echo -e "\033[${1}${@:2}\033[0m" 1>&2
|
||||
}
|
||||
|
||||
check_root() {
|
||||
if [[ $EUID != 0 ]]; then
|
||||
colorEcho ${RED} "当前非root账号(或没有root权限),无法继续操作,请更换root账号!"
|
||||
colorEcho ${YELLOW} "使用sudo -命令获取临时root权限(执行后可能会提示输入root密码)"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
FunctionStart() {
|
||||
colorEcho ${PURPLE} ${SplitLine}
|
||||
colorEcho ${PURPLE} ${SplitLine}
|
||||
echo ""
|
||||
}
|
||||
|
||||
FunctionSuccess() {
|
||||
colorEcho ${GREEN} ${SplitLine}
|
||||
echo ""
|
||||
}
|
||||
|
||||
FunctionEnd() {
|
||||
echo ""
|
||||
colorEcho ${BlinkGreen} ${SplitLine}
|
||||
echo ""
|
||||
echo ""
|
||||
}
|
||||
|
||||
tmp () {
|
||||
|
||||
gcloud compute instances create octopus-agent-2c-4g-1 --project=compact-lacing-371804 --zone=asia-northeast1-b --machine-type=n2d-custom-2-4096 --network-interface=network-tier=PREMIUM,subnet=default --metadata=startup-script=wget\ https://raw.githubusercontent.com/zeaslity/ProjectOctopus/main/source/src/main/java/io/wdd/source/shell/agent-bootup.sh\ \&\&\ chmod\ \+x\ agent-bootup.sh\ \&\&\ /bin/bash\ agent-bootup.sh --can-ip-forward --maintenance-policy=MIGRATE --provisioning-model=STANDARD --service-account=172889627951-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --create-disk=auto-delete=yes,boot=yes,device-name=octopus-agent-2c-4g,image=projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20221213,mode=rw,size=20,type=projects/compact-lacing-371804/zones/us-west4-b/diskTypes/pd-ssd --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any
|
||||
|
||||
|
||||
gcloud compute instances delete octopus-agent-2c-4g-7 --project=compact-lacing-371804 --zone=asia-northeast1-b
|
||||
gcloud compute instances delete tokyo-amd64-03 --project=compact-lacing-371804 --zone=asia-northeast1-b
|
||||
|
||||
|
||||
gcloud compute instances create octopus-agent-2c-4g-7 --project=compact-lacing-371804 --zone=asia-northeast1-b --machine-type=n2d-custom-2-4096 --network-interface=network-tier=PREMIUM,subnet=default --can-ip-forward --maintenance-policy=MIGRATE --provisioning-model=STANDARD --service-account=172889627951-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --create-disk=auto-delete=yes,boot=yes,device-name=octopus-agent-2c-4g,image=projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20221213,mode=rw,size=20,type=projects/compact-lacing-371804/zones/us-west4-b/diskTypes/pd-ssd --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any
|
||||
gcloud compute instances create tokyo-amd64-03 --project=compact-lacing-371804 --zone=asia-northeast1-b --machine-type=n2d-custom-2-4096 --network-interface=network-tier=PREMIUM,subnet=default --can-ip-forward --maintenance-policy=MIGRATE --provisioning-model=STANDARD --service-account=172889627951-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --create-disk=auto-delete=yes,boot=yes,device-name=octopus-agent-2c-4g,image=projects/ubuntu-os-cloud/global/images/ubuntu-2004-focal-v20221213,mode=rw,size=20,type=projects/compact-lacing-371804/zones/us-west4-b/diskTypes/pd-ssd --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any
|
||||
|
||||
gcloud compute ssh --zone "asia-northeast1-b" "octopus-agent-2c-4g-7" --project "compact-lacing-371804"
|
||||
gcloud compute ssh --zone "asia-northeast1-b" "tokyo-amd64-03" --project "compact-lacing-371804"
|
||||
|
||||
|
||||
wget https://raw.githubusercontent.com/zeaslity/ProjectOctopus/main/source/src/main/java/io/wdd/source/shell/agent-bootup.sh && chmod +x agent-bootup.sh && /bin/bash agent-bootup.sh
|
||||
|
||||
apt-cache madison openjdk-11-jdk | head -n 1 | awk '{print$3}'
|
||||
|
||||
java -jar /octopus-agent/agent.jar -Xms128m -Xmx512m -Dfile.encoding=utf-8 --spring.profiles.active=k3s --spring.cloud.nacos.config.group=k3s --spring.cloud.nacos.config.extension-configs[0].dataId=common-k3s.yaml --spring.cloud.nacos.config.extension-configs[0].group=k3s
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user