> ## Documentation Index
> Fetch the complete documentation index at: https://docs.startmyvpn.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Queue Workers

> Running background job workers for server provisioning and VPN config generation.

StartMyVPN relies on Laravel queues for operations that run in the background:

* Installing OpenVPN / WireGuard on new servers
* Generating WireGuard peer configs for users
* Adding and removing users from servers when services change
* Enforcing speed limits on WireGuard peers
* Cleaning up expired VPN configurations

**Without a running queue worker, these operations will not execute.**

***

## Supervisor (recommended for production)

Supervisor keeps queue workers alive and restarts them if they crash.

### Install Supervisor

```bash theme={null}
sudo apt install supervisor -y
```

### Create a worker configuration

```bash theme={null}
sudo nano /etc/supervisor/conf.d/startmyvpn-worker.conf
```

```ini theme={null}
[program:startmyvpn-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/startmyvpn/artisan queue:work --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www-data
numprocs=2
redirect_stderr=true
stdout_logfile=/var/www/startmyvpn/storage/logs/worker.log
stopwaitsecs=3600
```

<Note>
  Adjust `numprocs` based on your server's CPU cores. 2 workers is sufficient for most deployments.
</Note>

### Start the workers

```bash theme={null}
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start startmyvpn-worker:*
```

### Check worker status

```bash theme={null}
sudo supervisorctl status
```

***

## Restarting workers after deployment

After deploying updates, restart the queue workers so they pick up code changes:

```bash theme={null}
php artisan queue:restart
# OR via supervisorctl
sudo supervisorctl restart startmyvpn-worker:*
```

***

## Development / testing

For local development, run the worker manually in a separate terminal:

```bash theme={null}
php artisan queue:work
```

Or process a single job at a time:

```bash theme={null}
php artisan queue:work --once
```
