Skip to content

Fixes #39536 - preserve RAILS_LOG_TO_STDOUT in foreman-rake#11109

Open
Alleny244 wants to merge 1 commit into
theforeman:developfrom
Alleny244:fix/foreman-rake-preserve-rails-log-to-stdout
Open

Fixes #39536 - preserve RAILS_LOG_TO_STDOUT in foreman-rake#11109
Alleny244 wants to merge 1 commit into
theforeman:developfrom
Alleny244:fix/foreman-rake-preserve-rails-log-to-stdout

Conversation

@Alleny244

@Alleny244 Alleny244 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #39536.

foreman-rake runs Rails via runuser -, which starts a login shell and clears most environment variables before switching to the foreman user. As a result, RAILS_LOG_TO_STDOUT was lost during install-time rake executions, causing Rails to fall back to production.log even when stdout logging was intended.

This change preserves RAILS_LOG_TO_STDOUT across the runuser invocation. Container and RPM installs that set the variable now keep stdout logging throughout install-time rake boots and no longer create /var/log/foreman/production.log. Systems that do not set RAILS_LOG_TO_STDOUT continue using file logging as before.

Related PR: theforeman/foreman-oci-images#66

Prerequisites for testing

  • A system (or container) with the foreman user and runuser available

Testing scenarios

1. Verify runuser preserves the environment

sudo RAILS_LOG_TO_STDOUT=true runuser - foreman -s /bin/bash -c 'echo "[$RAILS_LOG_TO_STDOUT]"'
# Before fix: []

sudo RAILS_LOG_TO_STDOUT=true runuser -w RAILS_LOG_TO_STDOUT - foreman -s /bin/bash -c 'echo "[$RAILS_LOG_TO_STDOUT]"'
# After fix: [true]

2. Verify foreman-rake logs to stdout

With the patched /usr/sbin/foreman-rake:

rm -f /var/log/foreman/production.log

RAILS_LOG_TO_STDOUT=true foreman-rake db:version

ls /var/log/foreman/production.log
# Expected: No such file or directory

Boot messages (for example, Rails cache backend: File) should appear on stdout.

3. Verify existing behavior is unchanged

Run foreman-rake without RAILS_LOG_TO_STDOUT:

unset RAILS_LOG_TO_STDOUT
foreman-rake db:version

Rails should continue using production.log, matching the existing behavior for traditional installations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant