Repository navigation
Run the :system service as the Capistrano user and make its environment configurable - #13
Merged
Merged
Conversation
… son environnement Repris de la PR #6, après vérification de chaque point dans systemd (Ubuntu 24.04, systemd 255) : - en mode :system, l'unité n'avait pas de User= et Solid Queue tournait en root. Elle reçoit maintenant User=<id -un sur le serveur> : la valeur de la PR #6 (fetch(:run_as, fetch(:user))) donnait « User= » vide quand l'utilisateur vient de server "…", user: ou de la config SSH, et systemd lance alors le service en root ; - :solid_queue_service_unit_env_vars et :solid_queue_service_unit_env_files ajoutent des lignes Environment= et EnvironmentFile=, par défaut :service_unit_env_vars et :service_unit_env_files comme capistrano3-puma et capistrano-sidekiq. Elles viennent après les variables du template, donc les remplacent ; - la description du service nomme l'application et le stage. Non repris : WantedBy=multi-user.target (un service système en WantedBy=default.target démarre au boot sous systemd 245 et 255), l'abandon de default_env et de MALLOC_ARENA_MAX=2, :solid_queue_command (rake solid_queue:start existe toujours dans Solid Queue 1.7.2) et set_if_empty :solid_queue_systemctl_user, :user (sans effet : le code ne compare qu'à :system). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Section Configuration du README : variables et valeurs par défaut lues dans set_defaults, service utilisateur ou système, ordre et priorité des variables d'environnement du service (vérifiés dans systemd 255 : une ligne Environment= plus loin remplace la précédente, EnvironmentFile= remplace Environment=, un fichier absent sans « - » empêche le démarrage). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Takes over what holds up in #6, after checking each point.
Changes
:systemmode: the unit getsUser=<output of id -un on the server>. Without aUser=line, systemd runs the service as root. Make systemd unit configurable and fix :system-mode defaults #6 usedfetch(:run_as, fetch(:user)), which renders an emptyUser=when the user comes fromserver "…", user: "…"or from the SSH config, and systemd then runs the service as root too.:solid_queue_service_unit_env_varsand:solid_queue_service_unit_env_filesaddEnvironment="…"andEnvironmentFile=lines, after the template's own variables so they override them. They default tofetch(:service_unit_env_vars, [])andfetch(:service_unit_env_files, []), as in capistrano3-puma 8.1.0 (puma/systemd.rb:20-21) and capistrano-sidekiq 3.2.0 (sidekiq/systemd.rb:25-26).default_envandMALLOC_ARENA_MAX=2stay in the unit.Description=SolidQueue background job for <application> (<stage>).Not taken from #6
WantedBy=multi-user.targetin:systemmode: an enabled system service withWantedBy=default.targetstarts at boot on Ubuntu 20.04 (systemd 245) and 24.04 (systemd 255), withgraphical.targetormulti-user.targetas default target. The change wouldn't change behavior.default_envandMALLOC_ARENA_MAX=2from the unit: installed services would change silently at their nextsolid_queue:install. The new variables can override them instead.RAILS_ENV=<stage>: since 0.1.3, it comes from:rails_env(Use :rails_env for RAILS_ENV in the systemd service #9).:solid_queue_command:rake solid_queue:startstill exists in Solid Queue 1.7.2 (lib/solid_queue/tasks.rb:13).set_if_empty :solid_queue_systemctl_user, :user: no effect, every read of the variable compares it with:system.Tests
test/capistrano/test_service_unit.rb(cap preprod solid_queue:generatein a minimal Capistrano project): description;User=<current user>in:systemmode and noUser=line in user mode;Environment="…"andEnvironmentFile=lines, written afterMALLOC_ARENA_MAX=2; fallback to the shared variables. The four tests on new lines failed before the change.:systemcondition, theUser=line, theEnvironment=orEnvironmentFile=line, or either default makes at least one test fail.ExecStartreplaced by a command that dumpsid -unandenv): the service runs as theUser=user;MALLOC_ARENA_MAX=4from the new variable overrides the template's2; a variable fromEnvironmentFile=overrides the same one fromEnvironment=; a missing-/…file is ignored.User=line or an empty one, a system service runs as root; a missing environment file without-keeps the service from starting; a root-owned 0644 log file still receives the output of aUser=deployservice.bundle exec rake(tests + standard): green locally (Ruby 4.0.6).Upgrade
Installed
:systemservices keep running as root untilcap <stage> solid_queue:installruns again. Files the service created as root may then need to be given back to the deploy user. Solid Queue 1.7.2 writes no pid file by default (supervisor_pidfileis unset).🤖 Generated with Claude Code