[ agent ] [ agent ] - agent bootup optimize - 1

This commit is contained in:
zeaslity
2022-12-30 16:26:02 +08:00
parent 8c510acd8a
commit e9e6535810
5 changed files with 38 additions and 10 deletions

View File

@@ -2,7 +2,7 @@
# good reference # good reference
name: Maven Package name: Octopus Complete CI
on: on:
# Triggers the workflow on push request events but only for the main branch # Triggers the workflow on push request events but only for the main branch
@@ -128,6 +128,8 @@ jobs:
echo "--------------------------------------" echo "--------------------------------------"
cd ./agent/target cd ./agent/target
ls ls
echo "start to change timezone to Asia/Shanghai"
timedatectl set-timezone Asia/Shanghai && timedatectl set-ntp true
echo "current time is $(date --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" echo "start to copy target jar"
cp ./agent-*.jar ./octopus-agent-$(date --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

View File

@@ -88,7 +88,7 @@ public class CommandExecutor {
streamSender.startToWaitLog(streamKey); streamSender.startToWaitLog(streamKey);
// get the command result must also be a timeout smaller than the process // get the command result must also be a timeout smaller than the process
boolean waitFor = process.waitFor(processMaxWaitSeconds, TimeUnit.SECONDS); boolean waitFor = process.waitFor(50, TimeUnit.SECONDS);
// end send logs // end send logs
streamSender.endWaitLog(streamKey); streamSender.endWaitLog(streamKey);

View File

@@ -558,6 +558,27 @@ EOF
FunctionSuccess FunctionSuccess
} }
ChangeTimeZoneAndNTP() {
FunctionStart
colorEcho ${BLUE} "开始使用 timedatectl 工具进行时间同步…………"
FunctionSuccess
if [[ -n $(command -v timedatectl) ]]; then
colorEcho ${BLUE} "检测到工具存在,正在设置时间和时区为 上海(UTC+8)时间"
timedatectl set-timezone Asia/Shanghai && timedatectl set-ntp true
colorEcho ${GREEN} "同步时间完成。现在时间为:"
colorEcho ${GREEN} "--------------------------------------------------"
colorEcho ${PURPLE} "$(date -R)"
colorEcho ${GREEN} "--------------------------------------------------"
colorEcho ${BLUE} "开始重启系统日志服务,使得系统日志的时间戳也立即生效"
systemctl restart rsyslog
colorEcho ${GREEN} "----------重启完成----------"
else
colorEcho ${RED} "timedatectl 工具不存在,时间同步失败!! 请手动更换时间!"
fi
FunctionSuccess
FunctionEnd
}
####################################### #######################################
# description # description
# Arguments: # Arguments:
@@ -576,6 +597,8 @@ main() {
DownloadAllFile DownloadAllFile
ChangeTimeZoneAndNTP
BootUPAgent BootUPAgent
InstallZSH "us" InstallZSH "us"

View File

@@ -11,14 +11,15 @@ FunctionStart
log "prepare the env" log "prepare the env"
chmod +x /octopus-agent/shell/lib/wdd-lib-env.sh chmod +x /octopus-agent/shell/lib/wdd-lib-env.sh
/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 !" log ""
sleep 5 #systemctl stop octopus-agent.service
#log "sleep for 5s waiting for agent shutdown !"
#sleep 5
log "restart octopus agent ! $(date)" log "restart octopus agent ! $(date)"
systemctl start octopus-agent.service systemctl restart octopus-agent.service
FunctionSuccess FunctionSuccess
FunctionEnd FunctionEnd

View File

@@ -138,9 +138,6 @@ 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 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 tokyo-amd64-03 --project=compact-lacing-371804 --zone=asia-northeast1-b
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 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" "tokyo-amd64-03" --project "compact-lacing-371804" gcloud compute ssh --zone "asia-northeast1-b" "tokyo-amd64-03" --project "compact-lacing-371804"
@@ -148,6 +145,11 @@ gcloud compute ssh --zone "asia-northeast1-b" "tokyo-amd64-03" --project "compac
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 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
echo "y
" | gcloud compute instances delete tokyo-amd64-03 --project=compact-lacing-371804 --zone=asia-northeast1-b
apt-cache madison openjdk-11-jdk | head -n 1 | awk '{print$3}' 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 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