Tuesday, April 26, 2016

Odoo Boot Script

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

Odoo Server Configuration
Copy the included configuration file to a more convenient location changing it’s name to 
copy the inculded configuration file to a more conven
odoo-server.conf

sudo cp /opt/odoo/debian/openerp-server.conf /etc/odoo-server.conf


Next we need to modify the configuration file. The finished  file should look similar to this depending on your deploying needs:

[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


Next step is creating a boot script odoo-server to gain control over Odoo behavior and use it at server startup and shutdown.
FILE :- /etc/init.d/odoo-server

#!/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
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.


sudo chmod 755 /etc/init.d/odoo-server
sudo chown root: /etc/init.d/odoo-server

Since odoo user will run the application, change its ownership accordingly.

sudo chown -R odoo: /opt/odoo/

We should set odoo user as the owner of log directory as well.

sudo chown odoo:root /var/log/odoo

Finally, we should protect the server configuration file changing its ownership and permissions so no other non-root user can access it.

sudo chown odoo: /etc/odoo-server.conf
sudo chmod 640 /etc/odoo-server.conf


Testing the Server

It’s time to check that everything is working as expected, lets start the Odoo server.
sudo /etc/init.d/odoo-server start

Let’s take a look at log file to verify no errors occurred.
cat /var/log/odoo/odoo-server.log

Now we can check if the server stops properly too.
sudo /etc/init.d/odoo-server stop

Enter the same command again.
cat /var/log/odoo/odoo-server.log

Running Boot Script at Server Startup and Shutdown

If the Odoo server log doesn’t indicate any problem we can continue and make the Boot script start and stop with the server.
sudo update-rc.d odoo-server defaults

It’s a good idea to restart our server to see if everything is working.
sudo shutdown -r now

Once restarted verify one more time the log file.
cat /var/log/odoo/odoo-server.log

Testing Odoo Frontend

Open a new browser window and enter in the address bar:
http://<your_domain_or_IP_address>:port number
default port is 8069 for odoo

1 comment: