Skip to content

Instantly share code, notes, and snippets.

@cinderblock
Created May 17, 2018 21:04
Show Gist options
  • Save cinderblock/97739cf9d61c5c255263893d6f8ebc93 to your computer and use it in GitHub Desktop.
Save cinderblock/97739cf9d61c5c255263893d6f8ebc93 to your computer and use it in GitHub Desktop.
Simple script for updating rocket.chat on a systemd machine
#!/bin/bash
# USAGE: `./update-rocket.chat.sh` as regular user with sudo permissions
# Make script fail on any error
set -e
# Ensure that we're working inside of /opt
cd /opt
LATEST=$(curl -ILs -o /dev/null -w %{url_effective} https://releases.rocket.chat/latest/download)
# What we're going to call the new folder. Get the current version number from "latest" redirect
NAME=Rocket.Chat.$(echo ${LATEST} | cut -f1 -d'?' | cut -d- -f3 | cut -d. -f1,2,3)
# If the directory exists, don't do anything
if [[ -d ${NAME} ]]; then
echo "Already on latest: ${NAME}"
exit 0
fi
# Create a directory that tar will fill with the rocket chat bundle
sudo mkdir ${NAME}
# Make sure it's owned by rocketchat user & group
sudo chown rocketchat: ${NAME}
echo Getting latest bundle...
# Get the latest bundle and extract it
curl -sL ${LATEST} | sudo -u rocketchat tar zx -C ${NAME} --strip 1
echo Installing dependencies...
# Install dependencies
pushd ${NAME}/programs/server > /dev/null
sudo -u rocketchat yarn --silent > /dev/null
popd > /dev/null
echo Restarting server...
# Stop running service
sudo systemctl stop rocketchat
# Update symlink to point at new version
sudo ln -snf ${NAME} Rocket.Chat
# Start new instance
sudo systemctl start rocketchat
echo Done! Please wait ~30 seconds for new instance to start fully.
echo
# Watch startup logs for up to 30 seconds
timeout 30s journalctl -u rocketchat --follow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment