Adding the --save option when starting an Odoo server saves the configuration used to the ~/.openerp_serverrc file. We can use the file as a starting point for our server configuration, which will be stored on /etc/odoo, as shown in the following code: $ sudo mkdir /etc/odoo
$ sudo chown $(whoami) /etc/odoo
$ cp ~/.openerp_serverrc /etc/odoo/openerp-server.conf
This will have the configuration parameters to be used by our server instance. The following are the parameters essential for the server to work correctly:
• addons_path: This is a comma-separated list of the paths where modules will be looked up, using the directories from left to right. This means that the leftmost directories in the list have a higher priority.
• xmlrpc_port: This is the port number at which the server will listen. By default, port 8069 is used.
• log_level: This is the log verbosity. The default is the info level, but using the debug_rpc level, while more verbose, adds important information to monitor server performance.
The following settings are also important for a production instance:
• admin_passwd: This is the master password to access the web client database management functions. It's critical to set this with a strong password or an empty value to deactivate the function.
• dbfilter: This is a Python-interpreted regex expression to filter the
databases to be listed. For the user to not be prompted to select a database, it should be set with ^dbname$, for example, dbfilter = ^v8dev$.
• logrotate=True: This will split the log into daily files and keep only one month of log history.
• data_dir: This is the path where the attachment files are stored. Remember to have backups on it.
• without_demo=True: This should be set in production environments so that new databases do not have demo data on them.
When using a reverse proxy, the following settings should be considered: • proxy_mode=True: This is important to set when using a reverse proxy. • xmlrpc-interface: This sets the addresses that will be listened to. By
default, it listens to all 0.0.0.0, but when using a reverse proxy, it can be set to 127.0.0.1 in order to respond only to local requests.
A production instance is expected to handle significant workload. By default, the server runs one process and is capable of handling only one request at a time. 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 services are running on the server (such as PostgreSQL).
We can check the effect of the settings made by running the server with the -c or --config option as follows:
$ ./odoo.py -c /etc/odoo/openerp-server.conf
Setting up as a system service
Next, we will want to set up Odoo as a system service and have it started automatically when the system boots.
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 ~/odoo-prd/odoo/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/openerp-server NAME=odoo DESC=odoo CONFIG=/etc/odoo/openerp-server.conf LOGFILE=/var/log/odoo/odoo-server.log PIDFILE=/var/run/${NAME}.pid USER=odoo
The USER variable is the system user under which the server will run, and you probably want to change it. The other variables should be adequate and we will prepare the rest of the setup having their default values in mind. DAEMON is the path to the server executable, CONFIG is the configuration file to use, and LOGFILE is the log file location.
The DAEMON executable can be a symbolic link to our actual Odoo location, as shown in the following:
$ sudo ln -s ~/odoo-prd/odoo/odoo.py /usr/bin/openerp-server $ sudo chown $(whoami) /usr/bin/openerp-server
Next we must create the LOGFILE directory as follows: $ sudo mkdir /var/log/odoo
$ sudo chown $(whoami) /etc/odoo
Now we should be able to start and stop our Odoo service as follows:
$ sudo /etc/init.d/odoo start Starting odoo: ok
We should now be able to get a response from the server and see no errors in the log file, as shown in the following:
$ curl http://localhost:8069
<html><head><script>window.location = '/web' + location.hash;</script></head></html>
$ less /var/log/odoo/odoo-server.log # show the log file
Stopping the service is done in a similar way, as shown in the following:
$ sudo /etc/init.d/odoo stop Stopping odoo: ok
Ubuntu provides the easier to remember service command
to manage services. If you prefer, you can instead use sudo service odoo start and sudo service odoo stop. 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.