nativeInstallerdiscourse

Upgrade Discourse

Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and MacOS) or by clicking the shortcut in the Start Menu under “Start -> Bitnami APPNAME Stack -> Application console” (Windows). On OS X VMs, the installation directory is /opt/bitnami and OS X VM users can click the “Open Terminal” button to run commands. Learn more about the Bitnami stack environment and about OS X VMs.

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:

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

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

    $ sudo installdir/ctlscript.sh stop
    $ sudo installdir/ctlscript.sh start postgresql
    
  • Remove the previous database:

    $ psql -U postgres
    drop database bitnami_discourse;
    create database bitnami_discourse;
    alter database bitnami_discourse owner to bn_discourse;
    create extension hstore; create extension pg_trgm;
    
  • Restore the new database:

    $ psql -U postgres bitnami_discourse < backup.sql
    
  • Start the Redis server and migrate the database:

    $ sudo installdir/ctlscript.sh start redis
    $ cd installdir/apps/discourse/htdocs
    $ bin/rake db:migrate RAILS_ENV=production
    
  • Restore the uploaded files in the new server:

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

    $ sudo installdir/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

IMPORTANT: This procedure is supported since the Bitnami Discourse Stack v0.8.5-0.


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:

  • For Linux native installers, install the libc6-dev libraries. On Debian-based systems like Ubuntu, this is included in the build-essential package.

  • Change to the Discourse application directory:

    $ cd installdir/apps/discourse/htdocs
    
  • Stop the Apache and Discourse services:

    $ sudo installdir/ctlscript.sh stop apache
    $ sudo installdir/ctlscript.sh stop discourse_sidekiq
    
  • Stop and disable the Clockwork service if your current Discourse version uses it. This step is not required since v0.9.6.1.

    $ sudo installdir/ctlscript.sh stop discourse_clockwork
    $ sudo mv installdir/apps/discourse/scripts/clockwork.sh installdir/apps/discourse/scripts/clockwork.sh.disabled
    
  • Edit the file installdir/scripts/setenv.sh and comment the line:

    . installdir/scripts/build-setenv.sh
    
  • Edit the file installdir/ruby/.bundler/config and comment the line:

    BUNDLE_BUILD__NOKOGIRI: --with-iconv-dir=installdir/common
    
  • Change to the Discourse application directory:

    $ cd installdir/apps/discourse/htdocs
    
  • 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 that 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:

    $ sudo installdir/ruby/bin/ruby bin/rake db:migrate RAILS_ENV=production
    
  • Recompile the application assets (it may take a few minutes):

    $ sudo chmod 666 log/production.log
    $ sudo installdir/ruby/bin/ruby bin/rake assets:precompile RAILS_ENV=production
    
  • Remove the Discourse cache:

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

    $ sudo installdir/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
    $ cd installdir/apps/discourse/htdocs
    $ bin/rake 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 November 17, 2020