Skip to content

Use :rails_env for RAILS_ENV in the systemd service - #9

Merged
burisu merged 1 commit into
mainfrom
rails-env-from-capistrano
Nov 9, 2026
Merged

burisu merged 1 commit into
mainfrom
rails-env-from-capistrano

Conversation

@burisu

@burisu burisu commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Issue #8: the systemd service generated by solid_queue:install writes RAILS_ENV=<stage>. A stage whose name isn't the Rails environment (e.g. a preprod stage with set :rails_env, "production") therefore starts Solid Queue with RAILS_ENV=preprod.

Changes

  • lib/capistrano/templates/solid_queue.service.erb: RAILS_ENV comes from fetch(:rails_env, fetch(:stage)). Same rule as capistrano-rails (set_rails_env.rake: fetch(:rails_env) || fetch(:stage)) and capistrano3-puma (puma.rb:110). Without :rails_env, nothing changes.
  • The unit name stays <application>_solid_queue_<stage>: two stages on the same server can share the same RAILS_ENV.
  • CHANGELOG: an installed service isn't regenerated on deploy, cap <stage> solid_queue:install has to be run again.

Tests

  • test/capistrano/test_service_unit.rb runs cap preprod solid_queue:generate in a minimal Capistrano project (standard Capfile, SSHKit Local backend, so neither SSH nor systemd) and reads the generated unit:
    • with set :rails_env, "production" → Environment='RAILS_ENV=production' (fails without the fix: the unit contained RAILS_ENV=preprod);
    • without :rails_env → Environment='RAILS_ENV=preprod'.
  • Mutation: reverting to fetch(:stage), removing the fetch(:stage) fallback, or deleting the line each makes at least one of the two tests fail.
  • bundle exec rake (tests + standard): green locally (Ruby 4.0.6).

🤖 Generated with Claude Code

Le service systemd recevait toujours le nom du stage Capistrano comme
RAILS_ENV : un stage « preprod » configuré avec
`set :rails_env, "production"` lançait Solid Queue avec
RAILS_ENV=preprod (issue #8).

Le template lit maintenant `fetch(:rails_env, fetch(:stage))`, comme
capistrano-rails et capistrano3-puma. Un service déjà installé n'est
pas régénéré au déploiement : il faut relancer
`cap <stage> solid_queue:install`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@burisu
burisu marked this pull request as ready for review November 9, 2026 08:20
@burisu
burisu merged commit 033d366 into main Nov 9, 2026
5 checks passed
@burisu
burisu deleted the rails-env-from-capistrano branch November 9, 2026 08:20
@burisu
burisu restored the rails-env-from-capistrano branch November 9, 2026 08:21
@burisu
burisu deleted the rails-env-from-capistrano branch November 9, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant