Guió d'administració d'OpenERP V6

Descripció

Nom del guió

/etc/init.d/openerp-server6

Paràmetre obligatori

start|stop|restart|status, on:

  • start: Engega un servidor aturat.
  • stop: Atura un servidor engegat.
  • restart: Reengega un servidor. Si està engegat, primer l'atura.
  • status: Informa de l'estat de funcionament d'un servidor.
Paràmetres opcionals

[nom_instancia_oerp [-u nom_modul [-d nom_basedades […]]]]

  • nom_instancia_oerp: Si s'introdueixen paràmetres opcionals, aquest ha de ser el primer. Es refereix al nom de la instància sobre la que s'ha d'executar l'acció.
  • -u nom_modul: Per actualitzar un mòdul concretament (nom_modul) o tots (all).
  • -d nom_basedades: Per actuar sobre una base de dades determinada (nom_basedades) o totes (all).
  • […]: Altres paràmetres opcionals que es poden introduir al fitxer /bin/openerp-server.py en executar-lo.
Exemple de funcionament
$ sudo /etc/init.d/openerp-server6 start oerp6 -u training_dining_hall -d dining_hall

Aquesta comanda engegaria la instància oerp6 actualitzant el mòdul training_dining_hall de la base de dades dining_hall.

$ sudo /etc/init.d/openerp-server6 restart oerp6 -u training_dining_hall &

Aquesta comanda aturaria i engegaria la instància oerp6 actualitzant el mòdul training_dining_hall. Si s'utilitza per debugar codi de mòduls en desenvolupament, permet continuar treballant a la consola sense aturar el servidor i sense deixar de veure els logs. Per tornar a reengegar el servidor, no caldria aturar-lo amb Ctrl-C, només seria necessari tornar a executar aquesta comanda.

Configuració

Permet la seva configuració per poder adaptar-lo a les necessitats de cada moment.

Desenvolupament

Si estem desenvolupant mòduls per a OpenERP, podem necessitar veure els logs del que està passant a la mateixa consola on engeguem el servidor. Per fer-ho, s'ha de posar la variable LOG a TRUE, en cas contrari, es posa a FALSE. En un servidor de producció s'ha de posar a FALSE pel seu correcte funcionament.

Exemple:

# Module's Development
# FALSE or TRUE
LOG=TRUE
Instal·lació d'un nou servidor

Quan instal·lem un nou servidor, pot ser útil saber què està passant quan intentem engegar el servidor per saber què està fallant. Llavors s'ha de descomentar el set -x i comentar el set -e. Un cop la instal·lacio ja funciona correctament, s'ha de tornar a posar com estava.

Exemple:

# Installation debuger enabled
#set -x
# Installation debuger disabled
set -e
Fitxer de configuració per multiples instàncies

Només s'utilitza per servidors saas, si no és el cas, s'han de comentar les dues línies de lectura del fitxer.

Exemple:

# If config file not exists, exit with error code 1
#[ ! -x /etc/openerp.conf ] && exit 1
# Load config file parameters
#. /etc/openerp.conf
Paràmetres de configuració del servidor

Aquests paràmetres són diferents de cada instal·lació, i per tant, s'ha de posar una especial atenció en el moment de posar els seus valors. Si la configuració es fa mitjançant el fitxer mencionat a l'apartat anterior, s'han de comentar tots. Són els següents:

  • NAME: És el nom que rebrà gairebé tots els fitxers i directoris d'instal·lació d'OpenERP.
  • SERVER: Igual que abans, s'afegeix després del NAME per indicar els directoris i fitxers a utilitzar. Al client web posarem “web”.
  • CONFIGDIR: Directori on es desaran els diferents fitxers de configuració de les instàncies que s'han d'arrencar al servidor. Els noms dels fitxers han de tenir la següent estructura ”.${NAME}_${SERVER}rc_nomInstancia”.
  • INITDIR: Directori on s'allotja aquest guió.
  • DAEMONDIR: Directori on està el fitxer executable del servidor OpenERP (openerp-server.py). Normalment farem un enllaç simbòlic des de el directori /usr/bin.
  • SYSTEM_USER: Usuari de sistema amb el que es vol executar el servidor.

Exemple:

# If not exist the config file changes its parameters by:
NAME="openerp-6"
SERVER="server"
CONFIGDIR="/etc/${NAME}"
INITDIR="/etc/init.d"
DAEMONDIR="/usr/bin"
SYSTEM_USER=openerp

Codi font

#!/bin/sh

### BEGIN INIT INFO
# Provides:		openerp-server
# Required-Start:	$syslog
# Required-Stop:	$syslog
# Should-Start:		$network
# Should-Stop:		$network
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Short-Description:	Enterprise Resource Management software
# Description:		Open ERP is a complete ERP and CRM software.
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin

# If config file not exists, exit with error code 1
#[ ! -x /etc/openerp.conf ] && exit 1
# Load config file parameters
#. /etc/openerp.conf


# If not exist the config file changes its parameters by:
NAME="openerp-6"
SERVER="server"
CONFIGDIR="/etc/${NAME}"
INITDIR="/etc/init.d"
DAEMONDIR="/usr/bin"
SYSTEM_USER=openerp

# Module's Development
# FALSE or TRUE
LOG=TRUE

# Installation debuger enabled
#set -x
# Installation debuger disabled
set -e

# Assign order (start, stop, restart|force-reload, status)to $ORDER
if [ -z $1 ]; then
	echo "Usage: ${NAME}-${SERVER} {start|stop|restart|force-reload|status} [server-name [openerp-options ]]" >&2
	exit 1
fi
ORDER="${1}"
shift

# If a server parameter is given, sets the DB_USER variable with this parameter
if [ ! -z $1 ]; then
	DB_USER="$1"
	shift
