Skip to content

Commit

Permalink
Replace unicorn application server with the puma application server
Browse files Browse the repository at this point in the history
unicorn 6.1.0 does not support rack 3, there doesnt seem to be progress towards releasing a fixed version. So switch to puma

Fixes issue #569
  • Loading branch information
jcormier committed Nov 25, 2024
1 parent 00613fe commit b240f26
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 133 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,7 @@ Below is the complete list of parameters that can be set using environment varia
- **NGINX_CORS_ALLOW_METHODS**: Sets `Access-Control-Allow-Methods` response header to specify the methods allowed when accessing the resource in response to a preflight request.
- **NGINX_CORS_ALLOW_HEADERS**: Sets `Access-Control-Allow-Headers` response header to specify which headers can be used during the actual request.
- **NGINX_CORS_ALLOW_CREDENTIALS**: Sets `Access-Control-Allow-Credentials` response header to tell browsers whether to expose the response to frontend JavaScript code when the request's credentials mode (Request.credentials) is include.
- **UNICORN_WORKERS**: The number of unicorn workers to start. Defaults to `2`.
- **UNICORN_TIMEOUT**: Sets the timeout of unicorn worker processes. Defaults to `60` seconds.
- **PUMA_WORKERS**: The number of puma workers to start. Defaults to `2`.
- **MEMCACHE_HOST**: The host name of the memcached server. No defaults.
- **MEMCACHE_PORT**: The connection port of the memcached server. Defaults to `11211`.
- **SSL_CERTIFICATE_PATH**: The path to the SSL certificate to use. Defaults to `/home/redmine/data/certs/redmine.crt`.
Expand Down
16 changes: 10 additions & 6 deletions assets/build/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,16 @@ else
SQLITE3_GEM=${SQLITE3_2LINES_GEM}
fi

# Delete test: puma
sed -i \
-e '/gem .puma./d' \
"${REDMINE_INSTALL_DIR}/Gemfile"

(
echo "${PG_GEM}";
echo "${MYSQL2_GEM}";
echo "${SQLITE3_GEM}";
echo '# unicorn 5.5.0 has a bug in unicorn_rails. See issue #392';
echo 'gem "unicorn", "~> 6.1"';
echo 'gem "puma", "~> 6"';
echo 'gem "dalli", "~> 3.2.6"';
) >> ${REDMINE_INSTALL_DIR}/Gemfile

Expand Down Expand Up @@ -194,13 +198,13 @@ stdout_logfile=${REDMINE_LOG_DIR}/supervisor/%(program_name)s.log
stderr_logfile=${REDMINE_LOG_DIR}/supervisor/%(program_name)s.log
EOF

# configure supervisord to start unicorn
cat > /etc/supervisor/conf.d/unicorn.conf <<EOF
[program:unicorn]
# configure supervisord to start puma
cat > /etc/supervisor/conf.d/puma.conf <<EOF
[program:puma]
priority=10
directory=${REDMINE_INSTALL_DIR}
environment=HOME=${REDMINE_HOME}
command=bundle exec unicorn_rails -E ${RAILS_ENV} -c ${REDMINE_INSTALL_DIR}/config/unicorn.rb
command=bundle exec puma -e ${RAILS_ENV} -C ${REDMINE_INSTALL_DIR}/config/puma.rb
user=${REDMINE_USER}
autostart=true
autorestart=true
Expand Down
4 changes: 2 additions & 2 deletions assets/runtime/config/nginx/redmine
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Maintainer: @sameersbn

upstream redmine {
server 127.0.0.1:8080 fail_timeout=0;
server unix:{{REDMINE_INSTALL_DIR}}/tmp/sockets/puma.sock fail_timeout=0;
}

## Normal HTTP host
Expand Down Expand Up @@ -48,7 +48,7 @@ server {
}

## If a file, which is not found in the root folder is requested,
## then the proxy passes the request to the upsteam (redmine unicorn).
## then the proxy passes the request to the upsteam (redmine puma).
location @redmine {
## If you use HTTPS make sure you disable gzip compression
## to be safe against BREACH attack.
Expand Down
2 changes: 1 addition & 1 deletion assets/runtime/config/nginx/redmine-ssl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Maintainer: @sameersbn

upstream redmine {
server 127.0.0.1:8080 fail_timeout=0;
server unix:{{REDMINE_INSTALL_DIR}}/tmp/sockets/puma.sock fail_timeout=0;
}

## Normal HTTP host
Expand Down
48 changes: 48 additions & 0 deletions assets/runtime/config/redmine/puma.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#Change to match your CPU core count
# Check using this on the server => grep -c processor /proc/cpuinfo
workers {{PUMA_WORKERS}}
preload_app!

# Min and Max threads per worker
threads 1, 6
app_dir = File.expand_path("{{REDMINE_INSTALL_DIR}}")

# Default to production
rails_env = ENV['RAILS_ENV'] || 'production'
environment rails_env

# Set up socket location
bind "unix://#{app_dir}/tmp/sockets/puma.sock"
bind "tcp://0.0.0.0:8080"

# Logging
stdout_redirect "#{app_dir}/log/puma.stdout.log", "#{app_dir}/log/puma.stderr.log", true

# Set master PID and state locations
pidfile "#{app_dir}/tmp/pids/puma.pid"
state_path "#{app_dir}/tmp/pids/puma.state"
activate_control_app


before_fork do |server, worker|
require 'active_record'
# the following is highly recomended for Rails + "preload_app true"
# as there's no need for the master process to hold a connection
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!

end

on_worker_boot do
require 'active_record'

# the following is *required* for Rails + "preload_app true",
ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])

