Monday 20 March 2017

Running Odoo 8.0 as a Service

Step 1: Install postgres and pgAdmin.

First execute the below command to update the package lists from the repositories

sudo apt-get update

Execute below command to install postgres and pgAdmin3

sudo apt-get install postgresql-9.1 pgadmin3

Step 2: Start Postgres

sudo su postgres

Step 3: Create user in postgres provide password for that user.

createuser -P -s -e ubuntu (Same as Machine name)

Step 4: Open new terminal and install python requirements by following commands.

sudo apt-get install python-dateutil python-decorator python-docutils python-feedparser \python-gdata python-gevent python-imaging python-jinja2 python-ldap python-libxslt1 python-lxml \python-mako python-mock python-openid python-passlib python-psutil python-psycopg2 python-pybabel \python-pychart python-pydot python-pyparsing python-pypdf python-reportlab python-requests \python-simplejson python-tz python-unittest2 python-vatnumber python-vobject python-werkzeug \python-xlwt python-yaml wkhtmltopdf


Step 5: Download openERP/odoo for Linux platform from the below site.

https://www.odoo.com/page/download

Or you can download source from github which is more preferable options that provides more flexibility during development and deployment of any module.

https://github.com/odoo/odoo/releases

Extract the server and rename it to “odoo”. Copy this folder to “/opt/odoo/” folder(If “odoo” folder in “/opt” does not exists then create this folder).

Step 6: Create configuration file for openerp server.

Create “openerp-server.conf” file and copy and paste below content.

[options]
; This is the password that allows database operations:
admin_passwd = password for admin
db_host = localhost
db_port = 5432
db_user = ubuntu
db_password = password for postgres database user
addons_path = /opt/odoo/odoo/openerp/addons (It may change according to your downloaded bundle)
logfile = /var/log/openerp/openerp-server.log

Provide password in the admin_passwd. Here, db_user = ubuntu and db_password = ***** are for the user created in postgres for ubuntu user.

Copy “openerp-server.conf” file to “/etc” folder, and change odoo server’s folder ownership and permissions by executing below commands. Execute useradd command only if the you want to give other user permission for that folder.

useradd -d /opt/odoo/odoo -s /bin/bash ubuntu
chown ubuntu: -R /opt/odoo/odoo
chown ubuntu: /etc/openerp-server.conf
chmod 640 /etc/openerp-server.conf

Step 7: Install the boot script

Create an “openerp-server” file with the following content and copy-paste this file in “/etc/init.d/” folder.
#!/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: Business Applications
# Description: ODOO Business Applications.
### END INIT INFO
PATH=/bin:/sbin:/usr/bin
DAEMON=/opt/odoo/odoo/openerp-server (It may change according to your downloaded bundle)
NAME=openerp-server
DESC=openerp-server

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

# Specify an alternate config file (Default: /etc/odoo-server.conf).
CONFIGFILE="/etc/openerp-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


Make this file executable using the following commands :
chmod 755 /etc/init.d/openerp-server
chown ubuntu: /etc/init.d/openerp-server

Step 8: Create a log file for the odoo server and make this file executable using the following commands.

mkdir /var/log/openerp
chown ubuntu: /var/log/openerp
touch /var/log/openerp/openerp-server.log
chmod 777 /var/log/openerp/openerp-server.log

Step 9: Start the server

/etc/init.d/openerp-server start

To view logs of the server execute below command.

tail -f /var/log/openerp/openerp-server.log

Now you can access the odoo server by hitting the “localhost:8069” in web browser.

Step 10: Once the server started successfully then make this server start and stop automatically using below command.

sudo update-rc.d openerp-server defaults

No comments:

Post a Comment