Reader small image

You're reading from  Odoo 15 Development Essentials - Fifth Edition

Product typeBook
Published inFeb 2022
Reading LevelBeginner
PublisherPackt
ISBN-139781800200067
Edition5th Edition
Languages
Tools
Right arrow
Author (1)
Daniel Reis
Daniel Reis
author image
Daniel Reis

Daniel Reis has a degree in applied mathematics and an MBA. He has had a long career in the IT industry, mostly as a consultant implementing business applications in a variety of sectors. He has been working with Odoo (OpenERP at the time) since 2010 and is an active contributor to the Odoo Community Association (OCA), where he also serves as a board member. He is the managing director of Open Source Integrators, a leading open source and Odoo consultancy firm.
Read more about Daniel Reis

Right arrow

Chapter 15: Deploying and Maintaining Production Instances

In this chapter, you'll learn the basics of preparing an Odoo server for use in a production environment.

Setting up and maintaining servers is a non-trivial topic in itself and should be done by specialists. The information given here is not enough to ensure an average user can create a resilient and secure environment that hosts sensitive data and services.

The goal of this chapter is to introduce the most important configuration aspects and the best practices specific to Odoo deployments. This will help system administrators prepare their Odoo server hosts.

You will start by setting up the host system, and then you will install the Odoo prerequisites and Odoo itself. Ubuntu is a popular choice for cloud servers, and it will be used here. Then, the Odoo configuration file needs to be prepared. Until this point, the setup is similar to the one used for the development environment.

Next, Odoo needs to be configured...

Technical requirements

To follow this chapter, you will need a clean Ubuntu 20.04 server – for example, a virtual private server (VPS) hosted on the cloud.

The code and scripts used in this chapter can be found in the ch15/ directory of the GitHub repository at https://github.com/PacktPublishing/Odoo-15-Development-Essentials.

Preparing the host system

Odoo is usually deployed on Debian-based Linux systems. Ubuntu is a popular choice, and the latest long-term support (LTS) version is 20.04 Focal Fossa.

Other Linux distributions can also be used. The CentOS/Red Hat Enterprise Linux (RHEL) system is also popular in corporate circles.

The installation process requires elevated access, using the root superuser or the sudo command. When using a Debian distribution, the default login is root, which has administration access, and the command prompt shows #. On Ubuntu systems, the root account is disabled. Instead, the initial user is configured during the installation process and is a sudoer, meaning that the user is allowed to use the sudo command to elevate access and run commands with the root privileges.

Before starting the Odoo installation, the host system dependencies must be installed, and a specific user should be created to run the Odoo service.

The next section explains the required system...

Installing Odoo from source code

While Odoo provides Debian/Ubuntu and CentOS/RHEL system packages, installing from source code is a popular option due to the flexibility and control it provides.

Using source code provides better control over what is deployed and makes it easier to manage changes and fixes once in production. For example, it allows us to tie the deployment process to a Git workflow.

At this point, the Odoo system dependencies are already installed, and the database is ready to use. Now, the Odoo source code can be downloaded and installed, along with the required Python dependencies.

Let's see how to download the Odoo source code.

Downloading the Odoo source code

Sooner or later, your server will need upgrades and patches. A version control repository can be of great help when this time comes. We use git to get our code from a repository, just like we did when installing the development environment.

Next, we'll impersonate the odoo user...

Configuring Odoo

Once Odoo is installed, the configuration file to be used by the production service needs to be prepared.

The next sub-section provides guidance on how to do this.

Setting up the configuration file

Configuration files are expected to be in the /etc system directory. So, the Odoo production configuration file will be stored at /etc/odoo/odoo.conf.

To make it easier to see all of the available options, a default configuration file can be generated. This should be done by the user that will run the service.

If not done yet, create a session for the odoo user and activate the virtual environment:

$ sudo su - odoo
$ python3 -m venv /opt/odoo/env15

Now, the following command can be used to create a default configuration file:

(env15) $ odoo -c /opt/odoo/odoo.conf --save --stop-after-init

In the previous command, the -c option sets the location of the configuration file. If not given, it defaults to ~/.odoorc. The --save option writes the options...

Setting up Odoo as a system service

Odoo should run as a system service so that it is automatically started when the system boots and runs unattended, not requiring a user session.

In Debian/Ubuntu systems, the init system is responsible for starting services. Historically, Debian and its derived operating systems used sysvinit. This has changed, and recent Debian/Ubuntu systems use systemd. This is true for Ubuntu 16.04 and later.

To confirm that systemd is used in your system, try the following command:

$ man init

This command opens the documentation for the current init system in use, so you can check what is being used. At the top of the manual page, you should see SYSTEMD mentioned.

Let's continue with the systemd service configuration.