# if preload_app is true, then you may also want to check and
# restart any other shared sockets/descriptors such as Memcached,
# and Redis. TokyoCabinet file handles are safe to reuse
# between any number of forked children (assuming your kernel
# correctly implements pread()/pwrite() system calls)
end
107 changes: 0 additions & 107 deletions assets/runtime/config/redmine/unicorn.rb

This file was deleted.

6 changes: 5 additions & 1 deletion assets/runtime/env-defaults
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,14 @@ then
esac
fi

## UNICORN
## UNICORN (deprecated)
UNICORN_WORKERS=${UNICORN_WORKERS:-2}
UNICORN_TIMEOUT=${UNICORN_TIMEOUT:-60}

## PUMA
PUMA_WORKERS=${PUMA_WORKERS:-${UNICORN_WORKERS}}
# There is no PUMA timeout setting

## MEMCACHED
MEMCACHED_HOST=${MEMCACHED_HOST:-}
MEMCACHED_PORT=${MEMCACHED_PORT:-}
Expand Down
22 changes: 8 additions & 14 deletions assets/runtime/functions
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ USERCONF_TEMPLATES_DIR="${REDMINE_DATA_DIR}/config"

REDMINE_CONFIG="${REDMINE_INSTALL_DIR}/config/configuration.yml"
REDMINE_DATABASE_CONFIG="${REDMINE_INSTALL_DIR}/config/database.yml"
REDMINE_UNICORN_CONFIG="${REDMINE_INSTALL_DIR}/config/unicorn.rb"
REDMINE_PUMA_CONFIG="${REDMINE_INSTALL_DIR}/config/puma.rb"
REDMINE_SECRET_CONFIG="${REDMINE_INSTALL_DIR}/config/initializers/secret_token.rb"
REDMINE_ADDITIONAL_CONFIG="${REDMINE_INSTALL_DIR}/config/additional_environment.rb"
REDMINE_NGINX_CONFIG="/etc/nginx/sites-enabled/redmine"
Expand Down Expand Up @@ -343,23 +343,17 @@ redmine_configure_logger() {
echo "config.log_level = :${LOGGER_LEVEL}" >> "${REDMINE_ADDITIONAL_CONFIG}"
}

redmine_configure_unicorn() {
echo "Configuring redmine::unicorn..."
redmine_configure_puma() {
echo "Configuring redmine::puma..."
if [[ ${REDMINE_RELATIVE_URL_ROOT} == / ]]; then
exec_as_redmine sed -i '/{{REDMINE_RELATIVE_URL_ROOT}}/d' ${REDMINE_UNICORN_CONFIG}
exec_as_redmine sed -i '/{{REDMINE_RELATIVE_URL_ROOT}}/d' ${REDMINE_PUMA_CONFIG}
fi

if [[ ${NGINX_ENABLED} != true ]]; then
# nginx has been disabled, configure unicorn to listen on all interfaces
exec_as_redmine sed -i "s|127.0.0.1:8080|0.0.0.0:8080|" ${REDMINE_UNICORN_CONFIG}
fi

update_template ${REDMINE_UNICORN_CONFIG} \
update_template ${REDMINE_PUMA_CONFIG} \
REDMINE_INSTALL_DIR \
REDMINE_USER \
REDMINE_RELATIVE_URL_ROOT \
UNICORN_WORKERS \
UNICORN_TIMEOUT
PUMA_WORKERS
}

redmine_configure_secret_token() {
Expand Down Expand Up @@ -862,7 +856,7 @@ install_configuration_templates() {
install_template ${REDMINE_USER}: redmine/additional_environment.rb ${REDMINE_ADDITIONAL_CONFIG} 0644
install_template ${REDMINE_USER}: redmine/configuration.yml ${REDMINE_CONFIG} 0640
install_template ${REDMINE_USER}: redmine/database.yml ${REDMINE_DATABASE_CONFIG} 0640
install_template ${REDMINE_USER}: redmine/unicorn.rb ${REDMINE_UNICORN_CONFIG} 0644
install_template ${REDMINE_USER}: redmine/puma.rb ${REDMINE_PUMA_CONFIG} 0644
install_template ${REDMINE_USER}: redmine/secret_token.rb ${REDMINE_SECRET_CONFIG} 0644

if [[ ${REDMINE_RELATIVE_URL_ROOT} != / ]]; then
Expand Down Expand Up @@ -901,7 +895,7 @@ configure_redmine() {
redmine_configure_database
redmine_configure_memcached
redmine_configure_logger
redmine_configure_unicorn
redmine_configure_puma
redmine_configure_secret_token
redmine_configure_concurrent_uploads
redmine_configure_sudo_mode
Expand Down

0 comments on commit b240f26

Please sign in to comment.