A production instance is expected to handle a significant workload. By default, the server runs one process and can use only one CPU core for processing, because of the Python language GIL. However, a multiprocess mode is available so that concurrent requests can be handled. The option workers=N
sets the number of worker processes to use. As a guideline, you can try setting it to 1+2*P
, where P
is the number of processors. The best setting to use needs to be tuned for each case, since it depends on the server load and what other load intensive services are running on the server, such as PostgreSQL.
It is better to set workers too high for the load than too low. The minimum should be 6 due to the parallel connections used by most browsers, and the maximum is generally be limited by the amount of RAM on the machine.
There a few limit-*
config parameters to tune the workers. Workers are recycled when they reach these limits—the corresponding process is stopped, a new one is started. This protects the server from memory leaks and from particular processes overloading the server resources.
The official documentation already provides good advice on the tuning of the worker parameters, and you may refer to it for more details, at https://www.odoo.com/documentation/10.0/setup/deploy.html.
Next, we will want to set up Odoo as a system service and have it started automatically when the system boots.
In Ubuntu/Debian, the init
system is responsible, to start services. Historically, Debian (and derived operating systems) has used sysvinit
and Ubuntu has used a compatible system called Upstart
. Recently, this has changed, and the init
system used in the latest version is now systemd
.
This means that there are two different ways to install a system service, and you need to pick the correct one depending on the version of your operating system.
On the last Ubuntu stable version, 16.04, we should be using systemd
. But older versions such as 14.04 are still used in many cloud providers, so there is a good chance that you might need to use it.
To check if systemd
is used in your system try this command:
$ man init
This opens the documentation for the currently used init
system, and you will be able to check what is being used.
If the operating system you are using is recent, such as Debian 8 or Ubuntu 16.04, you should be using systemd
for init
system.
To add a new service to the system, we just need to create a file describing it. Create a /lib/systemd/system/odoo.service
file with the following content:
[Unit] Description=Odoo After=postgresql.service [Service] Type=simple User=odoo Group=odoo ExecStart=/home/odoo/odoo-10.0/odoo-bin -c /etc/odoo/odoo.conf [Install] WantedBy=multi-user.target
Next, we need to register the new service:
$ sudo systemctl enable odoo.service
To start this new service use following command:
$ sudo systemctl odoo start
And to check its status run this:
$ sudo systemctl odoo status
Finally, if you want to stop it, use this command:
$ sudo systemctl odoo stop
If you are using an older operating system, such as Debian 7, Ubuntu 15.04, or even 14.04, chances are that your system is sysvinit
on Upstart
. For this purpose, both should behave the same way. Many cloud VPS services are still based on Ubuntu 14.04 images, so this might be a scenario you may encounter when deploying your Odoo server.
Many cloud VPS services are still based on Ubuntu 14.04 images, so this might be a scenario you may encounter when deploying your Odoo server.
The Odoo source code includes an init
script used for the Debian packaged distribution. We can use it as our service init
script with minor modifications, as follows:
$ sudo cp /home/odoo/odoo-10.0/debian/init /etc/init.d/odoo $ sudo chmod +x /etc/init.d/odoo
At this point, you might want to check the content of the init
script. The key parameters are assigned to variables at the top of the file. A sample is as follows:
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin DAEMON=/usr/bin/odoo NAME=odoo DESC=odoo CONFIG=/etc/odoo/odoo.conf LOGFILE=/var/log/odoo/odoo-server.log PIDFILE=/var/run/${NAME}.pid USER=odoo
These variables should be adequate and we will prepare the rest of the set up with their default values in mind. But of course, you can change them to better suit your needs.
The USER
variable is the system user under which the server will run. We have already created the expected odoo
user.
The DAEMON
variable is the path to the server executable. Our actual executable to start Odoo is in a different location, but we can create a symbolic link to it:
$ sudo ln -s /home/odoo/odoo-10.0/odoo-bin /usr/bin/odoo $ sudo chown -h odoo /usr/bin/odoo
The CONFIG
variable is the configuration file to use. In a previous section, we created a configuration file in the default expected location: /etc/odoo/odoo.conf
.
Finally, the LOGFILE
variable is the directory where log files should be stored. The expected directory is /var/log/odoo
that we created when we were defining the configuration file.
Now we should be able to start and stop our Odoo service as follows:
$ sudo /etc/init.d/odoo start Starting odoo: ok
Stopping the service is done in a similar way, as shown in the following:
$ sudo /etc/init.d/odoo stop Stopping odoo: ok
In Ubuntu, the service
command can also be used:
$ sudo service odoo start $ sudo service odoo status $ sudo service odoo config
We now only need to make this service start automatically on system boot:
$ sudo update-rc.d odoo defaults
After this, when we reboot our server, the Odoo service should be started automatically and with no errors. It's a good time to check that all is working as expected.
At this point, we could confirm if our Odoo instance is up and responding to requests.
If Odoo is running properly, we should now be able to get a response from it and see no errors in the log file. We can check inside the server if Odoo is responding to HTTP requests using the following command:
$ curl http://localhost:8069 <html><head><script>window.location = '/web' + location.hash;</script></head></html>
And to see what is in the log file we can use the following:
$ sudo less /var/log/odoo/odoo-server.log In case you are just starting with Linux, you will like to know that you can follow what is going on in the log file using tail -f:
$ sudo tail -f /var/log/odoo/odoo-server.log