Skip to Content

10 - Understanding the Odoo Server Service and Workers

Welcome back! Up until now, we have been starting our Odoo server by typing python3 odoo-bin in the terminal. That is perfect for development.

But think about a live production server for a moment. What happens if you close your terminal window? The Odoo server shuts down immediately. What happens if the Ubuntu server restarts after a power outage? Odoo stays offline until you manually log back in and type the command again.

For a professional setup, Odoo needs to run in the background automatically. And even more importantly, it needs to handle hundreds of users at the exact same time. Today, we are going to learn how to achieve this using systemd services and multiprocessing workers.


1. Creating the Odoo Service (Running in the Background)

In Ubuntu, background programs are managed by a system called systemd. We need to create a simple configuration file that tells Ubuntu exactly how to start, stop, and restart our Odoo server.

To do this, we create a file called odoo.service in the /etc/systemd/system/ directory.

Here is what a professional Odoo 19 service file looks like:

[Unit]
Description=Odoo 19 Open Source ERP and CRM
Requires=postgresql.service
After=network.target postgresql.service

[Service]
Type=simple
SyslogIdentifier=odoo
PermissionsStartOnly=true
User=odoo
Group=odoo
# This is the exact command systemd will run in the background:
ExecStart=/home/odoo/odoo-dev/venv/bin/python3 /home/odoo/odoo-dev/odoo/odoo-bin -c /home/odoo/odoo-dev/odoo.conf
StandardOutput=journal+console

[Install]
WantedBy=multi-user.target

Once this file is saved, you no longer use odoo-bin directly in production. Instead, you use these powerful terminal commands:

  • sudo systemctl start odoo (Starts the server in the background)

  • sudo systemctl stop odoo (Shuts it down gracefully)

  • sudo systemctl restart odoo (Restarts the server to apply new Python code)

  • sudo systemctl enable odoo (Tells Ubuntu to start Odoo automatically if the server reboots!)


2. The Problem with a Single Process

By default, Odoo runs as a single Python process.

Because of how Python is built (specifically, something called the Global Interpreter Lock, or GIL), a single Python process can only do one thing at a time. If User A clicks "Print 100-page PDF Report", the server is completely busy generating that PDF. If User B tries to load the homepage at that exact second, their browser will just spin and wait until the PDF is finished.

In a business with 50 employees, this single-process bottleneck will cause the system to freeze constantly.


3. The Solution: Multiprocessing (Workers)

To fix this, we edit our odoo.conf file and turn on Workers.

When you assign workers, Odoo acts like a restaurant manager. Instead of cooking all the meals itself, the main Odoo process spawns several "worker" processes (the chefs). When a user requests a webpage, the manager hands the request to an available worker. Now, multiple users can be served at the exact same time!

How many workers do you need?

There is a strict mathematical formula for this based on your server's hardware. Do not just guess! Formula: (Number of CPU Cores * 2) + 1

If your cloud server has 4 CPU Cores, your odoo.conf file should look like this:

[options]
; 4 CPUs * 2 + 1 = 9 workers
workers = 9

; Reserve 1 separate worker just for background tasks (like sending emails)
max_cron_threads = 1

Note: One worker can generally handle about 6 concurrent users. So, 9 workers can comfortably support about 50-60 active employees clicking around at the same time.


4. The Rules of Enabling Workers

Turning on workers changes how Odoo behaves at a fundamental level. You must prepare your server for it:

  1. RAM Consumption: Every worker is a full copy of the Odoo application in your server's memory. If one worker takes 500MB of RAM, 9 workers will consume 4.5GB of RAM. Make sure your server has enough memory before turning this up!

  2. Resource Limits: You must tell the workers when to give up. If a worker gets stuck on a bad piece of code, it needs to be killed and replaced. Add these limits to your odoo.conf:

limit_time_cpu = 600
limit_time_real = 1200
limit_memory_hard = 2684354560
limit_memory_soft = 2147483648


5. Pro-Tips & Advice

💡 PRO TIP: Workers Require a Reverse Proxy (Nginx) The moment you set workers = 2 or higher in your odoo.conf, Odoo's built-in web server stops handling certain live-chat and long-polling features properly. To use workers professionally, you must put a web server like Nginx or Apache in front of Odoo, and you must add proxy_mode = True to your odoo.conf.

  • Checking the Logs: When Odoo is running as a background service, you can't see the errors on your screen anymore. To watch the live logs as they happen, use this command: sudo journalctl -u odoo -f (The -f means "follow" the log as it updates).

Rating
0 0

There are no comments for now.

to be the first to leave a comment.