Post

Sidekiq in production: starting, stopping, and killing processes

Sidekiq in production: starting, stopping, and killing processes

Sidekiq series — part 1 of 4

  1. You are here — Infra: starting, stopping, killing
  2. Diagnosis via console
  3. Bulk manipulation of jobs and processes
  4. UI hacks in the dashboard

Before diving into queues and jobs, it’s good to have the basics of the Sidekiq process lifecycle solid — because most incidents start with “how do I bring this down without losing jobs”.

API documentation: github.com/mperham/sidekiq/wiki/API.

Starting Sidekiq

1
bundle exec sidekiq -d -L log/sidekiq.log -C config/sidekiq.yml
  • -d daemonizes (releases the terminal).
  • -L log/sidekiq.log points to the log file.
  • -C config/sidekiq.yml points to the configuration file (queues, concurrency, retries).

In production this command usually lives in a systemd unit or the app’s Procfile, but for local testing and VPS without an orchestrator it’s perfect.

1
2
3
ps -ef | grep sidekiq | grep busy | grep -v grep | awk '{print $2}' > tmp/sidekiq.pid
cat tmp/sidekiq.pid
bundle exec sidekiqctl stop tmp/sidekiq.pid

sidekiqctl stop waits for running jobs to finish (up to the configured timeout) before killing the process. It’s the polite way — preserves idempotency if a worker is in the middle of a non-atomic operation.

The pipe ps -ef | grep busy filters for the process that’s actually working (not the master), and awk '{print $2}' extracts just the PID.

Stopping via the OS (last resort)

1
2
ps -ef | grep sidekiq | grep busy | grep -v grep | awk '{print $2}'
kill -9 $(ps -ef | grep sidekiq | grep busy | grep -v grep | awk '{print $2}')

kill -9 is the red button: the process dies immediately, with no chance to finish what it was doing. A running job becomes a retry, so only do this when:

  • sidekiqctl stop is stuck and not responding
  • The process has become a zombie consuming memory without doing anything
  • You’re in a fire situation where bringing it down is more important than preserving idempotency

If you find yourself using kill -9 frequently, it’s worth investigating why stop is taking so long — it’s usually a job that doesn’t respect the timeout or a stuck database connection.

Next in the series

Sidekiq diagnosis via console — Sidekiq::Stats, grouping by class, listing processes and workers.

This post is licensed under CC BY 4.0 by the author.