Laravel Queue Workers — systemd Template Notes

Posted by Spacened in Misc Dev via Web

### system admin notes

I’m using templated systemd units so I can spin up a queue worker per site without duplicating config.
Example below uses **34a.xyz** so replace with whatever domain your queue is one.

---

## Service file

`/etc/systemd/system/laravel-queue@.service`

```ini
[Unit]
Description=Laravel Queue Worker for %i
After=network.target

[Service]
User=www-data
Group=www-data
Restart=always
ExecStart=/usr/bin/php /home/frank/htdocs/%i/artisan queue:work --sleep=3 --tries=3 --timeout=90
WorkingDirectory=/home/frank/htdocs/%i
StandardOutput=append:/var/log/laravel-queue-%i.log
StandardError=append:/var/log/laravel-queue-%i.err.log

[Install]
WantedBy=multi-user.target
```

`%i` just expands to whatever comes after the `@` when I start the service.
So `laravel-queue@34a.xyz.service` → `%i = 34a.xyz`.

---

## Commands I actually use

Start it:

```bash
sudo systemctl start laravel-queue@34a.xyz.service
```

Enable on boot:

```bash
sudo systemctl enable laravel-queue@34a.xyz.service
```

Restart after deploys:

```bash
sudo systemctl restart laravel-queue@34a.xyz.service
```

Check status:

```bash
sudo systemctl status laravel-queue@34a.xyz.service
```

Tail logs:

```bash
sudo journalctl -u laravel-queue@34a.xyz.service -f
```

---

## Notes to self

* Each site gets its own worker. Keeps logs clean and easy to restart.
* If I update PHP or artisan path, only need to touch the template once.
* Remember to reload systemd after edits:

```bash
sudo systemctl daemon-reload
```
* Use consistent naming across sites — `@34a.xyz`, `@keyclient`, `@planet-cms`, etc.
* Logs live in `/var/log/laravel-queue-<site>.log`.

---

That’s it.
Start → enable → forget about it.
If it crashes, systemd restarts it automatically.

Loading comments...