Tags

, ,


Update ubuntu serve

  1. sudo apt-get update && sudo apt-get upgrade

Open Corresponding Firewall Ports

In this case we’re using Odoo’s default port 8069, but this could be any port you specify later in the configuration file.

  1. sudo ufw allow ssh
  2. sudo ufw allow 8069/tcp
  3. sudo ufw enable

Install Database and Server Dependencies

Now we’re going to install the PostgreSQL database and other necesary server libraries usingapt-get

  1. sudo apt-get install subversion git bzr bzrtools python-pip postgresql postgresql-server-dev-9.3 python-all-dev python-dev python-setuptools libxml2-dev libxslt1-dev libevent-dev libsasl2-dev libldap2-dev pkg-config libtiff5-dev libjpeg8-dev libjpeg-dev zlib1g-dev libfreetype6-dev liblcms2-dev liblcms2-utils libwebp-dev tcl8.6-dev tk8.6-dev python-tk libyaml-dev fontconfig

Create Odoo User and Log Directory

  1. Create the Odoo system user.
    sudo adduser --system --home=/opt/odoo --group odoo
  2. Create the log directory.
    sudo mkdir /var/log/odoo

Install Odoo Server Files from Source

  1. Change to the Odoo directory, in our case:
    cd /opt/odoo/
  2. Clone the Odoo files on your server.
    sudo git clone https://www.github.com/odoo/odoo --depth 1 --branch 9.0 --single-branch .

Using git brings a great flexibility because any time a new upgrade is available you only need to pull that branch, you can even install a different one alongside the production version, just change the destination directory and the--branch X.x flag. Before doing any operation remember to make a full backup of your database and custom files.

Create PostgreSQL User

  1. Switch to postgres user.
    1
    sudo su - postgres
    
  2. But, if you’re deploying a Production server you may want to set a strong password for the database user.
    1
    createuser odoo -U postgres -dRSP
    
  3. You’ll be prompted for a password, save it, we’ll need it shortly.

    In the scenario of a testing or development environment you could create a user with no password usingcreateuser odoo -U postgres -dRS.

  4. Press CTRL+D to exit from postgres user session.

If you want to run multiple Odoo instances on the same Linode remember to check pg_hba.conf and change it according your needs.

Specific Dependencies for Odoo Applications

Using pip instead of apt-get will guarantee that your installation has the correct versions needed. We’ll also abstain of using Ubuntu’s packaged versions of Wkhtmltopdf and node-less.

Install Python Dependencies

Install Python libraries using the following commands:

1
2
sudo pip install -r /opt/odoo/doc/requirements.txt
sudo pip install -r /opt/odoo/requirements.txt

Install Less CSS via nodejs and npm.

  1. Download nodejs installation script from nodesource.
    1
    wget -qO- https://deb.nodesource.com/setup | sudo bash -
    
  2. Now that our repository list is updated install nodejs using apt-get.
    1
    sudo apt-get install nodejs
    
  3. Time to install a newer version of Less via npm.
    1
    sudo npm install -g less less-plugin-clean-css
    

Install Updated Wkhtmltopdf Version

  1. Switch to a temporally directory of your choice.
    1
    cd /tmp
    
  2. Download the recommended version of wkhtmltopdf for Odoo server, currently 0.12.1
    1
    sudo wget http://download.gna.org/wkhtmltopdf/0.12/0.12.1/wkhtmltox-0.12.1_linux-trusty-amd64.deb
    
  3. Install the package using dpkg.
    1
    sudo dpkg -i wkhtmltox-0.12.1_linux-trusty-amd64.deb
    
  4. To function properly we’ll need to copy the binaries to an adequate location.
    1
    2
    sudo cp /usr/local/bin/wkhtmltopdf /usr/bin
    sudo cp /usr/local/bin/wkhtmltoimage /usr/bin
    

