From 09119ef3012f2453757840c46a605c0bb2d9eaa0 Mon Sep 17 00:00:00 2001 From: zeaslity Date: Wed, 28 Dec 2022 09:51:05 +0800 Subject: [PATCH] [ server ] [ executor ] - optimize code -5 --- .../src/main/resources/application-local.yml | 20 +++++++++++++++++++ server/src/main/resources/bootstrap.yml | 8 ++++---- .../java/io/wdd/source/shell/agent-bootup.sh | 7 ++++--- .../java/io/wdd/source/shell/agent-reboot.sh | 20 ------------------- .../java/io/wdd/source/shell/agent-restart.sh | 20 +++++++++++++++++++ .../java/io/wdd/source/shell/agent-update.sh | 18 ++++++++--------- .../io/wdd/source/shell/lib/wdd-lib-env.sh | 2 +- .../io/wdd/source/shell/lib/wdd-lib-os.sh | 5 ++++- .../io/wdd/source/shell/lib/wdd-lib-sys.sh | 8 +++----- 9 files changed, 64 insertions(+), 44 deletions(-) create mode 100644 server/src/main/resources/application-local.yml delete mode 100644 source/src/main/java/io/wdd/source/shell/agent-reboot.sh create mode 100644 source/src/main/java/io/wdd/source/shell/agent-restart.sh diff --git a/server/src/main/resources/application-local.yml b/server/src/main/resources/application-local.yml new file mode 100644 index 0000000..ef43407 --- /dev/null +++ b/server/src/main/resources/application-local.yml @@ -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 \ No newline at end of file diff --git a/server/src/main/resources/bootstrap.yml b/server/src/main/resources/bootstrap.yml index ef43407..605cba7 100644 --- a/server/src/main/resources/bootstrap.yml +++ b/server/src/main/resources/bootstrap.yml @@ -2,11 +2,11 @@ spring: application: name: octopus-server profiles: - active: local + active: k3s cloud: nacos: config: - group: local + group: k3s config-retry-time: 3000 file-extension: yaml max-retry: 3 @@ -16,5 +16,5 @@ spring: timeout: 5000 config-long-poll-timeout: 5000 extension-configs: - - group: local - data-id: common-local.yaml \ No newline at end of file + - group: k3s + data-id: common-k3s.yaml \ No newline at end of file diff --git a/source/src/main/java/io/wdd/source/shell/agent-bootup.sh b/source/src/main/java/io/wdd/source/shell/agent-bootup.sh index 0caa3ec..08cc715 100644 --- a/source/src/main/java/io/wdd/source/shell/agent-bootup.sh +++ b/source/src/main/java/io/wdd/source/shell/agent-bootup.sh @@ -204,11 +204,12 @@ DownloadAllFile() { colorEcho $BLUE "start to download octopus agent !" # check for latest version # download the lasted jar - cd /optopus-agent - . ./shell/lib/wdd-lib-os.sh - + cd $OctopusAgentPath + colorEcho $BLUE "start to load wdd-lib-os.sh" + . ./lib/wdd-lib-os.sh CheckAndDownloadLatestVersion + FunctionSuccess FunctionEnd diff --git a/source/src/main/java/io/wdd/source/shell/agent-reboot.sh b/source/src/main/java/io/wdd/source/shell/agent-reboot.sh deleted file mode 100644 index a3ef7a1..0000000 --- a/source/src/main/java/io/wdd/source/shell/agent-reboot.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - - -. ./lib/wdd-lib-log.sh -. ./lib/wdd-lib-sys.sh - - -FunctionStart - -log "prepare the env" -chmod +x ./lib/wdd-lib-env.sh -./lib/wdd-lib-env.sh - -systemctl stop octopus-agent.service -systemctl start octopus-agent.service - -FunctionSuccess -FunctionEnd - - diff --git a/source/src/main/java/io/wdd/source/shell/agent-restart.sh b/source/src/main/java/io/wdd/source/shell/agent-restart.sh new file mode 100644 index 0000000..9c0bdbc --- /dev/null +++ b/source/src/main/java/io/wdd/source/shell/agent-restart.sh @@ -0,0 +1,20 @@ +#!/bin/bash + + +. /octopus-agent/shell/lib/wdd-lib-log.sh +. /octopus-agent/shell/lib/wdd-lib-sys.sh + + +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 +systemctl start octopus-agent.service + +FunctionSuccess +FunctionEnd + + diff --git a/source/src/main/java/io/wdd/source/shell/agent-update.sh b/source/src/main/java/io/wdd/source/shell/agent-update.sh index ba92f8b..896b3d5 100644 --- a/source/src/main/java/io/wdd/source/shell/agent-update.sh +++ b/source/src/main/java/io/wdd/source/shell/agent-update.sh @@ -1,25 +1,23 @@ #!/bin/bash -. ./lib/wdd-lib-log.sh -. ./lib/wdd-lib-sys.sh -. ./lib/wdd-lib-os.sh +. /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/agent-reboot.sh ]]; then\ +if [[ ! -f /octopus-agent/shell/agent-reboot.sh ]]; then\ warn "agent-bootup.sh not exist! start to download !" - cd /octopus-agent - wget $RepoSourcePath/agent-reboot.sh + cd /octopus-agent/shell + wget $RepoSourcePath/agent-reboot.sh fi log "start to reboot the octopus agent !" -chmod +x /octopus-agent/agent-reboot.sh -/octopus-agent/agent-reboot.sh +chmod +x /octopus-agent/shell/agent-reboot.sh +/octopus-agent/shell/agent-reboot.sh diff --git a/source/src/main/java/io/wdd/source/shell/lib/wdd-lib-env.sh b/source/src/main/java/io/wdd/source/shell/lib/wdd-lib-env.sh index b0d75b0..314c1a4 100644 --- a/source/src/main/java/io/wdd/source/shell/lib/wdd-lib-env.sh +++ b/source/src/main/java/io/wdd/source/shell/lib/wdd-lib-env.sh @@ -272,7 +272,7 @@ 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 cpuBrand="$cpuName" export memoryTotal=$tram export diskTotal=$disk_total_size export diskUsage=$disk_used_size diff --git a/source/src/main/java/io/wdd/source/shell/lib/wdd-lib-os.sh b/source/src/main/java/io/wdd/source/shell/lib/wdd-lib-os.sh index 29b594e..84d44b7 100644 --- a/source/src/main/java/io/wdd/source/shell/lib/wdd-lib-os.sh +++ b/source/src/main/java/io/wdd/source/shell/lib/wdd-lib-os.sh @@ -19,9 +19,12 @@ CheckAndDownloadLatestVersion(){ log "start to download the latest version !" wget "$OctopusAgentUrl$latestVersion" - cp "$OctopusAgentUrl$latestVersion" agent.jar + cp "$latestVersion" agent.jar log "" + echo "" + log "----------------------------------------------" ls /octopus-agent/ | grep jar + log "----------------------------------------------" } \ No newline at end of file diff --git a/source/src/main/java/io/wdd/source/shell/lib/wdd-lib-sys.sh b/source/src/main/java/io/wdd/source/shell/lib/wdd-lib-sys.sh index 6c3db52..43cd23c 100644 --- a/source/src/main/java/io/wdd/source/shell/lib/wdd-lib-sys.sh +++ b/source/src/main/java/io/wdd/source/shell/lib/wdd-lib-sys.sh @@ -1,7 +1,5 @@ #!/bin/bash - - . /octopus-agent/shell/lib/wdd-lib-log.sh @@ -140,12 +138,12 @@ 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