Friday, November 3, 2023

Convert Redmine to Run in a Docker Container - Part I

 Introduction

We have been running Redmine, an issue tracking system, on a Virtual Machine running Ubuntu. The Ubuntu OS is near end of life for support, and the Redmine version is also very old. So we wanted to upgrade both the OS and Redmine to the latest versions.

The following article describes the steps we took to upgrade the OS and Redmine.

As an option, you can upgrade only Redmine to run in a docker container, and that will simplify the data backup part of the task, because you can copy the existing data to a new location on the same server.

Convention

When you see code blocks:

  • Lines that start with $ are commands to be typed (or copy-pasted), without the $, into the terminal window
  • Lines that start with # are helpful comments for you

Turn off the Old Web Server

Before we backup Redmine, let us turn it off by turning off the Apache web server that hosts the Redmine website on the host Ubuntu OS.

1. Change all port numbers in /etc/apache2/ports.conf to avoid any possible conflicts:
$ sudo nano /etc/apache2/ports.conf

 

Old PortNew Port
808080
4438443

Press CTRL+S and CTRL+X to save and exit

2. Turn off the old web server

$ sudo systemctl stop apache2

$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: inactive (dead) since Fri 2023-09-01 15:31:52 PDT; 8s ago
  Process: 39951 ExecStop=/usr/sbin/apachectl stop (code=exited, status=0/SUCCESS)
  Process: 36201 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
  Process: 5395 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 765 (code=exited, status=0/SUCCESS)

Prepare Redmine for Upgrade

Backup the Redmine Database

This step depends on your existing database server. In our case, we use SQL server, and so I used the SQL Management Studio to back up the Redmine database.

Backup the Redmine Data

In addition to the Redmine database, we also need to backup the Redmine data  files on the local hard drive.They include the configuration files, the plugins, the themes, and the uploaded files that were attached to issues.

# Create downloads folder
$ cd ~
$ mkdir downloads

# remove .gz file sin the downloads folder
$ rm -f downloads/*.gz

# Move into the old redmine installation folder for backing up its files
$ cd www/redmine

# Backup config files
$ sudo tar -czf ~/downloads/redmine-config.gz ./config

# Backup plugins
$ sudo tar -czf ~/downloads/redmine-plugins.gz ./plugins

# Backup themes
$ sudo tar -czf ~/downloads/redmine-themes.gz  ./public/themes

# Backup all uploaded files for issues (it can be several GB)
$ sudo tar -czf ~/downloads/redmine-files.gz ./files

# If needed, backup newer uploaded files for issues for August 2023 after the 7th
$ sudo tar -newer=2023-10-07 -czf ~/downloads/redmine-files_after_1007.gz ./files/2023/10

Copy backup files to another computer

This step is needed if you are going to upgrade the host OS to a new version by wiping the old hard drive and doing a fresh OS install.
  • Login to another PC at 192.168.1.100 (use your own backup computer's IP here)
  • Start the command prompt
  • Do the following commands:
> REM Go to home directory
> CD %HOMEPATH%

> REM Go to Downloads folder
> CD Downloads

> REM Copy all .gz files from the Redmine server to the current diretory
> scp yourlogin@192.168.1.100:downloads/*.gz ./

> REM OR Copy individual .gz file from the Redmine server to the current diretory
> REM These files are not too big, and they will not take too long transfer
> scp yourlogin@192.168.1.100:downloads/redmine-config.gz ./
> scp yourlogin@192.168.1.100:downloads/redmine-plugins.gz ./
> scp yourlogin@192.168.1.100:downloads/redmine-themes.gz ./

> REM This file is huge, and it will take an hour or so to transfer
> scp yourlogin@192.168.1.100:downloads/redmine-files.gz ./

> REM This newer uploads file is smaller, and it will not take as long transfer
> scp yourlogin@192.168.1.100:downloads/redmine-files_after_1007.gz ./

Un-install obsolete or unused Redmine plugins

This step is for upgrading from an existing old version of Redmine

Visit the home page of each plugin in your redmine instance and verify which ones are not compatible with the latest version. Those plugins will need to be un-installed before we upgrade Redmine to the latest version.

Turn on the old web server

$ sudo systemctl start apache2

$ sudo systemctl status apache2

For our case, we need to un-install these obsolete plugins from Redmine:

  • clipboard_image_paste
  • redmine_agile
  • redmine_custom_css
  • redmine_emojibutton
  • redmine_lightbox2

$ cd $REDMINE_ROOT

# Un-install the plugins in Redmine
$ bundle exec rake redmine:plugins:migrate NAME=clipboard_image_paste VERSION=0 RAILS_ENV=production
$ bundle exec rake redmine:plugins:migrate NAME=redmine_agile VERSION=0 RAILS_ENV=production
$ bundle exec rake redmine:plugins:migrate NAME=redmine_custom_css VERSION=0 RAILS_ENV=production
$ bundle exec rake redmine:plugins:migrate NAME=redmine_emojibutton VERSION=0 RAILS_ENV=production
$ bundle exec rake redmine:plugins:migrate NAME=redmine_lightbox2 VERSION=0 RAILS_ENV=production

# If you are doing and in-place upgrade of Redmine, remove the 
# plugin folders for the plugins that were un-installed above

$ rm -rf plugins/clipboard_image_paste
$ rm -rf plugins/redmine_agile
$ rm -rf plugins/redmine_custom_css
$ rm -rf plugins/redmine_emojibutton
$ rm -rf plugins/redmine_lightbox2

Turn off and disable the old web server for good

Now we are done with the old Redmine web server, for good. So let us turn off the old Apache web server permanently because it is no longer needed. The new instance will be running in a Docker container with its own web server.

$ sudo systemctl stop apache2

$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: inactive (dead) since Fri 2023-09-01 15:31:52 PDT; 8s ago
  Process: 39951 ExecStop=/usr/sbin/apachectl stop (code=exited, status=0/SUCCESS)
  Process: 36201 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
  Process: 5395 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 765 (code=exited, status=0/SUCCESS)

$ sudo systemctl disable apache2

$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; disabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: inactive (dead) since Fri 2023-09-01 15:31:52 PDT; 7min ago
 Main PID: 765 (code=exited, status=0/SUCCESS)

Stay tuned for Part II where we do the actual upgrade of the OS and get Redmine up and running in a Docker container!

No comments:

Post a Comment