From 57617ebd54f561efbb17c70ba3cefbc01ec3cf0d Mon Sep 17 00:00:00 2001 From: Yarden Asado Date: Tue, 2 Apr 2024 15:08:10 -0400 Subject: [PATCH] try the pre nnd rotate scripts --- github.sh | 28 ++++----- pre_install_gh.sh.tpl | 75 +++++++++++------------ rotate_version_gh.sh.tpl | 124 +++++++++++++++++++-------------------- 3 files changed, 109 insertions(+), 118 deletions(-) diff --git a/github.sh b/github.sh index d8986a532749..0597cf68f281 100755 --- a/github.sh +++ b/github.sh @@ -92,17 +92,17 @@ parallel-ssh \ --send-input < ./rotate_version.sh hr -### Update the version marker file -#echo "Mark which RC build is now active..." -#current_marker_file="rocket.chat-$environment.tgz" -#aws s3 cp "s3://$s3_bucket/$rc_tarball" "s3://$s3_bucket/$current_marker_file" --acl public-read -#hr -# -### Flush CDN -#echo "Flushing $environment CDN" -#unset AWS_SESSION_TOKEN -#unset AWS_ACCESS_KEY_ID -#unset AWS_SECRET_ACCESS_KEY -#FASTLY_SERVICE=$(aws ssm get-parameter --name /rocketchat/fastly_service_id --with-decryption --query Parameter.Value --output text) -#FASTLY_TOKEN=$(aws ssm get-parameter --name /rocketchat/fastly_api_key --with-decryption --query Parameter.Value --output text) -#curl -X POST -H "Fastly-Key: $FASTLY_TOKEN" "https://api.fastly.com/service/$FASTLY_SERVICE/purge/$environment" +## Update the version marker file +echo "Mark which RC build is now active..." +current_marker_file="rocket.chat-$environment.tgz" +aws s3 cp "s3://$s3_bucket/$rc_tarball" "s3://$s3_bucket/$current_marker_file" --acl public-read +hr + +## Flush CDN +echo "Flushing $environment CDN" +unset AWS_SESSION_TOKEN +unset AWS_ACCESS_KEY_ID +unset AWS_SECRET_ACCESS_KEY +FASTLY_SERVICE=$(aws ssm get-parameter --name /rocketchat/fastly_service_id --with-decryption --query Parameter.Value --output text) +FASTLY_TOKEN=$(aws ssm get-parameter --name /rocketchat/fastly_api_key --with-decryption --query Parameter.Value --output text) +curl -X POST -H "Fastly-Key: $FASTLY_TOKEN" "https://api.fastly.com/service/$FASTLY_SERVICE/purge/$environment" diff --git a/pre_install_gh.sh.tpl b/pre_install_gh.sh.tpl index 6b7fc921a9f9..cb23fd466048 100644 --- a/pre_install_gh.sh.tpl +++ b/pre_install_gh.sh.tpl @@ -1,46 +1,41 @@ #!/bin/bash +AWS="/usr/local/bin/aws" +AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION_ENVSUBST +RC_DIR=$RC_DIR_ENVSUBST +RC_FILE=$RC_TARBALL_ENVSUBST +S3_BUCKET=$S3_BUCKET_ENVSUBST + set -e -echo "run pre" +# Clean old RC dirs and create new +prepare_directories () { + echo "Removing previous release's directories..." + sudo rm -rf $RC_DIR-{new,old} + sudo mkdir -p $RC_DIR-new +} +# Download given RocketChat build +build_rc () { + local s3_path + s3_path="s3://$S3_BUCKET/$RC_FILE" + tmprcdir=$(mktemp -d) + cd $tmprcdir + echo "Downloading Rocket.Chat installation files.." + $AWS s3 cp --quiet "$s3_path" . + echo "Unpacking Rocket.Chat files..." + tar zxf "$RC_FILE" + rm -f "$RC_FILE" + echo "Installing modules..." + # loglevels (high to low): error, warn, notice, http, timing, info, verbose, silly + # default = notice + # To disable logging, set loglevel to `silent` + # However, even with `silent` the "package_name@version install_folder" lines are still shown + npm_config_loglevel=warn npm install --production --prefix ./bundle/programs/server + echo "Copying to the new location..." + sudo mv ./bundle $RC_DIR-new/ + rm -rf $tmprcdir +} -#AWS="/usr/local/bin/aws" -#AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION_ENVSUBST -#RC_DIR=$RC_DIR_ENVSUBST -#RC_FILE=$RC_TARBALL_ENVSUBST -#S3_BUCKET=$S3_BUCKET_ENVSUBST -# -#set -e -# -## Clean old RC dirs and create new -#prepare_directories () { -# echo "Removing previous release's directories..." -# sudo rm -rf $RC_DIR-{new,old} -# sudo mkdir -p $RC_DIR-new -#} -# -## Download given RocketChat build -#build_rc () { -# local s3_path -# s3_path="s3://$S3_BUCKET/$RC_FILE" -# tmprcdir=$(mktemp -d) -# cd $tmprcdir -# echo "Downloading Rocket.Chat installation files.." -# $AWS s3 cp --quiet "$s3_path" . -# echo "Unpacking Rocket.Chat files..." -# tar zxf "$RC_FILE" -# rm -f "$RC_FILE" -# echo "Installing modules..." -# # loglevels (high to low): error, warn, notice, http, timing, info, verbose, silly -# # default = notice -# # To disable logging, set loglevel to `silent` -# # However, even with `silent` the "package_name@version install_folder" lines are still shown -# npm_config_loglevel=warn npm install --production --prefix ./bundle/programs/server -# echo "Copying to the new location..." -# sudo mv ./bundle $RC_DIR-new/ -# rm -rf $tmprcdir -#} -# -#prepare_directories -#build_rc +prepare_directories +build_rc diff --git a/rotate_version_gh.sh.tpl b/rotate_version_gh.sh.tpl index 84171fdc6150..dba44d01d830 100644 --- a/rotate_version_gh.sh.tpl +++ b/rotate_version_gh.sh.tpl @@ -1,69 +1,65 @@ #!/bin/bash +RC_DIR=$RC_DIR_ENVSUBST + set -e -echo "run rotate" +# Find Rocket.Chat service names +find_rocket () { + find /etc/systemd/system/multi-user.target.wants/ -maxdepth 1 -type l -name 'rocket*' -printf '%f\n' +} + +# activate command on Rocket.Chat +systemctl_rocket () { + find_rocket | xargs --no-run-if-empty sudo systemctl "$@" +} + +stop_rc () { + echo "Stopping service..." + systemctl_rocket stop + echo "Waiting for service to stop..." + for service in $(find_rocket) + do + until [ "$(systemctl show $service -p ActiveState)" = "ActiveState=inactive" ] + do + printf '.' + sleep 2 + done + done +} + +start_rocket_and_wait_for_response () { + echo "Starting service..." + systemctl_rocket start + echo "Waiting 1 minute for service to start..." + timeout=60 + until $(curl --output /dev/null --silent --head --fail http://localhost) + do + if [ "$timeout" = "0" ] + then + echo -e "\nWaiting timed out - Rocket.Chat not responding yet" + exit 1 + fi + printf '.' + timeout=$((timeout - 2)) + sleep 2 + done +} + +# Switch previous version with current +update_rc () { + stop_rc + echo "Switching versions..." + sudo mv $RC_DIR{,-old} + sudo mv $RC_DIR{-new,} + start_rocket_and_wait_for_response +} + +# Delete previous version +cleanup () { + echo "Cleaning up old directories..." + sudo rm -rf $RC_DIR-old +} -#RC_DIR=$RC_DIR_ENVSUBST -# -#set -e -# -## Find Rocket.Chat service names -#find_rocket () { -# find /etc/systemd/system/multi-user.target.wants/ -maxdepth 1 -type l -name 'rocket*' -printf '%f\n' -#} -# -## activate command on Rocket.Chat -#systemctl_rocket () { -# find_rocket | xargs --no-run-if-empty sudo systemctl "$@" -#} -# -#stop_rc () { -# echo "Stopping service..." -# systemctl_rocket stop -# echo "Waiting for service to stop..." -# for service in $(find_rocket) -# do -# until [ "$(systemctl show $service -p ActiveState)" = "ActiveState=inactive" ] -# do -# printf '.' -# sleep 2 -# done -# done -#} -# -#start_rocket_and_wait_for_response () { -# echo "Starting service..." -# systemctl_rocket start -# echo "Waiting 1 minute for service to start..." -# timeout=60 -# until $(curl --output /dev/null --silent --head --fail http://localhost) -# do -# if [ "$timeout" = "0" ] -# then -# echo -e "\nWaiting timed out - Rocket.Chat not responding yet" -# exit 1 -# fi -# printf '.' -# timeout=$((timeout - 2)) -# sleep 2 -# done -#} -# -## Switch previous version with current -#update_rc () { -# stop_rc -# echo "Switching versions..." -# sudo mv $RC_DIR{,-old} -# sudo mv $RC_DIR{-new,} -# start_rocket_and_wait_for_response -#} -# -## Delete previous version -#cleanup () { -# echo "Cleaning up old directories..." -# sudo rm -rf $RC_DIR-old -#} -# -#update_rc -#cleanup +update_rc +cleanup