DEV Community

Cover image for Restarting Laravel Queue Workers Safely
shirish rai
shirish rai

Posted on • Edited on

Restarting Laravel Queue Workers Safely

When managing background processes or queue workers in a production environment, Supervisor is often the go-to process control system. But if you’ve ever worked with Supervisor on a Linux server, you've likely come across these two commands:

sudo service supervisor restart
sudo supervisorctl restart [program_name]
Enter fullscreen mode Exit fullscreen mode

They might look similar at a glance — both contain the word restart — but they operate at very different levels and are used in very different situations. Let’s break down what each command does, when to use it, and what to avoid in a production environment.


🔍 1. sudo service supervisor restart

✅ What it does

This command restarts the Supervisor daemon itself — not just the programs it manages. Think of it as turning Supervisor completely off and then back on.

When you run this:

  • Supervisor stops all processes it’s managing.
  • It re-reads your main config file (/etc/supervisor/supervisord.conf) and any included .conf files.
  • Then it restarts itself and everything it controls.

⚠️ Why it can be risky

This method is disruptive, especially in production environments. All processes — queue workers, background services, long-running jobs — are stopped and restarted. If any job is mid-processing, it could be lost.

✅ When to use it

  • You've made changes to Supervisor's configuration files and need them to take effect.

  • The Supervisor daemon is unresponsive or has crashed.

  • You want to restart all managed processes at once and you're okay with downtime.

🧠 Pro Tip

Use this during scheduled maintenance windows or in development/staging environments.


🔍 2. sudo supervisorctl restart [program_name]

✅ What it does

This command is much more targeted. It allows you to restart a single program without restarting the entire Supervisor service.
Example:

sudo supervisorctl restart laravel-worker
Enter fullscreen mode Exit fullscreen mode

This stops just the laravel-worker process and starts it again — leaving other services untouched.

✅ Why it's safer

Because it doesn’t restart the Supervisor daemon itself, this command is less disruptive and far more appropriate for production use.

You can also use:

sudo supervisorctl restart all
Enter fullscreen mode Exit fullscreen mode

To restart all managed processes, without restarting Supervisor itself.

✅ When to use it

  • You’ve updated your application code (like deploying a new Laravel version).

  • You want to restart just one service/worker.

  • You want to minimize disruption while keeping services running.


🔃 3. php artisan queue:restart

✅ What it does

Gracefully tells Laravel to stop and restart all queue workers, by updating a timestamp in the cache. Running workers detect this and shut themselves down after finishing their current job.
This command does not stop the underlying process — Supervisor or another process monitor will automatically restart the worker afterward.

📦 How it works

  • Laravel stores a timestamp (in the cache) for the last restart request.
  • Each worker checks this before picking up a new job.
  • If the cache timestamp is newer than when the worker started, it exits.
  • Supervisor (or systemd) sees that it exited and starts a new one.

✅ Why it’s safe and graceful

It allows in-progress jobs to finish before shutting down, preventing job loss or data corruption.

✅ When to use it

  • During deployment after code changes
  • When updating environment variables or job logic

🧠 Example Deployment Snippet

If you're using Laravel queues (and you should be using Supervisor to manage them), it's best to restart your workers using Supervisor commands rather than manually killing and starting workers.

php artisan queue:restart
sudo supervisorctl restart laravel-worker
Enter fullscreen mode Exit fullscreen mode

This combo ensures Laravel gracefully restarts workers, and Supervisor brings them back up cleanly.

🔚 Conclusion

Both sudo service supervisor restart and sudo supervisorctl restart are valuable tools — but like any powerful tool, use them wisely.

  • Use supervisorctl restart [program_name] for safe, minimal-disruption restarts.
  • Use service supervisor restart when you're updating Supervisor itself or fixing a broader issue.

Understanding the difference can help you avoid unintentional downtime and keep your production services running smoothly.

Top comments (0)