Installing Redmine 5.0.4 in jail on FreeBSD 13.1

Redmine and FreeBSD have a difficult relationship. At the moment, Redmine is not in FreeBSD packages, and there are two versions in the ports, fiddling with which only takes time and disk space. The guides found on the net for installing redmine on FreeBSD are long outdated. So I had to roll up my sleeves and proceed by trial and error. This case did not become successful immediately, so I decided to leave the dry residue for myself and my followers.

I’ll say right away that the purpose of this post is to save time, and not at all to teach someone what they didn’t know before.

For simplicity, everything in the jail was done as root, especially since there is nothing in it except for redmine and was not planned.

So, we raise the jail:

zfs create -o mountpoint=/jails zroot/jails
zfs create zroot/jails/redmine
bsdinstall jail /jails/redmine

In /etc/jail.conf we add (the interface and IP address we prescribe our own)

redmine {
host.hostname = "redmine";
path = "/jails/redmine/";
interface = "wlan0";
ip4.addr = 192.168.20.203;
mount.devfs;
devfs_ruleset = 4;
exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
}

We start the jail, log in using the JID number.

service jail start redmine
jls

JID IP Address Hostname Path
1 192.168.20.203 redmine /jails/redmine

jexec 1 /bin/sh

So here we are.

pkg update

The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg from pkg+http://pkg.FreeBSD.org/FreeBSD:13:amd64/quarterly, please wait...
Verifying signature with trusted certificate pkg.freebsd.org.2013102301... done
[redmine] Installing pkg-1.18.4...
[redmine] Extracting pkg-1.18.4: 100%
Updating FreeBSD repository catalogue...
[redmine] Fetching meta.conf: 100% 163 B 0.2kB/s 00:01
[redmine] Fetching packagesite.pkg: 100% 6 MiB 3.4MB/s 00:02
Processing entries: 100%
FreeBSD repository update completed. 32318 packages processed.
All repositories are up to date.

Then we go for wisdom to the site redmine.org

https://www.redmine.org/projects/redmine/wiki/RedmineInstall

First of all, we find a link to the desired version there and download it.

fetch https://www.redmine.org/releases/redmine-5.0.4.tar.gz

Unpack, place in a folder where the project will live in the future. Let it be /opt/redmine

mkdir /opt
tar xfvz redmine-5.0.4.tar.gz -C /opt
mv /opt/redmine-5.0.4/ /opt/redmine

Next, install ruby ​​and ruby-gems with one command:

pkg install ruby30-gems

What about a database in jail? Personally, on my not the coolest home server, I keep as many jails with different services, including Home Assistant, Nextcloud, the same Redmine and a number of other test projects. It is expensive to keep your own DBMS in each jail, so this whole zoo goes to the host for data. So, let’s have a database and a web proxy on a host whose address, for example, 192.168.20.138. And therefore, we take out the installation of the database server outside of this post, raise the database server on our own, then create the database as described on the site https://www.redmine.org/projects/redmine/wiki/RedmineInstall. Do not forget to configure the database server to accept client connections from the local network.

At this stage, I left Gauss diagrams for aesthetes and refused to install everything related to working with graphics, ImageMagic and GhostScript, respectively, did not install.

After the DBMS has taken off and is ready to serve the database, we proceed to the next step:

cd /opt/redmine
gem install bundler

Once again, we make sure that everything in /opt/redmine/config/database.yml is filled in accordance with the database that you raised, based on the instructions from here: https://www.redmine.org/projects/redmine/wiki/RedmineInstall

For me it looks like this:

cat database.yml

production:
adapter: postgresql
database: redmine
host: 192.168.20.138
username: redmine
password: "xxxxxx"
encoding: utf8

Don’t forget to download and install the database client.
In my case:

pkg install postgresql13-client

Next, we run an important procedure that will download and install rails and all the necessary gems described in the Gemfile.

bundle install --without development test rmagick

The last argument in this command tells you not to install graphical functionality that requires ImageMagic and GhostScript in the system.

The following command defines the rules for working with cookies, preventing the possibility of session hijacking.

bundle exec rake generate_secret_token

Now it’s time to populate the previously created database with initial values ​​if you raised the database from scratch. After entering the second command, the system will ask you to enter the language in which Redmine will communicate with you.

RAILS_ENV=production bundle exec rake db:migrate
RAILS_ENV=production bundle exec rake redmine:load_default_data

Next is the most interesting. This whole zoo, written in ruby ​​on rails, needs to be given away via http. Out of the box, at that moment only the puma web server was available for installation. All other servers indicated in the documentation must be searched for and installed separately without any guarantees of version compatibility, which Redmine has all the time. By default, puma is in the test group, and therefore is not installed automatically. To fix this, you need to find the line in the file /opt/regmine/Gemfile

gem 'puma', '< 6.0.0'

and move it to the beginning of the file, placing it under the line

gem 'bundler', '>= 1.12.0'

then repeat the command

bundle install --without development test rmagick

Now we can check what we got.

bundle exec rails server -u puma -e production

If everything is correct, you will see something like:

=> Booting Puma=> Rails 6.1.7 application starting in production=> Run bin/rails server --help for more startup optionsPuma starting in single mode…

  • Puma version: 5.6.5 (ruby 3.0.5-p211) (“Birdie’s Version”)

  • min threads: 0

  • Max threads: 5

  • Environment: production

  • PID: 14769

  • Listening on http://192.168.20.203:3000Use Ctrl-C to stop

And in the browser at the above address, you will see a pristine Redmine.

Using Ctrl-C to stop the service does not look very convenient, so immediately there is a desire to daemonize this puma. To do this, there is another gem application that needs to be legalized in GemFile by placing above the line

gem 'puma', '< 6.0.0'

such a line

gem 'puma-daemon', require: false

then once again repeat the already known spell:

bundle install --without development test rmagick

But that is not all. For daemonization to work, you need to create a puma.rb file in the /opt/redmine/config directory, which should contain at least the following:

#!/usr/bin/env puma
application_path="/opt/redmine"
directory application_path
environment 'production'
require 'puma/daemon'
daemonize true
port 3000
workers 3
threads 2,3
pidfile "#{application_path}/tmp/pids/puma.pid"
state_path "#{application_path}/tmp/pids/puma.state"
stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"

Let’s run it again:

bundle exec rails server -u puma -e production

The result should be something like:

=> Booting Puma
=> Rails 6.1.7 application starting in production
=> Run `bin/rails server --help` for more startup options
[14931] Puma starting in cluster mode...
[14931] * Puma version: 5.6.5 (ruby 3.0.5-p211) ("Birdie's Version")
[14931] * Min threads: 2
[14931] * Max threads: 3
[14931] * Environment: production
[14931] * Master PID: 14931
[14931] * Workers: 3
[14931] * Restarts: (✔) hot (✔) phased
[14931] * Listening on http://192.168.20.203:3000

You can stop the daemon with the command

bundle exec pumactl --state /opt/redmine/tmp/pids/puma.state stop

With the start and restart options, respectively, start and restart, but it works only from the application directory.

Voila. As a result, we have a jail created from scratch with a working Redmine 5.0.4, while the database server lives outside the jail. Actually, nothing prevents, if necessary, from running MySQL or MariaDB inside the jail, but Postgres does not like such violence against itself, it is sad for him in a cage.

Now you can take care of sending Redmine out through reverse proxy. But that is another story.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *