Thorn Tech Marketing Ad
Skip to main content
Version: 1.1.0

Running the In-Place Upgrade Script

Overview

This article goes over how to run the in-place upgrade script to upgrade to version 1.001.00 of StorageLink.

Important Mentions

Make a new Backup File

Our recommended approach for upgrading to a new version of StorageLink is to spin up a new StorageLink instance and import your Users & Settings into the new instance using a Backup file. You can export a new Backup file under Settings ---> Backup & Recovery ---> Export Backup File. For more information on our recommended upgrade process, check out this article.

We've created this script for user conveniance, but the safest approach would be the method mentioned above. Before running the script, we would highly recommend creating a new Backup File containing your Users & Settings.

LetsEncrypt

Additionally, if you used LetsEncrypt to create an SSL cert, make sure to edit the new website.conf file to include your hostname, as the script will install a new website.conf file during the upgrade. The new website.conf file is located at these locations depending on your Cloud Provider.

Azure & Google Cloud:

/etc/nginx/sites-available/website.conf

AWS:

/etc/nginx/conf.d/website.conf

Check out the Troubleshooting section of the LetsEncrypt article to see what the website.conf file should look like for you.

Memory Settings

The script also adds a new StorageLink configuration file, which controls the Memory Settings for the StorageLink application. The conf file is located at:

/opt/swiftgw/swiftgateway-1.1.0.conf

By default, the configuration file is set to use the Memory Settings for a VM that has 8GB of RAM. If your VM has more or less than 8GB of RAM, make sure to edit your conf file to reflect your VM size.

You can use this article to find out the correct Memory values for your VM size.

Troubleshooting

If you run the script and you become stuck at the Please wait while StorageLink finishes setting up loading screen, contact us at support@thorntech.com and send us the most recent application log (Date is included in the name):

/opt/swiftgw/log/application-2024-05-1.log

Running the Script

SSH into the VM and run this command to elevate your privileges:

sudo su

If you have run the in-place upgrade script before, make sure you're in a different directory than where you previously ran it. You can run this command to create a new directory and move into it:

mkdir 110-upgrade
cd 110-upgrade

Next, run a wget command to download the script:

wget https://thorntech-products.s3.amazonaws.com/storagelink/1.001.00/in-place-upgrade-storagelink.sh

Give the script execute permissions:

chmod +x in-place-upgrade-storagelink.sh
info

You only need to run the apt-get update command if you're on Azure or Google Cloud (OS = Ubuntu). If you're on AWS (OS = AL2023), you can skip this step.

Update the available packages since we're installing Java 17:

apt-get update

Finally, run the script:

./in-place-upgrade-storagelink.sh

When you refresh your Web Admin UI you should now see an updated UI and version at the bottom.

Script Contents

Here are the contents of the script for reference:

#!/bin/bash

#
# Preparation
#

# Show debug output, and halt on errors
set -xe

# Must run script as root, or else show usage
if [[ $(whoami) != "root" ]]; then
echo "Usage: sudo $0"
exit 1
fi

function extractPropValueFromSourceFile {
local prefix="${1}"
local str=`grep "${prefix}" ${2} 2>/dev/null`
echo "${str#$prefix}" | xargs
}

# Set target version
TARGET_VERSION="1.1.0"
TARGET_VERBOSE_VERSION="1.001.00"

# Set date
TODAY=$(date +"%m%d%Y")

APPLICATION_PROPERTIES="/opt/swiftgw/application.properties"

# Determine the cloud provider
AWS_DOMAIN=$(curl -s "http://169.254.169.254/latest/meta-data/services/domain")
AZURE_DOMAIN=$(curl --noproxy "*" -H 'Metadata: True' "http://169.254.169.254/metadata/instance/compute/azEnvironment?api-version=2019-06-01&format=text")
CLOUD_PROVIDER=gcp
[[ $AWS_DOMAIN == "amazonaws.com" ]] && CLOUD_PROVIDER=aws
[[ $AZURE_DOMAIN == "AzurePublicCloud" ]] && CLOUD_PROVIDER=azure

# Determine operating system and Nginx user
if getent passwd www-data > /dev/null 2>&1; then
OS=ubuntu
NGINX_USER=www-data
NGINX_CONF_PATH="/etc/nginx/sites-available"
else
OS=centos
NGINX_USER=nginx
NGINX_CONF_PATH="/etc/nginx/conf.d"
fi

if [ $OS == ubuntu ]; then
apt-cache search openjdk-17-jre-headless
DEBIAN_FRONTEND=noninteractive apt-get install openjdk-17-jre-headless -y -q
else
yum install -y java-17-amazon-corretto
/usr/sbin/update-alternatives --set java /usr/lib/jvm/java-17-amazon-corretto.x86_64/bin/java
fi

#
# Install SFTP Gateway files
#

# Download public resources
wget https://thorntech-products.s3.amazonaws.com/storagelink/${TARGET_VERBOSE_VERSION}/assets.zip
unzip assets.zip

# Install Java files

# jar
cd assets
chmod +x swiftgateway-${TARGET_VERSION}.jar
chown swiftgw:swiftgw swiftgateway-${TARGET_VERSION}.jar
mv swiftgateway-${TARGET_VERSION}.jar /opt/swiftgw/

# conf
chown swiftgw:swiftgw swiftgateway-${TARGET_VERSION}.conf
mv swiftgateway-${TARGET_VERSION}.conf /opt/swiftgw/

# Install website files
mv admin-ui.tar.gz /usr/share/nginx
cd /usr/share/nginx
mv admin-ui admin-ui-${TODAY}
tar xzvpf admin-ui.tar.gz && rm -f $_
chown -R ${NGINX_USER}:${NGINX_USER} admin-ui

# Populate the application properties file
CLIENT_ID=$(extractPropValueFromSourceFile "security.client-id=" ${APPLICATION_PROPERTIES})
CLIENT_SECRET=$(extractPropValueFromSourceFile "security.client-secret=" ${APPLICATION_PROPERTIES})
(
cat <<EOF
window._env_ = {
"clientid": "$CLIENT_ID",
"clientsecret": "$CLIENT_SECRET",
"cloudProvider": "$CLOUD_PROVIDER",
"version": "$TARGET_VERSION"
};
EOF
) | sudo tee /usr/share/nginx/admin-ui/webconfig.js
cd admin-ui
chown -R ${NGINX_USER}:${NGINX_USER} webconfig.js

# Update the version
service swiftgateway stop
cd /etc/systemd/system/
cp -a swiftgateway.service swiftgateway.service-${TODAY}
sed -i "s/swiftgateway-.*.jar/swiftgateway-${TARGET_VERSION}.jar/" swiftgateway.service
sed -i "s/e.activeVersion/\"${TARGET_VERSION}\"/" /usr/share/nginx/admin-ui/static/js/main.*.js
sed -i "s/3.*/${TARGET_VERSION}/" /etc/profile.d/login-info.sh

# Restart Nginx
nginx -t && service nginx restart

# Restart Java
systemctl daemon-reload
service swiftgateway start