Skip to content

Make systemd unit configurable and fix :system-mode defaults - #6

Closed
floriancrusius wants to merge 2 commits into
codeur:mainfrom
floriancrusius:feature/configurable-systemd-unit
Closed

floriancrusius wants to merge 2 commits into
codeur:mainfrom
floriancrusius:feature/configurable-systemd-unit

Conversation

@floriancrusius

Copy link
Copy Markdown

Summary

  • Configurable env vars in the systemd unit — adds :solid_queue_service_unit_env_files and :solid_queue_service_unit_env_vars (inspired by capistrano-sidekiq). Both fall back to shared :service_unit_env_files / :service_unit_env_vars so multi-plugin setups can share one source.
  • Configurable command — :solid_queue_command (default "rake solid_queue:start") so SolidQueue >= 0.4 setups can switch to "bin/jobs" without templating.
  • Fix [Install] WantedBy= — now multi-user.target in :system mode (previously always default.target, which prevented boot activation of system units).
  • Fix :system mode running as root — now renders User=<solid_queue_user> (defaults to :run_as, then Capistrano's :user).
  • Breaking: Capistrano's default_env is no longer auto-rendered into the unit; MALLOC_ARENA_MAX=2 is no longer hardcoded. Pass what you need explicitly via the new hooks. RAILS_ENV is still derived from the current stage.

Test plan

  • bundle exec cap <stage> solid_queue:generate and inspect the generated solid_queue.service — verify Environment=, EnvironmentFile=, ExecStart=, User=, WantedBy= look correct in both :user and :system modes.
  • bundle exec cap <stage> solid_queue:install on a staging host, systemctl --user status <unit> (or sudo systemctl status … for :system) — service comes up.
  • Set :solid_queue_service_unit_env_vars, ["FOO=bar"] and confirm it lands in the rendered unit.
  • Set :solid_queue_command, "bin/jobs" on a SolidQueue-0.4+ app and confirm the process starts.

- Add :solid_queue_service_unit_env_files / :solid_queue_service_unit_env_vars
  for injecting EnvironmentFile= and Environment="KEY=VALUE" lines into the
  unit (inspired by capistrano-sidekiq). Both fall back to shared
  :service_unit_env_files / :service_unit_env_vars.
- Add :solid_queue_command (default "rake solid_queue:start") so setups on
  SolidQueue >= 0.4 can switch to "bin/jobs" without templating.
- Fix WantedBy: multi-user.target when running in :system mode (previously
  always default.target, which prevented boot activation of system units).
- Fix :system mode running the service implicitly as root — now uses
  :solid_queue_user (falls back to :run_as, then :user).
- Drop implicit rendering of Capistrano's default_env and the hardcoded
  MALLOC_ARENA_MAX=2; pass anything you need explicitly via the new hooks.
  RAILS_ENV is still derived from the current stage.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the SolidQueue systemd integration by making the generated unit file more configurable (command + environment injection) and by correcting :system-mode unit defaults so services can be enabled at boot and run as a non-root user.

Changes:

  • Add configuration for the systemd unit’s environment (:solid_queue_service_unit_env_files / :solid_queue_service_unit_env_vars) with fallbacks to shared :service_unit_env_* variables.
  • Add :solid_queue_command to control what runs after bundle exec (defaulting to rake solid_queue:start).
  • Adjust :system mode rendering (set User= and use WantedBy=multi-user.target) and document the breaking removal of rendering Capistrano default_env into the unit.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
README.md Documents new configuration knobs for command, user, and unit environment injection.
lib/capistrano/templates/solid_queue.service.erb Updates the unit template to use configurable env/files, configurable command, and corrected :system defaults (User=, WantedBy=).
lib/capistrano/solid_queue.rb Introduces new default variables for command/user/unit env sources.
CHANGELOG.md Records new configuration features, fixes, and breaking behavior change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/capistrano/solid_queue.rb Resolved
Comment thread README.md Resolved
Comment thread README.md Resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@burisu

burisu commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for this PR. We checked each point and took over what holds up in #13:

  • User= in :system mode, taken from the user Capistrano connects with on the server (id -un). With fetch(:run_as, fetch(:user)), the line is empty when the user comes from server "…", user: "…" or from the SSH config, and systemd then still runs the service as root.
  • :solid_queue_service_unit_env_vars and :solid_queue_service_unit_env_files, with your fallback to :service_unit_env_vars and :service_unit_env_files.
  • The service description with the application and the stage.
  • A Configuration section in the README.

Left out:

  • WantedBy=multi-user.target: in our tests on systemd 245 and 255, an enabled system service with WantedBy=default.target starts at boot.
  • Dropping default_env and MALLOC_ARENA_MAX=2 from the unit: installed services would change silently at their next solid_queue:install. The new variables can override both instead.
  • RAILS_ENV=<stage>: since 0.1.3, RAILS_ENV comes from :rails_env (The SolidQueue background job does not reference the environment in RAILS_ENV #8).
  • :solid_queue_command: rake solid_queue:start still exists in Solid Queue 1.7.2.

The CHANGELOG entries of #13 credit this PR.

@burisu burisu closed this Nov 9, 2026
@burisu

burisu commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Closed in favor of #13, now merged into main. Thanks again.

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.

3 participants