Set up Odoo as a system service

For a production instance, it is very important that the Odoo server gets started when the computer reboots. On current Linux systems, there are different ways of achieving this, depending on the distribution and the server setup; either it is an init script, or a systemd configuration. This recipe shows how to do both.

Getting ready

We assume that you followed the first two recipes to install and configure your Odoo instance. Especially the deployed source of Odoo, which is at /home/odoo/odoo-prod/project/src/odoo/, and the configuration file of the instance, which is at /home/odoo/odoo-prod/project/production.conf. The scripts also makes use of the start-odoo script created in step 9 of the Install Odoo for production recipe.

You will first need to find out which initialization system is running on your system. For this, run the following:

$ dpkg -l systemd

If the last line of output starts with ii systemd, then systemd is available on your system. Otherwise, you are probably running sysvinit (on a system running an old Debian variant) or upstart (on an Ubuntu-based system).

How to do it…

Now that you know which version of the initialization system you are running, you can choose how to configure Odoo.

Configuring systemd to start Odoo

To configure systemd to start Odoo, you need to perform the following steps:

  1. As root, create a file called /lib/systemd/system/odoo.service, with the following contents:
    [Unit]
    Description=Odoo 9.0
    After=postgresql.service
    
    [Service]
    Type=simple
    User=odoo
    Group=odoo
    ExecStart=/home/odoo/odoo-prod/project/bin/start-odoo
    
    [Install]
    WantedBy=multi-user.target
    
  2. As root, register the service:
    # systemctl enable odoo.service
    
  3. As root, start the service:
    # service odoo start
    
  4. To stop the service, you can run the following:
    # service odoo stop
    

Configuring sysvinit or upstart to start Odoo

To configure sysvinit or upstart to start Odoo, you need to perform the following steps:

  1. As root, copy the init file provided by Odoo to /etc/init.d:
    # cp src/odoo/debian/init /etc/init.d/odoo
    # chmod +x /etc/init.d/odoo
    
  2. As root, edit that file to change the environment variables defined at the top of the script (we only list the ones which need changing as follows, with the appropriate values):
    DAEMON=/home/odoo/odoo-prod/project/bin/start-odoo
    
  3. In the same file, also modify the _start function as follows:
    function _start() {
        start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER:$USER --background --make-pidfile --exec $DAEMON
    }
    
  4. As root, register the daemon with sysvinit or upstart:
    # update-rc.d odoo defaults
    
  5. As root, start the service:
    # /etc/init.d/odoo start
    
  6. If you want to stop the service, you run the following:
    # /etc/init.d/odoo stop
    

How it works…

The three configurations, systemd, sysvinit, and upstart, use some configuration files or scripts to know which programs must run when the server boots. The configurations provided in the recipe will need small adaptations to match the paths of your instance.

Note

Don't forget to reboot your server and check that Odoo is properly started!

There's more…

If you are using the buildout method described in the Use buildout for repeatable builds recipe, you will need to adapt the paths to use the start_odoo script created by the recipe.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.124.145