Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- Deploys no longer run `solid_queue:quiet` after `deploy:starting`. Solid Queue has no quiet mode: the `SIGTERM` it sends starts a shutdown, so jobs stopped for the whole deploy. The service is now stopped after `deploy:updated` and started after `deploy:published` ([#15](https://github.com/codeur/capistrano-solid_queue/pull/15)).
- Ruby 3.1 or later is required ([#15](https://github.com/codeur/capistrano-solid_queue/pull/15)).
- Capistrano 3.5 or later is required: `Capistrano::Plugin` doesn't exist before ([#15](https://github.com/codeur/capistrano-solid_queue/pull/15)).
- The service starts Solid Queue with `bin/jobs`, as Solid Queue documents, instead of `rake solid_queue:start`. The application needs `bin/jobs`: Rails 8 applications have it, and `bin/rails solid_queue:install` creates it. Run `cap <stage> solid_queue:install` again to update an installed service ([#16](https://github.com/codeur/capistrano-solid_queue/pull/16)).

### Removed

- `solid_queue:reload` and the `ExecReload=` line of the service: the `SIGTSTP` it sent didn't reload Solid Queue ([#15](https://github.com/codeur/capistrano-solid_queue/pull/15)).
- `solid_queue:quiet`: Solid Queue has no quiet mode, the `SIGTERM` it sent started a shutdown. `solid_queue:stop` stops Solid Queue gracefully ([#16](https://github.com/codeur/capistrano-solid_queue/pull/16)).

### Fixed

Expand All @@ -30,6 +32,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- `solid_queue:uninstall` removes only the unit of the service, not every file whose name starts with it ([#15](https://github.com/codeur/capistrano-solid_queue/pull/15)).
- `solid_queue:status` shows the status of a stopped service instead of failing ([#15](https://github.com/codeur/capistrano-solid_queue/pull/15)).
- The README lists the hooks the plugin registers ([#14](https://github.com/codeur/capistrano-solid_queue/pull/14)), tells to enable lingering for user services, and links to the right code of conduct ([#15](https://github.com/codeur/capistrano-solid_queue/pull/15)).
- The README says when the gem isn't needed (Solid Queue running inside Puma) and how to pass `bin/jobs` options ([#16](https://github.com/codeur/capistrano-solid_queue/pull/16)).
- The gem's changelog link points to this file, and the gem no longer ships its outdated RBS signature, `.standard.yml` and `Rakefile` ([#15](https://github.com/codeur/capistrano-solid_queue/pull/15)).

## [0.1.3] - 2026-11-09
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Capistrano Systemd integration for SolidQueue

Runs [Solid Queue](https://github.com/rails/solid_queue) in its own process, with `bin/jobs`, as a systemd service. The application needs `bin/jobs`: Rails 8 applications have it, and `bin/rails solid_queue:install` creates it. If Solid Queue runs inside Puma with its plugin (`plugin :solid_queue`), you don't need this gem: both would start a Solid Queue supervisor.

Adds the following capistrano commands:

```sh
cap solid_queue:disable # Disable solid_queue systemd service
cap solid_queue:enable # Enable solid_queue systemd service
cap solid_queue:generate # Generate solid_queue systemd service
cap solid_queue:install # Install solid_queue systemd service
cap solid_queue:quiet # Quiet solid_queue (start graceful termination)
cap solid_queue:restart # Restart solid_queue service via systemd
cap solid_queue:start # Start solid_queue service via systemd
cap solid_queue:status # Get solid_queue service status via systemd
Expand Down Expand Up @@ -122,6 +123,12 @@ set :solid_queue_service_unit_env_files, ["/var/www/my_app/shared/.env", "-/etc/

When they aren't set, the `:service_unit_env_vars` and `:service_unit_env_files` variables, also read by capistrano3-puma and capistrano-sidekiq, are used.

Solid Queue reads the options of `bin/jobs` from environment variables too, for instance:

```ruby
set :solid_queue_service_unit_env_vars, ["SOLID_QUEUE_CONFIG=config/calendar.yml", "SOLID_QUEUE_SKIP_RECURRING=true"]
```

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
Expand Down
7 changes: 0 additions & 7 deletions lib/capistrano/tasks/solid_queue.rake
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ namespace :solid_queue do # rubocop:disable Metrics
end
end

desc "Quiet solid_queue (start graceful termination)"
task :quiet do
on roles(fetch(:solid_queue_role)) do
plugin.execute_systemd("kill", "-s", "SIGTERM", fetch(:solid_queue_service_unit_name), raise_on_non_zero_exit: false)
end
end

desc "Start solid_queue service via systemd"
task :start do
on roles(fetch(:solid_queue_role)) do
Expand Down
2 changes: 1 addition & 1 deletion lib/capistrano/templates/solid_queue.service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Environment='RAILS_ENV=<%= fetch(:rails_env, fetch(:stage)) %>'
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
ExecStart=<%= capture(:echo, SSHKit.config.command_map[:bundle]).strip %> exec bin/jobs
ExecStop=/bin/kill -TERM $MAINPID
Environment=MALLOC_ARENA_MAX=2
<% fetch(:solid_queue_service_unit_env_vars).each do |variable| -%>
Expand Down
4 changes: 4 additions & 0 deletions test/capistrano/test_service_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def test_user_service_has_no_user_line
refute_match(/^User=/, generate_unit)
end

def test_service_starts_solid_queue_with_bin_jobs
assert_match(/^ExecStart=\S+.* exec bin\/jobs$/, generate_unit)
end

def test_service_has_no_reload_command
refute_includes generate_unit, "ExecReload"
end
Expand Down
19 changes: 6 additions & 13 deletions test/capistrano/test_systemctl_failure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,21 @@
class Capistrano::TestSystemctlFailure < Minitest::Test
include CapistranoProject

def test_quiet_goes_on_when_systemctl_fails
run_cap("solid_queue:quiet", stage_config: 'SSHKit.config.command_map[:"/bin/systemctl"] = "false"') do |output, status|
assert_includes output, "false --user kill -s SIGTERM app_solid_queue_preprod"
def test_status_goes_on_when_the_service_is_not_running
run_cap("solid_queue:status", stage_config: 'SSHKit.config.command_map[:"/bin/systemctl"] = "false"') do |output, status|
assert_includes output, "false --user status app_solid_queue_preprod"
assert status.success?, output
end
end

def test_quiet_goes_on_when_systemctl_fails_as_system_user
def test_status_goes_on_when_the_service_is_not_running_as_system_user
stage_config = <<~RUBY
set :solid_queue_systemctl_user, :system
SSHKit.config.command_map[:sudo] = "false"
RUBY

run_cap("solid_queue:quiet", stage_config: stage_config) do |output, status|
assert_includes output, "false /bin/systemctl kill -s SIGTERM app_solid_queue_preprod"
assert status.success?, output
end
end

def test_status_goes_on_when_the_service_is_not_running
run_cap("solid_queue:status", stage_config: 'SSHKit.config.command_map[:"/bin/systemctl"] = "false"') do |output, status|
assert_includes output, "false --user status app_solid_queue_preprod"
run_cap("solid_queue:status", stage_config: stage_config) do |output, status|
assert_includes output, "false /bin/systemctl status app_solid_queue_preprod"
assert status.success?, output
end
end
Expand Down
3 changes: 2 additions & 1 deletion test/capistrano/test_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ def test_deploy_stops_then_starts_the_service
end
end

def test_there_is_no_reload_task
def test_there_is_no_reload_or_quiet_task
run_cap("--tasks") do |output, status|
assert status.success?, output
assert_includes output, "solid_queue:restart"
refute_includes output, "solid_queue:reload"
refute_includes output, "solid_queue:quiet"
end
end
end
Loading