Chuyển đến nội dung

Bài 6 · Concepts and Setup

odoo.conf and Command-Line Options

Configure Odoo with odoo.conf and command-line options: addons path, database, workers, logging and dev mode, plus the shell and scaffold commands.

Typing a long odoo-bin command each time gets old quickly. Odoo reads the same settings from a configuration file, usually called odoo.conf, and lets command-line options override it. Knowing the important options also helps you read the hosting documentation and server logs with confidence.

This lesson lists the settings you will use most, shows a real configuration file, and introduces odoo-bin sub-commands such as shell and scaffold, which you will use again in later chapters.

How settings are combined

Odoo builds its configuration in layers. A later layer overrides an earlier one:

  1. Built-in defaults.
  2. The configuration file (-c path/to/odoo.conf, or ~/.odoorc by default).
  3. Command-line options.

To save the current settings of a run into a file, start the server with --save: Odoo writes the effective configuration to the file given by -c (or the default location).

A configuration file

The file uses the INI format with one section, [options]. Option names use underscores here, for example db_host, while the command line uses dashes or underscores (--db_host and --db-host both work in current versions, check --help for your series). This is a real example (read-only):

INI
[options]
; --- security ---
admin_passwd = change-me-long-random-string
; --- database ---
db_host = localhost
db_port = 5432
db_user = odoo
db_password = secret
db_name = demo
; --- paths ---
addons_path = /opt/odoo/odoo/addons,/opt/odoo/addons,/opt/custom-addons
data_dir = /var/lib/odoo
; --- network ---
http_port = 8069
; --- logging ---
logfile = /var/log/odoo/odoo.log
log_level = info

The settings you will meet again and again:

Option Meaning
admin_passwd Master password for the database manager (back up, drop, restore). Always change it
addons_path Comma-separated folders searched for modules
db_host, db_port, db_user, db_password How to reach PostgreSQL
db_name A fixed database to use (useful for single-database servers)
http_port The port for the web interface
data_dir Where the filestore and sessions are stored
workers Number of worker processes; 0 means the simple threaded mode used for development
limit_time_cpu, limit_time_real, limit_memory_soft Safety limits for workers
list_db Whether the database manager and list are available (set False in production)
proxy_mode Trust the reverse proxy's forwarded headers
log_level, logfile How much to log and where

Useful command-line options

  • -d NAME select the database.
  • -i module1,module2 install modules when starting.
  • -u module update (upgrade) modules: it reloads their data files and updates tables. Use -u all to update everything (slow).
  • --dev=all or --dev=xml,reload development helpers: reload Python code when files change and read XML from disk again.
  • --stop-after-init run the initialisation or update and exit. Great for scripts and tests.
  • --test-enable and --test-tags run automated tests.
  • --without-demo=all skip demo data when creating a database.

Sub-commands

odoo-bin has sub-commands in addition to starting the server (read-only examples):

Terminal
# Interactive Python shell with the ORM ready (env is already defined)
./odoo-bin shell -d demo

# Create the skeleton of a new module in the custom addons folder
./odoo-bin scaffold library_book custom-addons

# Print the effective configuration
./odoo-bin --help

The shell is very handy: inside it you can run env["res.partner"].search([]) and explore objects interactively. The scaffold command creates a ready-made module folder, which the next lessons dissect.

A runnable stand-in: layered configuration

The layered override is the one part you can model directly. This stand-in merges defaults, a file and command-line options with Python's configparser, then prints the result.

Python Stand-in: defaults, file and command line

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that the password is masked when printed. Do the same in your own scripts: never print secrets into logs.

Stand-in: validating addons_path

A very common start-up error is a wrong addons_path: a folder that does not exist or a module folder given instead of its parent. The next stand-in checks a list of paths against a fake file tree.

Python Stand-in: check an addons_path

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The last path in the example is a module folder, not an addons folder. Odoo expects the parent: the folder that contains module folders.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. Which source of settings wins when the same option is given in odoo.conf and on the command line?

    Command-line options override the configuration file, which overrides the defaults.
  2. 2. What does -u my_module do?

    -u (--update) upgrades an installed module. Uninstalling is done from the Apps menu.
  3. 3. What should addons_path contain?

    Each entry is a directory that holds module directories. Pointing it at a module folder itself is a common mistake.
  4. 4. Why set list_db = False in production?

    It prevents people from listing, dropping or backing up databases through the web interface.

Summary

  • Odoo reads defaults, then odoo.conf, then command-line options; later layers win.
  • Key settings: addons_path, database connection, admin_passwd, http_port, workers, list_db.
  • -i installs, -u updates, --dev helps development, --stop-after-init is useful for scripts.
  • odoo-bin shell opens an interactive ORM session; scaffold creates a module skeleton.
  • addons_path entries are parent folders of modules.

Next: Databases and Developer Mode

Theo dõi tiến độ của bạn

Tạo tài khoản miễn phí để đánh dấu bài đã học và tiếp tục từ chỗ bạn dừng lại trên mọi thiết bị.