Odoo Server Configuration

  1. Copy the included configuration file to a more convenient location changing it’s name toodoo-server.conf
    1
    sudo cp /opt/odoo/debian/openerp-server.conf /etc/odoo-server.conf
    
  2. Next we need to modify the configuration file. The finished file should look similar to this depending on your deploying needs:
    /etc/odoo-server.conf
    1
    2
    3
    4
    5
    6
    7
    8
    9
    [options]
    admin_passwd = admin
    db_host = False 
    db_port = False
    db_user = odoo
    db_password = <PostgreSQL_user_password>
    addons_path = /opt/odoo/addons
    logfile = /var/log/odoo/odoo-server.log
    xmlrpc_port = 8069
    
    • admin_passwd = admin This is the password that allows database operations.
    • db_host = False Unless you plan to connect to a different database server address, leave this line untouched.
    • db_port = False Odoo uses PostgreSQL default port 5432, change only if necessary.
    • db_user = odoo Database user, in this case we used the default name.
    • db_password = The previously created PostgreSQL user password.
    • addons_path = We need to modify this line to read: addons_path = /opt/odoo/addons. Add</path/to/custom/modules> if needed.
    • We need to include the path to log files adding a new line:logfile = /var/log/odoo/odoo-server.log
    • Optionally we could include a new line specifying the Odoo Frontend port used for connection: xmlrpc_port = 8069. This only makes sense if you’re planning to run multiple Odoo instances (or versions) on the same server. For normal installation you could skip this line and Odoo will connect by default to port 8069.

Odoo Boot Script

Next step is creating a boot script odoo-server to gain control over Odoo behavior and use it at server startup and shutdown.

/etc/init.d/odoo-server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
### BEGIN INIT INFO
# Provides: odoo-server
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Odoo ERP
# Description: Odoo is a complete ERP business solution.
### END INIT INFO

PATH=/bin:/sbin:/usr/bin
# Change the Odoo source files location according your needs.
DAEMON=/opt/odoo/openerp-server
# Use the name convention of your choice 
NAME=odoo-server
DESC=odoo-server

# Specify the user name (Default: odoo).
USER=odoo

# Specify an alternate config file (Default: /etc/odoo-server.conf).
CONFIGFILE="/etc/odoo-server.conf"

# pidfile
PIDFILE=/var/run/$NAME.pid

# Additional options that are passed to the Daemon.
DAEMON_OPTS="-c $CONFIGFILE"

[ -x $DAEMON ] || exit 0
[ -f $CONFIGFILE ] || exit 0

checkpid() {
[ -f $PIDFILE ] || return 1
pid=`cat $PIDFILE`
[ -d /proc/$pid ] && return 0
return 1
}

case "${1}" in
start)
echo -n "Starting ${DESC}: "

start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
--chuid ${USER} --background --make-pidfile \
--exec ${DAEMON} -- ${DAEMON_OPTS}

echo "${NAME}."
;;

stop)
echo -n "Stopping ${DESC}: "

start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \
--oknodo

echo "${NAME}."
;;

restart|force-reload)
echo -n "Restarting ${DESC}: "

start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \
--oknodo

sleep 1

start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
--chuid ${USER} --background --make-pidfile \
--exec ${DAEMON} -- ${DAEMON_OPTS}

echo "${NAME}."
;;

*)
N=/etc/init.d/${NAME}
echo "Usage: ${NAME} {start|stop|restart|force-reload}" >&2
exit 1
;;
esac

exit 0

Odoo Files Ownership and Permissions

  1. Change the odoo-server file permissions and ownership so only root can write to it, while odoo user will only be able to read and execute it.
    1
    2
    sudo chmod 755 /etc/init.d/odoo-server
    sudo chown root: /etc/init.d/odoo-server
    
  2. Since odoo user will run the application, change its ownership accordingly.
    1
    sudo chown -R odoo: /opt/odoo/
    
  3. We should set odoo user as the owner of log directory as well.
    1
    sudo chown odoo:root /var/log/odoo
    
  4. Finally, we should protect the server configuration file changing its ownership and permissions so no other non-root user can access it.
    1
    2
    sudo chown odoo: /etc/odoo-server.conf
    sudo chmod 640 /etc/odoo-server.conf
    

Testing the Server

  1. It’s time to check that everything is working as expected, lets start the Odoo server.
    1
    sudo /etc/init.d/odoo-server start
    
  2. Let’s take a look at log file to verify no errors occurred.
    1
    cat /var/log/odoo/odoo-server.log
    
  3. Now we can check if the server stops properly too.
    1
    sudo /etc/init.d/odoo-server stop
    
  4. Enter the same command again.
    1
    cat /var/log/odoo/odoo-server.log
    

Running Boot Script at Server Startup and Shutdown

  1. If the Odoo server log doesn’t indicate any problem we can continue and make the Boot script start and stop with the server.
    1
    sudo update-rc.d odoo-server defaults
    
  2. It’s a good idea to restart our Linode to see if everything is working.
    1
    sudo shutdown -r now
    
  3. Once restarted verify one more time the log file.
    1
    cat /var/log/odoo/odoo-server.log
    

Testing Odoo Frontend

  1. Open a new browser window and enter in the address bar:
    1
    http://<your_domain_or_IP_address>:8069
    
Advertisements