| name | frappe-ops-bench |
| description | Use when running bench commands, managing sites, configuring multi-tenancy, or setting up domains. Prevents misconfigured bench environments, broken site routing, and DNS mismatches. Covers bench CLI commands, site creation, bench init, multi-tenancy setup, DNS-based routing, common-site-config. Keywords: bench, site, multi-tenancy, domains, bench init, bench new-site, bench setup, common_site_config, bench command not working, site setup, multi-tenant, domain routing, new site..
|
| license | MIT |
| compatibility | Claude Code, Claude.ai Projects, Claude API. Frappe v14-v16. |
| metadata | {"author":"OpenAEC-Foundation","version":"2.0"} |
Bench CLI Complete Reference
Complete bench CLI reference for site management, app lifecycle, configuration, and multi-tenancy.
Version: v14/v15/v16
Quick Reference: Essential Commands
| Task | Command |
|---|
| Create bench | bench init myproject --frappe-branch version-15 |
| Create site | bench new-site mysite.localhost --admin-password admin |
| Set default site | bench use mysite.localhost |
| Get app | bench get-app erpnext --branch version-15 |
| Install app | bench --site mysite install-app erpnext |
| Start dev server | bench start |
| Run migrations | bench --site mysite migrate |
| Build assets | bench build --app myapp |
| Backup site | bench --site mysite backup |
| Restore backup | bench --site mysite restore /path/to/backup.sql.gz |
| Open console | bench --site mysite console |
| Open DB shell | bench --site mysite mariadb |
| Check scheduler | bench doctor |
| View pending jobs | bench show-pending-jobs |
| Update everything | bench update |
| Drop site | bench drop-site mysite --force |
Workflow 1: Creating a New Bench
bench init myproject --frappe-branch version-15
bench init myproject --frappe-branch version-15 --python python3.11
cd myproject
What bench init creates:
myproject/
โโโ apps/ # Installed Frappe apps (frappe is default)
โโโ sites/ # All sites and shared config
โ โโโ common_site_config.json
โโโ config/ # Redis, Procfile, supervisor configs
โโโ env/ # Python virtual environment
โโโ logs/ # Log files
โโโ Procfile # Process definitions for bench start
Critical Rules
- ALWAYS specify
--frappe-branch to pin Frappe version
- ALWAYS run commands from inside the bench directory
- NEVER run bench commands as root โ use a dedicated frappe user
Workflow 2: Site Management
Creating Sites
bench new-site mysite.localhost --admin-password admin
bench new-site mysite.localhost --db-name mysite_db --admin-password admin
bench new-site mysite.localhost --mariadb-root-password rootpass --admin-password admin
bench new-site mysite.localhost --admin-password admin --install-app erpnext
Setting Default Site
bench use mysite.localhost
export FRAPPE_SITE=mysite.localhost
Dropping a Site
bench drop-site mysite.localhost --force
Site Directory Structure
sites/mysite.localhost/
โโโ site_config.json # Site-specific config (db credentials)
โโโ private/ # Auth-required files, backups
โโโ public/ # Publicly accessible files
โโโ locks/ # Scheduler lock files
โโโ task-logs/ # Scheduler task logs
Workflow 3: App Management
bench get-app erpnext --branch version-15
bench get-app https://github.com/org/custom-app.git --branch main
bench --site mysite install-app erpnext
bench --site mysite list-apps
bench --site mysite uninstall-app custom_app
bench remove-app custom_app
bench switch-to-branch version-15 erpnext frappe
bench exclude-app custom_app
bench include-app custom_app
Critical Rules
- ALWAYS
get-app before install-app โ get downloads, install activates
- ALWAYS backup before
uninstall-app โ it deletes app-related data
- NEVER manually delete app folders โ use
bench remove-app
Workflow 4: bench update: What It Does
bench update
bench update --pull --app erpnext
bench update --no-build
bench update --no-backup
bench update --reset
bench update executes these steps in order:
- Backup all sites
- Pull latest code for all apps (
git pull)
- Install Python/Node requirements
- Build static assets (
bench build)
- Run migrations on all sites (
bench migrate)
- Restart bench processes
Critical Rules
- ALWAYS run
bench update in a screen/tmux session โ it takes time
- NEVER use
--reset in production without understanding it does git reset --hard
- ALWAYS test updates on staging first
Workflow 5: bench migrate
bench --site mysite migrate
bench --site all migrate
bench --site mysite ready-for-migration
What bench migrate does:
- Runs schema sync (DocType changes โ database)
- Runs patches (data migrations)
- Rebuilds search index
- Syncs translations
- Rebuilds Dashboard cache
When to Migrate
- After
bench update (done automatically)
- After changing hooks.py
- After adding/modifying DocTypes
- After pulling code changes
- NEVER skip migrate after code changes โ leads to schema mismatches
Workflow 6: bench build
bench build
bench build --app myapp
bench build --app myapp --production
bench watch
When to Build
- After changing JS/CSS files
- After
bench get-app (done automatically)
- After modifying
package.json
- ALWAYS build after modifying client-side assets
Workflow 7: Console and Database Access
bench --site mysite console
bench --site mysite console --autoreload
bench --site mysite mariadb
bench --site mysite postgres
bench --site mysite execute myapp.tasks.daily_cleanup
bench --site mysite execute myapp.api.process --kwargs '{"name": "INV-001"}'
bench --site mysite request GET /api/resource/User
Workflow 8: Backup and Restore
bench --site mysite backup
bench backup-all-sites
bench --site mysite backup --backup-encryption-key mykey
bench --site mysite restore /path/to/database.sql.gz
bench --site mysite restore /path/to/database.sql.gz \
--with-public-files /path/to/files.tar \
--with-private-files /path/to/private-files.tar
bench --site mysite partial-restore /path/to/database.sql.gz
Critical Rules
- ALWAYS backup before
bench update, uninstall-app, or drop-site
- Backups older than 24 hours auto-deleted by default โ configure
keep_backups_for_hours
- ALWAYS test restore on a staging site before relying on a backup
Workflow 9: Scheduler and Background Jobs
bench --site mysite scheduler enable
bench --site mysite scheduler disable
bench --site mysite scheduler pause
bench --site mysite scheduler resume
bench doctor
bench show-pending-jobs
bench --site mysite purge-jobs
bench --site mysite trigger-scheduler-event hourly
bench worker --queue short
Workflow 10: Multi-Tenancy
DNS-Based Routing (Recommended)
bench config dns_multitenant on
bench new-site site1.example.com --admin-password admin
bench new-site site2.example.com --admin-password admin
bench setup nginx
sudo service nginx reload
Requests are routed by matching the Host header to site names.
Port-Based Routing (Alternative)
bench config dns_multitenant off
bench new-site site2.localhost --admin-password admin
bench set-nginx-port site2.localhost 8082
bench setup nginx
sudo service nginx reload
Custom Domain Mapping
bench setup add-domain site1.example.com --site mysite
bench setup nginx
sudo service nginx reload
Configuration: common_site_config.json
Located at sites/common_site_config.json โ applies to ALL sites.
Essential Keys
| Key | Default | Purpose |
|---|
background_workers | 1 | Number of background job workers |
developer_mode | false | Auto-sync DocType changes to files |
dns_multitenant | false | Enable DNS-based multi-tenancy |
gunicorn_workers | 2 | Web server worker count (min: 2) |
maintenance_mode | 0 | Take all sites offline |
pause_scheduler | 0 | Pause job scheduler |
serve_default_site | โ | Default site when host not matched |
server_script_enabled | false | Enable Server Scripts |
scheduler_tick_interval | 60 | Seconds between scheduler checks |
webserver_port | 8000 | Development server port |
socketio_port | 9000 | Socket.IO port |
live_reload | false | Auto-reload on asset rebuild |
Redis Configuration
| Key | Default |
|---|
redis_cache | redis://localhost:13000 |
redis_queue | redis://localhost:11000 |
redis_socketio | redis://localhost:13000 |
Setting Config Values
bench config set-common-config -c background_workers 4
bench config set-common-config -c developer_mode 1
bench --site mysite set-config developer_mode 1
bench --site mysite set-config maintenance_mode 1
bench --site mysite show-config
Configuration: site_config.json
Per-site config at sites/<sitename>/site_config.json.
Mandatory Keys
| Key | Purpose |
|---|
db_type | mariadb or postgres |
db_name | Database name |
db_password | Database password |
Important Optional Keys
| Key | Purpose |
|---|
admin_password | Administrator initial password |
host_name | Full site URL (with protocol) |
install_apps | Apps to install on restore/reinstall |
allow_cors | CORS origins ("*", URL, or array) |
max_file_size | Upload limit (default: 10MB) |
mute_emails | Disable all outgoing email |
logging | Debug level (0-2, level 2 shows SQL queries) |
Environment Variable Overrides
Environment variables override config files. Key mappings: FRAPPE_REDIS_QUEUE, FRAPPE_REDIS_CACHE, FRAPPE_DB_HOST, FRAPPE_DB_PORT, FRAPPE_DB_NAME, FRAPPE_DB_PASSWORD.
Priority: Environment Variable > site_config.json > common_site_config.json > Default
Production Setup
sudo bench setup production frappe-user
bench setup lets-encrypt mysite.example.com
sudo bench restart
bench disable-production
Version Differences
| Feature | V14 | V15 | V16 |
|---|
| bench init | Yes | Yes | Yes |
| Scheduler tick interval | ~240s | ~240s | 60s |
db_user config (separate) | No | No | Yes |
console --autoreload | No | Yes | Yes |
trim-tables command | No | Yes | Yes |
trim-database command | No | Yes | Yes |
request command | No | Yes | Yes |
| Gettext translations | No | No | Yes |
Reference Files