Creating a systemd service

If the operating system is recent – such as Debian 8 and Ubuntu 16.04 or later – systemd should be the init system being used.

To add a new service to the system, simply create...

Setting up an Nginx reverse proxy

While Odoo itself can serve web pages, it is recommended to have a reverse proxy in front of it. A reverse proxy receives the traffic from the clients and then forwards it to the Odoo servers responding to them. Doing this has several benefits.

On the security side, it can provide the following:

  • Handle (and enforce) HTTPS protocols to encrypt traffic.
  • Hide the internal network characteristics.
  • Act as an application firewall, limiting the URLs accepted for processing.

On the performance side, it can provide the following:

  • Cache static content, avoiding burdening the Odoo services with these requests and thereby reducing their load.
  • Compress content to speed up loading time.
  • Act as a load balancer, distributing load between several Odoo services.

There are several options that can serve as a reverse proxy. Historically, Apache has been a popular choice. In recent years, Nginx has become widely used and...

Configuring and enforcing HTTPS

Web traffic should not travel through the internet in plain text. When exposing the Odoo server on a network, HTTPS should be used to encrypt the traffic.

In some cases, it might be acceptable to use a self-signed certificate. Keep in mind that using a self-signed certificate provides limited security. While it allows for traffic to be encrypted, it has some security limitations, such as not being able to prevent man-in-the-middle attacks, or not being able to present security warnings on recent web browsers.

A more robust solution is to use a certificate signed by a recognized authority. This is particularly important when running e-commerce websites. Another option is to use a Let's Encrypt certificate, and the Certbot program automates getting SSL certificates for it. See https://certbot.eff.org/instructions to learn more.

Next, we will see how to create a self-signed certificate, in case this is the preferred choice.

Creating a self...

Maintaining the Odoo service and modules

Once the Odoo server is up and running, it is expected for some maintenance to be needed – for example, installing or updating modules.

These actions involve some risk for the production system, and it is best to test them in a staging environment before applying in production. Let's start with a basic recipe to create a staging environment.

Creating a staging environment

The staging environment should be a copy of the production system and ideally should have its own dedicated server.

A simplification, which is safe enough for most cases, is to have the staging environment in the same server as the production system.

To create a copy of the odoo-prod production database as the odoo-stage database, use the following commands:

$ dropdb odoo-stage
$ createdb --owner=odoo odoo-stage
$ pg_dump odoo-prod | psql -d odoo-stage
$ sudo su - odoo
$ cd ~/.local/share/Odoo/filestore/
$ cp -r odoo-prod odoo-stage
$ exit

Note...

Summary

In this chapter, we learned about the additional steps required for setting up and running Odoo on a Debian-based production server. We looked at the most important settings in the configuration file, and we learned how to take advantage of the multiprocessing mode.

For improved security and scalability, we also learned how to use Nginx as a reverse proxy in front of Odoo server processes and how to configure it to use HTTPS-encrypted traffic.

Finally, some advice was provided on how to create a staging environment and perform updates to Odoo code or custom modules.

This covers the essentials of what's needed to run an Odoo server and provide a reasonably stable and secure service to your users. We can now use it to host our library management system!

Further reading

To learn more about Odoo, you should take a look at the official documentation at https://www.odoo.com/documentation. Some topics are covered in more detail there, and you'll find topics not covered in this book.

There are also other published books on Odoo that you might find useful. Packt Publishing has a few in its catalog, and in particular, Odoo Development Cookbook provides more advanced material on topics not discussed in this book. At the time of writing, the last edition available was for Odoo 14, which is available at https://www.packtpub.com/product/odoo-14-development-cookbook-fourth-edition/9781800200319.

Finally, Odoo is an open source product with a vibrant community. Getting involved, asking questions, and contributing is a great way not only to learn but also to build a business network. With this in mind, we should also mention the Odoo Community Association (OCA), which promotes collaboration and quality open source code. You can learn...

Why subscribe?

  • Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
  • Improve your learning with Skill Plans built especially for you
  • Get a free eBook or video every month
  • Fully searchable for easy access to vital information
  • Copy and paste, print, and bookmark content

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com for more details.

At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Odoo 15 Development Essentials - Fifth Edition
Published in: Feb 2022Publisher: PacktISBN-13: 9781800200067
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Daniel Reis

Daniel Reis has a degree in applied mathematics and an MBA. He has had a long career in the IT industry, mostly as a consultant implementing business applications in a variety of sectors. He has been working with Odoo (OpenERP at the time) since 2010 and is an active contributor to the Odoo Community Association (OCA), where he also serves as a board member. He is the managing director of Open Source Integrators, a leading open source and Odoo consultancy firm.
Read more about Daniel Reis