Skip to content

Instantly share code, notes, and snippets.

@bblanchon
Created March 16, 2015 10:45
Show Gist options
  • Save bblanchon/5d6482855bfa5200614a to your computer and use it in GitHub Desktop.
Save bblanchon/5d6482855bfa5200614a to your computer and use it in GitHub Desktop.
Automatically upgrade TeamCity server
#!/usr/bin/bash
set -eu
trap "tput sgr0" 0
echo -n "Enter new TeamCity version: "
read VERSION
FILE=TeamCity-$VERSION.tar.gz
URL="https://download.jetbrains.com/teamcity/$FILE"
if [[ ! -f $FILE ]]; then
tput smso
echo "Download $URL..."
tput rmso
wget "$URL"
fi
tput smso
echo "Stop TeamCity..."
tput rmso
sudo service teamcity-server stop
while [[ $(nmap localhost -p 8111,8543 | grep open | wc -l) -gt 0 ]]; do
tput smso
echo "Ports are still opened, waiting..."
tput rmso
sleep 5
done
OLD_BUILD=$(ls TeamCity/BUILD* | cut -c16-)
OLD_DIR="TeamCity_$OLD_BUILD"
tput smso
echo "Backup installation to $OLD_DIR..."
tput rmso
mv TeamCity $OLD_DIR
tput smso
echo "Extract $FILE..."
tput rmso
tar xf $FILE
tput smso
echo "Copy configuration..."
tput rmso
cp -f $OLD_DIR/conf/server.xml TeamCity/conf/server.xml
tput smso
echo "Start TeamCity..."
tput rmso
sudo service teamcity-server start
sleep 10
if [[ $(nmap localhost -p 8111,8543 | grep open | wc -l) -eq 2 ]]; then
tput smso
echo "Upgrade complete !"
tput rmso
else
tput smso
echo "ERROR: Server failed to start!!!!"
tput rmso
sleep 5
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment