Startup Script for openerp-server



Need 2 files to make daemon services on Ubuntu for openerp-server:openerp-server,openerp-server.conf 

i)  openerp-server startup script, path: /etc/init.d/openerp-server
# OpenERP Server Startup script
# Provides: openerp-server
# Required-Start: $syslog
# Required-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OpenERP Server - the server
# Description: OpenERP is a complete ERP and CRM software
## END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC=openerp-server
NAME=openerp-server
DAEMON=/home/joyal/openerp-erver5.0.14/bin/openerp-server.py

# Specify the user name (Your Operating System user).
USER="joyal"

# Specifty an alternate config file (Default: ~/.openerp-serverrc)
CONFIGFILE="/etc/openerp-server.conf"

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

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

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
[ -f $CONFIGFILE ] || exit 0
checkpid() {
[ -f $PIDFILE ] || return 1
pid=`cat $PIDFILE`
[ -d /proc/$pid ] && return 0
return 1
}

# function that starts the daemon/service
if [ -f /lib/lsb/init-functions ] || [ -f /etc/gentoo-release ] ; then
do_start() {
start-stop-daemon --start --quiet --pidfile $PIDFILE \
--chuid $USER --background --make-pidfile \
--exec $DAEMON -- $DAEMON_OPTS
RETVAL=$?
sleep 5 # wait for few seconds
return $RETVAL
}

# Function that stops the daemon/service
do_stop() {
start-stop-daemon --stop --quiet --pidfile $PIDFILE --oknodo
RETVAL=$?
sleep 2 # wait for few seconds
rm -f $PIDFILE # remove pidfile
return $RETVAL
}
do_restart() {
start-stop-daemon --stop --quiet --pidfile $PIDFILE --oknodo
sleep 2 # wait for few seconds
rm -f $PIDFILE # remove pidfile

start-stop-daemon --start --quiet --pidfile $PIDFILE \
--chuid $USER --background --make-pidfile \
--exec $DAEMON -- $DAEMON_OPTS
RETVAL=$?
sleep 5 # wait for few seconds
return $RETVAL
}
else
do_start() {
$DAEMON $DAEMON_OPTS > /dev/null 2>&1 &
RETVAL=$?
sleep 5 # wait for few seconds
echo $! > $PIDFILE # create pidfile
return $RETVAL
}

do_stop() {
pid=`cat $PIDFILE`
kill -15 $pid

RETVAL=$?
sleep 2 # wait for few seconds
rm -f $PIDFILE # remove pidfile
return $RETVAL
}

do_restart() {
if [ -f $PIDFILE ]; then
do_stop
fi
do_start
return $?
}

fi
start_daemon() {
if [ -f $PIDFILE ]; then
echo "pidfile already exists: $PIDFILE"
exit 1
fi
echo -n "Starting $DESC: "
do_start
checkpid
if [ $? -eq 1 ]; then
rm -f $PIDFILE
echo "failed."
exit 1
fi
echo "done."
}

stop_daemon() {
checkpid
if [ $? -eq 1 ]; then
exit 0
fi
echo -n "Stopping $DESC: "
do_stop
if [ $? -eq 1 ]; then
echo "failed."
exit 1
fi
echo "done."
}

restart_daemon() {
echo -n "Reloading $DESC: "
do_restart
checkpid
if [ $? -eq 1 ]; then
rm -f $PIDFILE
echo "failed."
exit 1
fi
echo "done."
}

status_daemon() {
echo -n "Checking $DESC: "
checkpid
if [ $? -eq 1 ]; then
echo "stopped."
else
echo "running."
fi
}

case "$1" in
start) start_daemon ;;
stop) stop_daemon ;;
restart|force-reload) restart_daemon ;;
status) status_daemon ;;
*)

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

# vim: sts=4 st=4 et

ii) configuration file, path: /etc/openerp-server.conf 

#Here I have commented some options, you can remove comments and try it.
[options]

# Paths options
root_path = /home/joyal/openerp-erver5.0.14/bin
#addons_path = /home/joyal/openerp-erver5.0.14/bin/addons
#pg_path = None

# Email options
#smtp_server = localhost
#smtp_port = 25
#smtp_user = False
#smtp_password = False
#email_from = False

# Log options
#verbose = True
#syslog = False
#log_level = debug
#logfile = /var/log/openerp-server/openerp-server.log

# Database connection
db_host = localhost
db_name = False
db_user = postgres
db_password = postgres
db_maxconn = 64
#list_db = False

# Security options
#admin_passwd = admin
#secure = False
#secure_pkey_file = server.pkey
#secure_cert_file = server.cert

# Demo options
without_demo = False
demo = {}

# Report options
#csv_internal_sep = ,
reportgz = False

# Debug
debug_mode = True

# Connection options
port = 8069
netport = 8070
soap = False
xmlrpc = True
netrpc = True
netinterface =
interface =
login_message = False

# Cache options
cache_timeout = 100000

# Translations
#translate_modules = ['all']

# Price
price_accuracy = 2
# vim: sts=4 st=4 et


After creating this two files, run this command on gnome-terminal(it will start /etc/init.d/openerp-server script every time booting your computer):

$ sudo update-rc.d openerp-server defaults

That's it!!! We have make startup script for openerp-server. I have implemented this script on ubuntu10.04, try it on other flavours of ubuntu and enjoy playing with OpenERP.

Comments

  1. this is possible for 6.1, i m using bazar version of openerp?

    ReplyDelete

Post a Comment

Popular posts from this blog

Geeta - Sea of divine knowledge and Motivation for Life time

OpenERP 7 installation

ERP Functional workshop at Singapore