From 45be1a8103fa4506e4cabfa5899f0213a734202e Mon Sep 17 00:00:00 2001 From: Brice TEXIER Date: Mon, 9 Nov 2026 09:29:06 +0100 Subject: [PATCH 1/2] =?UTF-8?q?D=C3=A9velopper=20les=20valeurs=20de=20defa?= =?UTF-8?q?ult=5Fenv=20dans=20le=20service=20systemd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit capistrano-rbenv ajoute RBENV_ROOT="$HOME/.rbenv" à default_env. Dans les commandes Capistrano, SSHKit exporte chaque valeur entre guillemets doubles, donc le shell du serveur remplace $HOME. Le template écrivait la valeur telle quelle : l'unité contenait RBENV_ROOT=$HOME/.rbenv, alors que son ExecStart (rbenv exec bundle) passe par le shell et contient le chemin absolu. Issue #1 : remplacer ExecStart par le shim bundle, qui exporte lui-même RBENV_ROOT, faisait démarrer le service. Chaque valeur passe maintenant par `printf %s ""` sur le serveur, avec les guillemets doubles échappés comme le fait SSHKit. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + lib/capistrano/templates/solid_queue.service.erb | 2 +- test/capistrano/test_service_unit.rb | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) 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..548e1b6 100644 --- a/test/capistrano/test_service_unit.rb +++ b/test/capistrano/test_service_unit.rb @@ -17,6 +17,19 @@ 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 + private def generate_unit(stage_config: "") From e120e03707ce88978aa9795fd87313a92e0aec04 Mon Sep 17 00:00:00 2001 From: Brice TEXIER Date: Mon, 9 Nov 2026 09:33:29 +0100 Subject: [PATCH 2/2] Tester une valeur de default_env qui commence par -- MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit capistrano-asdf ajoute à default_env RUBY_CONFIGURE_OPTS, dont la valeur commence par « --with-jemalloc » ou « --enable-yjit ». Depuis le commit précédent, la valeur passe par printf sur le serveur : le test vérifie, sur le printf de la CI (Linux), qu'elle arrive intacte dans l'unité. Co-Authored-By: Claude Opus 5.5 --- test/capistrano/test_service_unit.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/capistrano/test_service_unit.rb b/test/capistrano/test_service_unit.rb index 548e1b6..41ccb8c 100644 --- a/test/capistrano/test_service_unit.rb +++ b/test/capistrano/test_service_unit.rb @@ -30,6 +30,12 @@ def test_default_env_keeps_double_quotes 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: "")