fi

# Additional options that are passed to the Daemon.
PARAM=""
if [ $# -ge 1 ]; then
	while [ ! -z "${1}" ]; do
		PARAM="${PARAM} ${1}"
		shift
	done
fi

start_daemon () {
	echo "Starting ${NAME}-${SERVER} ${DB_USER}: "
	test -x ${DAEMONDIR}/${NAME}-${SERVER}_${DB_USER} || exit 0
	if [ -f ${PIDFILE} ]; then
		echo "${NAME}-${SERVER} ${DB_USER} already running: `cat ${PIDFILE}`"
		return
	fi

	if [ $LOG = "TRUE" ] ; then
    		echo "\nstart-stop-daemon --start --pidfile ${PIDFILE} --chuid ${SYSTEM_USER} --make-pidfile --exec ${DAEMONDIR}/${NAME}-${SERVER}_${DB_USER} -- ${DAEMON_OPTS}"
    		start-stop-daemon --start --pidfile ${PIDFILE} --chuid ${SYSTEM_USER} --make-pidfile --exec ${DAEMONDIR}/${NAME}-${SERVER}_${DB_USER} -- ${DAEMON_OPTS}
    	else
    		start-stop-daemon --start --quiet --pidfile ${PIDFILE} --chuid ${SYSTEM_USER} --background --make-pidfile --exec ${DAEMONDIR}/${NAME}-${SERVER}_${DB_USER} -- ${DAEMON_OPTS}
    	fi
	sleep 0.5
	echo "${NAME}-${SERVER} ${DB_USER}: `cat ${PIDFILE}`: running."
}


stop_daemon () {
    echo "Stopping ${NAME}-${SERVER} ${DB_USER}: "
    while [ `ps -ef | grep python | grep openerp | grep server | grep ${DB_USER} | awk ' { print $2 } '` ] ; do
        if [ -f ${PIDFILE} ]; then
            start-stop-daemon --stop --quiet --pidfile ${PIDFILE} #--oknodo
            sleep 0.5
        else
            PID=`ps -ef | grep python | grep openerp | grep server | grep ${DB_USER} | awk ' { print $2 } '`
            sudo kill -9 $PID
        	sleep 0.5
            echo "pid $PID stopped."
        fi
    done
    if [ -f ${PIDFILE} ]; then
        echo "pid `cat ${PIDFILE}` stopped."
        rm -f ${PIDFILE} # remove pidfile
    else
		echo "${NAME}-${SERVER} ${DB_USER}: not running"
    fi
    return
}

status_daemon(){
	echo -n "Checking ${NAME}-${SERVER} ${DB_USER}: "
	if [ -f ${PIDFILE} ]; then
		echo "`cat ${PIDFILE}` running."
	else
		echo "stopped."
	fi
}

case "${ORDER}" in
	start)
		if [ ${DB_USER} ] ; then
			PIDFILE="/var/run/${NAME}-${SERVER}_${DB_USER}.pid"
			DAEMON_OPTS="--config=${CONFIGDIR}/.${NAME}_${SERVER}rc_${DB_USER} ${PARAM}"
			start_daemon
		else
			for DB_USER in `ls -a ${CONFIGDIR}/.${NAME}_${SERVER}rc* | awk -v FS="_" '{print $3}'` ; do
				PIDFILE="/var/run/${NAME}-${SERVER}_${DB_USER}.pid"
				DAEMON_OPTS="--config=${CONFIGDIR}/.${NAME}_${SERVER}rc_${DB_USER} ${PARAM}"
				start_daemon
			done
		fi
		;;

	stop)
		if [ ${DB_USER} ] ; then
			PIDFILE="/var/run/${NAME}-${SERVER}_${DB_USER}.pid"
			stop_daemon
		else
			for DB_USER in `ls -a ${CONFIGDIR}/.${NAME}_${SERVER}rc* | awk -v FS="_" '{print $3}'` ; do
				PIDFILE="/var/run/${NAME}-${SERVER}_${DB_USER}.pid"
				stop_daemon
			done
		fi
		;;

	restart)
		if [ ${DB_USER} ] ; then
			PIDFILE="/var/run/${NAME}-${SERVER}_${DB_USER}.pid"
			DAEMON_OPTS="--config=${CONFIGDIR}/.${NAME}_${SERVER}rc_${DB_USER} ${PARAM}"
			stop_daemon
			start_daemon
		else
			for DB_USER in `ls -a ${CONFIGDIR}/.${NAME}_${SERVER}rc* | awk -v FS="_" '{print $3}'` ; do
				PIDFILE="/var/run/${NAME}-${SERVER}_${DB_USER}.pid"
				DAEMON_OPTS="--config=${CONFIGDIR}/.${NAME}_${SERVER}rc_${DB_USER} ${PARAM}"
				stop_daemon
				start_daemon
			done
		fi
		;;

	status)
		if [ ${DB_USER} ] ; then
			PIDFILE="/var/run/${NAME}-${SERVER}_${DB_USER}.pid"
			status_daemon
		else
			for DB_USER in `ls -a ${CONFIGDIR}/.${NAME}_${SERVER}rc* | awk -v FS="_" '{print $3}'` ; do
				PIDFILE="/var/run/${NAME}-${SERVER}_${DB_USER}.pid"
				status_daemon
			done
		fi
		;;

	*)
		N=/etc/init.d/${NAME}-${SERVER}
		echo "Usage: ${NAME}-${SERVER} {start|stop|restart|force-reload|status} [server-name [openerp-options ]]" >&2
		exit 1
		;;
esac

exit 0
 
openerp/scripts.txt · Darrera modificació: 2011/11/17 22:56 per jesteve
 
Copyright: Zikzakmedia Llicència Creative Commons By-NC-SA
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki