diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a6b227..83f5e07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - `RAILS_ENV` of the systemd service now comes from `:rails_env`, falling back to `:stage` [#8](https://github.com/codeur/capistrano-solid_queue/issues/8). Run `cap solid_queue:install` again to update an installed service. - `solid_queue:quiet` no longer aborts the deploy when `systemctl` fails, as before 0.1.1. +- `default_env` values in the systemd service are expanded by the server shell, as in Capistrano commands, so `RBENV_ROOT=$HOME/.rbenv` set by capistrano-rbenv becomes an absolute path [#1](https://github.com/codeur/capistrano-solid_queue/issues/1). Run `cap solid_queue:install` again to update an installed service. ## [0.1.2] - 2025-06-12 diff --git a/lib/capistrano/templates/solid_queue.service.erb b/lib/capistrano/templates/solid_queue.service.erb index 39cba23..b2cf7ca 100644 --- a/lib/capistrano/templates/solid_queue.service.erb +++ b/lib/capistrano/templates/solid_queue.service.erb @@ -6,7 +6,7 @@ After=syslog.target network.target Type=simple Environment='RAILS_ENV=<%= fetch(:rails_env, fetch(:stage)) %>' <% fetch(:default_env).reject{ |k, _| k.to_s == 'path' }.each do |variable, value| -%> -Environment='<%= variable.to_s.upcase %>=<%= value.to_s %>' +Environment='<%= variable.to_s.upcase %>=<%= capture(:printf, "%s", %("#{value.to_s.gsub('"', '\"')}")) %>' <% end -%> WorkingDirectory=<%= current_path %> ExecStart=<%= capture(:echo, SSHKit.config.command_map[:bundle]).strip %> exec rake solid_queue:start diff --git a/test/capistrano/test_service_unit.rb b/test/capistrano/test_service_unit.rb index 6815659..41ccb8c 100644 --- a/test/capistrano/test_service_unit.rb +++ b/test/capistrano/test_service_unit.rb @@ -17,6 +17,25 @@ def test_rails_env_defaults_to_stage assert_includes unit, "Environment='RAILS_ENV=preprod'" end + def test_default_env_is_expanded_by_the_server_shell + unit = generate_unit(stage_config: 'set :default_env, { rbenv_root: "$HOME/.rbenv", rbenv_version: "3.3.0" }') + + assert_includes unit, "Environment='RBENV_ROOT=#{Dir.home}/.rbenv'" + assert_includes unit, "Environment='RBENV_VERSION=3.3.0'" + end + + def test_default_env_keeps_double_quotes + unit = generate_unit(stage_config: %(set :default_env, { greeting: 'say "hi"' })) + + assert_includes unit, %(Environment='GREETING=say "hi"') + end + + def test_default_env_keeps_values_starting_with_dashes + unit = generate_unit(stage_config: 'set :default_env, { ruby_configure_opts: "--with-jemalloc=/usr/include/jemalloc --enable-yjit" }') + + assert_includes unit, "Environment='RUBY_CONFIGURE_OPTS=--with-jemalloc=/usr/include/jemalloc --enable-yjit'" + end + private def generate_unit(stage_config: "")