Skip to content

Commit

Permalink
feat: cwctl upgrade node for existing installations (#7772)
Browse files Browse the repository at this point in the history
Co-authored-by: Sojan Jose <sojan@pepalo.com>
  • Loading branch information
vishnu-narayanan and sojan-official committed Sep 18, 2023
1 parent 86894b2 commit 2429daa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion VERSION_CW
@@ -1 +1 @@
2.17.0
3.1.0
2 changes: 1 addition & 1 deletion VERSION_CWCTL
@@ -1 +1 @@
2.3.0
2.4.0
37 changes: 33 additions & 4 deletions deployment/setup_20.04.sh
Expand Up @@ -2,7 +2,7 @@

# Description: Install and manage a Chatwoot installation.
# OS: Ubuntu 20.04 LTS
# Script Version: 2.3.0
# Script Version: 2.4.0
# Run this script as root

set -eu -o errexit -o pipefail -o noclobber -o nounset
Expand All @@ -19,7 +19,7 @@ fi
# option --output/-o requires 1 argument
LONGOPTS=console,debug,help,install,Install:,logs:,restart,ssl,upgrade,webserver,version
OPTIONS=cdhiI:l:rsuwv
CWCTL_VERSION="2.3.0"
CWCTL_VERSION="2.4.0"
pg_pass=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 15 ; echo '')

# if user does not specify an option
Expand Down Expand Up @@ -722,14 +722,42 @@ EOF
# None
##############################################################################
function upgrade_redis() {

echo "Checking Redis availability..."

# Check if Redis is installed
if ! command -v redis-server &> /dev/null; then
echo "Redis is not installed. Skipping Redis upgrade."
return
fi

echo "Checking Redis version..."

# Get current Redis version
current_version=$(redis-server --version | awk -F 'v=' '{print $2}' | awk '{print $1}')

# Parse major version number
major_version=$(echo "$current_version" | cut -d. -f1)

if [ "$major_version" -ge 7 ]; then
echo "Redis is already version $current_version (>= 7). Skipping Redis upgrade."
return
fi

echo "Upgrading Redis to v7+ for Rails 7 support(Chatwoot v2.17+)"

curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
apt update -y
apt upgrade redis-server -y
apt install libvips -y
}

function upgrade_node() {
echo "Upgrading nodejs version to v20.x"
curl -sL https://deb.nodesource.com/setup_20.x | sudo bash -
apt install -y nodejs
}

##############################################################################
# Upgrade an existing installation to latest stable version(-u/--upgrade)
Expand All @@ -746,6 +774,7 @@ function upgrade() {
sleep 3
upgrade_prereq
upgrade_redis
upgrade_node
sudo -i -u chatwoot << "EOF"
# Navigate to the Chatwoot directory
Expand All @@ -765,7 +794,7 @@ function upgrade() {
yarn
# Recompile the assets
rake assets:precompile RAILS_ENV=production
rake assets:precompile RAILS_ENV=production NODE_OPTIONS=--openssl-legacy-provider
# Migrate the database schema
RAILS_ENV=production POSTGRES_STATEMENT_TIMEOUT=600s bundle exec rake db:migrate
Expand Down Expand Up @@ -829,7 +858,7 @@ function webserver() {
# None
##############################################################################
function version() {
echo "cwctl v$CWCTL_VERSION alpha build"
echo "cwctl v$CWCTL_VERSION beta build"
}

##############################################################################
Expand Down

0 comments on commit 2429daa

Please sign in to comment.