vmware-marketplacediscourse

Upgrade Discourse®

It is strongly recommended to create a backup before starting the update process. If you have important data, create and try to restore a backup to ensure that everything works properly.

Migrating the database

Follow the steps below to migrate the database from an old version to a new one:

  • Create a database backup of the running application with the following command:

      $ pg_dump -U postgres bitnami_discourse > backup.sql
    
  • Create a tarball with the uploaded files of the running application, which are located in the public/uploads directory:

      $ sudo tar -czvf uploads.tar.gz /bitnami/discourse/public/uploads
    
  • Copy both backups to the server hosting the new version.

  • On the new server, stop all servers and start only PostgreSQL and Redis:

      $ sudo /opt/bitnami/ctlscript.sh stop
      $ sudo /opt/bitnami/ctlscript.sh start postgresql
      $ sudo /opt/bitnami/ctlscript.sh start redis
    
  • Remove the previous database:

      $ /opt/bitnami/postgresql/bin/psql -U postgres -c "CREATE DATABASE bitnami_discourse; GRANT ALL PRIVILEGES ON DATABASE bitnami_discourse TO bn_discourse;"
      $ /opt/bitnami/postgresql/bin/psql -U postgres -d bitnami_discourse -c "CREATE EXTENSION hstore; CREATE EXTENSION pg_trgm;"
    
  • Restore the new database:

      $ psql -U postgres bitnami_discourse < backup.sql
    
  • Navigate to the Discourse installation directory and migrate the database:

      $ cd /opt/bitnami/discourse
      $ RAILS_ENV=production bundle exec rake db:migrate
    
  • Restore the uploaded files in the new server:

      $ sudo tar -xzvf uploads.tar.gz -C /
    
  • Restart all servers:

      $ sudo /opt/bitnami/ctlscript.sh start
    

NOTE: If your previous and new Discourse installations use different ports, you must modify the port value in the Discourse database after migrating it. To do this, connect to the Discourse database and execute the SQL command UPDATE site_settings SET value = PORT-NUMBER WHERE id = PORT-SETTING-RECORD-ID;. Replace the PORT-NUMBER placeholder with the port number used by the new Discourse installation, and the PORT-SETTING-RECORD-ID placeholder with the correct record identifier in the site_settings table. You can obtain the value for the PORT-SETTING-RECORD-ID placeholder using the query SELECT id,value FROM site_settings; and inspecting the output to obtain the identifier of the record containing the port number.

Keeping in sync with the Discourse repository at GitHub

NOTE: This is an advanced feature that should be used only by someone that knows the application and what is happening at every step of the process described below. If not, there is a new Discourse version available every week and the standard process to upgrade the whole stack can be followed.

Since Discourse changes very fast, the Bitnami Discourse Stack includes the .git files necessary to stay in sync with the repository.

As some configuration parameters are adjusted during the installation, there may be some differences between the installed version and the repository even if the installer was built recently. Follow these steps:

  • Stop all servers and start only PostgreSQL and Redis:

      $ sudo /opt/bitnami/ctlscript.sh stop
      $ sudo /opt/bitnami/ctlscript.sh start postgresql
      $ sudo /opt/bitnami/ctlscript.sh start redis
    
  • Prepare your environment for the upgrade. Navigate to the Discourse installation directory:

      $ cd /opt/bitnami/discourse
    
  • In the Discourse installation directory, checkout the master branch and pull the latest version. You will need to checkout the Gemfile and Gemfile.lock files to overwrite Bitnami’s changes to support offline installations.

    NOTE: You will need to configure Git as described in the Troubleshooting section to stash the changes if this is the first time you’re using it, and replace the LATEST-VERSION placeholder with the latest version number.

      $ git checkout Gemfile*
      $ git checkout bin
      $ git stash
      $ git fetch
      $ git checkout tags/vLATEST-VERSION
      $ git stash apply
    

    NOTE: You may need to remove raindrops, unicorn and kgio gems from the Gemfile.lock file.

  • View the Gemfile.lock file to see the version of Bundler in use.

  • Install and configure that version of Bundler, replacing the BUNDLER-VERSION placeholder with the version number:

      $ gem install bundler -v BUNDLER-VERSION
      $ bundle config default BUNDLER-VERSION
    

    For example:

      $ gem install bundler -v 2.1.1
      $ bundle config default 2.1.1
    
  • Execute the following command:

      $ sudo bundle install --without development test sqlite --binstubs --deployment
    
  • Apply any new database migrations:

      $ RAILS_ENV=production bundle exec rake db:migrate
    
  • Recompile the application assets (it may take a few minutes):

      $ sudo chmod 666 log/production.log
      $ sudo RAILS_ENV=production bundle exec rake assets:precompile
    
  • Remove the Discourse cache:

      $ sudo rm -rf tmp/cache
    
  • Restart Apache and Discourse servers:

      $ sudo /opt/bitnami/ctlscript.sh start
    

Troubleshooting

  • If you run git and you get this output:

      Please tell me who you are.
    

    Run the commands below, replacing the placeholders with your name and email address:

      $ git config --global user.email "you@example.com"
      $ git config --global user.name "Your Name"
    
  • If you see the following error:

      rake aborted!
      cannot load such file -- rb-inotify
    

    Check that you are running the command using the rake command in the Discourse directory and that the command is running in production mode:

      $ export RAILS_ENV=production
      $ sudo bundle install
    
  • If there is a merge conflict, it should be fixed manually. You will see an error like this:

      $ git stash apply
      Auto-merging app/assets/javascripts/discourse/routes/discourse_location.js
      CONFLICT (content): Merge conflict in app/assets/javascripts/discourse/routes/discourse_location.js
      Auto-merging app/assets/javascripts/discourse.js
    

    To resolve this, the files listed must be edited. There are two options:

    • Keep local changes. For each conflicting file:

      • Remove everything from <<<<<<< Updated upstream to ======= and the line >>>>>>> Stashed changes. Then, run the following command:

          $ git add FILENAME
        
      • Check everything. Output of this command should be as shown:

          $ git status
          Already up-to-date.
        
      • Unstage changes automatically set to be committed.

          $ git reset HEAD
        
    • Discard local changes. For each conflicting file:

      • Remove everything from ======= to >>>>>>> Stashed changes and the line <<<<<<< Updated upstream. Then, run the following command:

          $ git add FILENAME
        
      • Check everything. Output of this command should be as shown:

          $ git status
          Already up-to-date.
        
      • Unstage changes automatically set to be committed.

          $ git reset HEAD
        
  • On Linux 32-bit instances, you may have problems with the gem libv8-3.16.14.3.gem because there is no precompiled version of this gem for this platform. An easy workaround would be to edit the Gemfile.lock file and replacing libv8 (3.16.14.3) with libv8 (3.16.14.1).

Last modification February 9, 2023