Better openerp-server init.d script, for ennhanced Monit/d behavior

0

This script was taken from the default distributions openerp-server init.d script and mainly modified for improved Monit/d behavior.

The main problem was that sometimes the openerp-server could not be reliable shutdown – as a result a manual kill had been necessary. This should be now addressed with the following script:

#!/bin/sh

### BEGIN INIT INFO
# Provides:		openerp-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:	Enterprise Resource Management software
# Description:		Open ERP is a complete ERP and CRM software.
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/openerp/openerp-server-6.1-1/openerp-server
NAME=openerp-server
DESC=openerp-server-6.1-1
CONFIG=/etc/openerp/openerp-server-6.1-1.conf
ADDONS_PATH=/opt/openerp/openerp-server-6.1-1/openerp/addons/,/opt/openerp/data/current/addons/
LOGFILE=/var/log/openerp/6.1-1/openerp-server.log
RUNFOLDER=/var/run/openerp
PIDFILE=${RUNFOLDER}/${NAME}.pid
USER=openerp

test -x ${DAEMON} || exit 0

set -e

# su - ${USER}

case "${1}" in
	start)
                echo "--- Setting up environment ${DESC} ---"
		mkdir -p ${RUNFOLDER}
		touch ${PIDFILE} 
		chown -R ${USER} ${RUNFOLDER}
		echo -n "Starting ${DESC}: "
		sudo -u ${USER} start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
			--chuid ${USER} --background --make-pidfile \
			--exec ${DAEMON} -- --config=${CONFIG} \
			--addons-path=${ADDONS_PATH} --logfile=${LOGFILE}
		echo "${NAME}."
		;;

	stop)
		echo -n "Stopping ${DESC}: "
		start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \
			--oknodo
		echo "${NAME}."
                echo "Kill ${NAME} in case there is still an instance running"
                # Be sure:
		sleep 15
                rm -f ${PIDFILE}
		while pkill -u openerp python; do sleep 1; done
                echo "Killed ${NAME}"
                echo "."
		;;
        show)
                echo "Show all pids of process ${NAME}"
                CPIDS=$(pgrep -fu openerp python)
		if [[ -n $CPIDS ]]; then
			echo $CPIDS
		else
			echo "Not Running"
		fi
                echo "."
                ;;
	debug)
                echo "Call: ${DAEMON} --debug --config=${CONFIG}"
                echo "Debugging ${DESC}: "
                echo 		sudo -u ${USER} ${DAEMON} --debug --addons-path=${ADDONS_PATH} --config=${CONFIG}
		sudo -u ${USER} ${DAEMON} --debug --addons-path=${ADDONS_PATH} --config=${CONFIG}
                echo "${NAME}."
                ;;
	import)
                echo "Call: sudo -u ${USER} ${DAEMON} --addons-path=${ADDONS_PATH} -P status.pickle --config=${CONFIG}"
                echo "Importing & Exporting ${DESC}: "
                sudo -u ${USER} ${DAEMON} -P status.pickle --addons-path=${ADDONS_PATH} --config=${CONFIG}
                echo "${NAME}."
                ;;
        update-all)
                echo "Call: sudo -u ${USER} ${DAEMON} --addons-path=${ADDONS_PATH} --config=${CONFIG} --update=all"
                echo "Importing & Exporting ${DESC}: "
	        echo  sudo -u ${USER} ${DAEMON} --addons-path=${ADDONS_PATH} --config=${CONFIG} --update=all
                echo "${NAME}."
                ;;
	restart|force-reload)
		echo "Restarting ${DESC}: "

                echo "--- Stopping ${DAEMON} daemon ---"
		start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \
			--oknodo
		sleep 15
                echo "--- Killing all ${USER} processes ---"
               	while pkill -u openerp python; do sleep 1; done
                echo "Killed ${NAME}"
                echo "."
		sleep 5
		rm -f ${PIDFILE}
		echo "."
		echo "--- Setting up environment ${DESC} ---"
                mkdir -p ${RUNFOLDER}
                touch ${PIDFILE} 
                chown -R ${USER} ${RUNFOLDER} 
		echo "."
                echo -n "Starting ${DESC}: "
                sudo -u ${USER} start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
                        --chuid ${USER} --background --make-pidfile \
                        --exec ${DAEMON} -- --config=${CONFIG} \
                        --addons-path=${ADDONS_PATH} --logfile=${LOGFILE}
		echo "Restarted ${NAME}."
		;;
	*)
		N=/etc/init.d/${NAME}
		echo "Usage: ${NAME} {start|stop|restart|force-reload|show|debug|import}" >&2
		exit 1
		;;
esac

exit 0

Postgres: Copy a database

0

For backup and development reasons a copy of a postgres database on the same system is often used. This is not a big problem and can be done directly as a SQL statement:

CREATE DATABASE newDBname WITH TEMPLATE originalDBname OWNER dbuser;

in your favorite console (psql, pgadmin, etc). There is one thing to remember, if you do a template copy this can not be done hot – so you need to assure that all users are logged of.
If you can not guarantee that, then you might better stick with doing a dump and then restoring it using pg_dump and psql:

pg_dump -U dbuser originalDBname | psql -U dbuser newDBname

Eclipse: convert upper case text to lower case and viceversa with a simple shortcut

0

This is just a quick post to share these 2 little shortcuts to convert text from lower case to uppercase and vice-versa in Eclipse.
Lower case: CTRL+SHIFT+Y (CMD+SHIFT+Y on Mac OS X)
Upper case: CTRL+SHIFT+X (CMD+SHIFT+X on Mac OS X)
Camel case: Anyone knows a shortcut?
You can select one or more characters to convert.

OpenERP: Connect Kettle to OpenERP

0

[1] http://kettle.pentaho.com

[2] http://ci.pentaho.com/view/Data%20Integration/job/Kettle/

[3] http://apps.openerp.com/addon/1833?filter=%7B%22order_by%22%3A+%22click_counter+desc%22%2C+%22author%22%3A+78%7D&page=0

[4] http://erpmoldeo.wordpress.com/2011/02/10/openerp-kettle-and-terminatooor/

[5] http://www.akretion.com/en/products-and-services/openerp-kettle-bi-connector-terminatooor

[6] http://forums.pentaho.com/showthread.php?98831-Asking-OpenERP-module-for-pentaho-data-integration-(Kettle)

Glassfish: Running in an java.lang.NoSuchMethodError Exception, when porting a Glassfish2 project

0

Using the default installation with the standard domain “domain1” of a fresh Glassfish3 installation, I deployed an old Entprise project. The project worked perfectly with Glassfish2, but on Glassfish3 I did ran into an java.lang.NoSuchMethodError:

[#|2012-08-07T15:38:25.983+0200|SEVERE|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=20;_ThreadName=Thread-2;|org.apache.commons.collections.MapUtils.putAll(Ljava/util/Map;[Ljava/lang/Object;)Ljava/util/Map;at org.glassfish.apf.AnnotationInfo@cb88c8

java.lang.IllegalStateException: org.apache.commons.collections.MapUtils.putAll(Ljava/util/Map;[Ljava/lang/Object;)Ljava/util/Map;at org.glassfish.apf.AnnotationInfo@cb88c8

at com.sun.enterprise.deployment.archivist.Archivist.readAnnotations(Archivist.java:487)

at com.sun.enterprise.deployment.archivist.Archivist.readAnnotations(Archivist.java:429)

at com.sun.enterprise.deployment.archivist.Archivist.readRestDeploymentDescriptors(Archivist.java:405)

at com.sun.enterprise.deployment.archivist.Archivist.readDeploymentDescriptors(Archivist.java:380)

at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:243)

at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:252)

at com.sun.enterprise.deployment.archivist.ApplicationArchivist.readModulesDescriptors(ApplicationArchivist.java:657)

at com.sun.enterprise.deployment.archivist.ApplicationArchivist.openWith(ApplicationArchivist.java:258)

at com.sun.enterprise.deployment.archivist.ApplicationFactory.openWith(ApplicationFactory.java:240)

at org.glassfish.javaee.core.deployment.DolProvider.load(DolProvider.java:175)

at org.glassfish.javaee.core.deployment.DolProvider.load(DolProvider.java:94)

at com.sun.enterprise.v3.server.ApplicationLifecycle.loadDeployer(ApplicationLifecycle.java:827)

at com.sun.enterprise.v3.server.ApplicationLifecycle.setupContainerInfos(ApplicationLifecycle.java:769)

at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:368)

at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)

at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)

at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)

at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)

at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)

at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)

at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)

at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)

at org.glassfish.admin.rest.ResourceUtil.runCommand(ResourceUtil.java:214)

at org.glassfish.admin.rest.ResourceUtil.runCommand(ResourceUtil.java:207)

at org.glassfish.admin.rest.resources.TemplateListOfResource.createResource(TemplateListOfResource.java:148)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)

at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)

at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)

at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)

at com.sun.jersey.server.impl.uri.rules.SubLocatorRule.accept(SubLocatorRule.java:134)

at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)

at com.sun.jersey.server.impl.uri.rules.SubLocatorRule.accept(SubLocatorRule.java:134)

at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)

at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)

at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)

at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)

at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)

at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)

at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)

at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)

at com.sun.jersey.server.impl.container.grizzly.GrizzlyContainer._service(GrizzlyContainer.java:182)

at com.sun.jersey.server.impl.container.grizzly.GrizzlyContainer.service(GrizzlyContainer.java:147)

at org.glassfish.admin.rest.adapter.RestAdapter.service(RestAdapter.java:148)

at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)

at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)

at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)

at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)

at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)

at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)

at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)

at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)

at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)

at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)

at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)

at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)

at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)

at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)

at com.sun.grizzly.ContextTask.run(ContextTask.java:71)

at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)

at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)

at java.lang.Thread.run(Thread.java:662)

Caused by: org.apache.commons.collections.MapUtils.putAll(Ljava/util/Map;[Ljava/lang/Object;)Ljava/util/Map;at org.glassfish.apf.AnnotationInfo@cb88c8

at org.glassfish.apf.impl.AnnotationProcessorImpl.process(AnnotationProcessorImpl.java:367)

at org.glassfish.apf.impl.AnnotationProcessorImpl.process(AnnotationProcessorImpl.java:375)

at org.glassfish.apf.impl.AnnotationProcessorImpl.processAnnotations(AnnotationProcessorImpl.java:289)

at org.glassfish.apf.impl.AnnotationProcessorImpl.process(AnnotationProcessorImpl.java:217)

at org.glassfish.apf.impl.AnnotationProcessorImpl.process(AnnotationProcessorImpl.java:134)

at com.sun.enterprise.deployment.archivist.Archivist.processAnnotations(Archivist.java:598)

at com.sun.enterprise.deployment.archivist.Archivist.readAnnotations(Archivist.java:442)

… 64 more

Caused by: java.lang.NoSuchMethodError: org.apache.commons.collections.MapUtils.putAll(Ljava/util/Map;[Ljava/lang/Object;)Ljava/util/Map;

at de.xxx(Unknown Source)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:247)

at com.sun.enterprise.deployment.util.TypeUtil.getMethod(TypeUtil.java:399)

at com.sun.enterprise.deployment.MethodDescriptor.getMethod(MethodDescriptor.java:333)

at org.glassfish.ejb.deployment.annotation.handlers.TransactionAttributeHandler.processAnnotation(TransactionAttributeHandler.java:101)

at org.glassfish.ejb.deployment.annotation.handlers.AbstractAttributeHandler.processAnnotation(AbstractAttributeHandler.java:183)

at org.glassfish.apf.impl.AnnotationProcessorImpl.process(AnnotationProcessorImpl.java:344)

… 70 more

The corresponding apache commons library for this method should have been bundled in the EAR – so what was the problem?

As I was pretty sure that the directory structure and deployment rules of the EAR where right I was quite confused. To figure out the problem I first checked if I was using the libraries appropriately, if they were correctly wrapped and if there was any library conflict. After some investigations it was quite obvious that there was already another library with a different version and thus a different method signature installed. The resolution was quite simple – just remove the conflicting library (“commons-collections-3.1.jar”) as it was not used by any other application.

rm commons-collections-3.1.jar

Magento: Adding a list of categories as a single category block to Magento

0

Magento is missing per default a categories block, so you have to code it on your own. For this knowledge of the language php or better ;) might be required.
First we need to change the layout in the file of your magenta installation (assuming that we use the Theme WEBBLAZER):

/app/design/frontend/default/WEBBLAZER/layout/catalog.xml

add the following line to this file

        
            
        

to insert the categories in the left sidebar.

Now we need to create our category.phtml file, just place it in the following path:

/app/design/frontend/default/WEBBLAZER/template/catalog/navigation/category.phtml

and insert the next block of code

load(__REPLACE_WITH_YOUR_ROOT_CATEGORY__)->getChildren();
$catIds = explode(',',$cats);
?>
  • load($catId); echo $category->getName(); $subCats = Mage::getModel('catalog/category')->load($category->getId())->getChildren(); $subCatIds = explode(',',$subCats); ?> 1): ?>
    • load($subCat); echo $subCategory->getName(); ?>

be careful the replace the placeholder __REPLACE_WITH_YOUR_ROOT_CATEGORY__ with your root category. Which would be in our case 42.

Thats it – you now should have a list of all subcategories of your root category 42 in the left sidebar.

References:
[1] http://www.devinrolsen.com/magento-custom-category-listing-block/
[2] http://thinkclay.com/technology/magento-display-categories-in-sidebar
[3] http://stackoverflow.com/questions/4273898/how-to-sort-a-category-list-array-alphabetically-in-magento

Oracle: Timeout idle or dead sessions

0

Lately in a project we had a lot of problems with idle database sessions. It turns out that the DBA did not configure any timeout for the oracle database for idle or dead sessions.

This is done with the PMON process, and via SQL*Net, by the sqlnet_expire_time parameter.

SQL*Net

In your sqlnet.ora file add the setting
sqlnet_expire_time=2
which will poll the SQL*Net client every two minutes and disconnect the session if there is no activity.
For PMON you can buy the according Oracle DBA scripts from Burleson’s website:
http://www.dba-oracle.com/oracle_scripts.htm

Reference [1]: http://www.dba-oracle.com/t_timeout_dead_or_idle_oracle_sessions.htm

Reference [2]: http://docs.oracle.com/cd/B19306_01/network.102/b14213/sqlnet.htm

Magento: Configure Magento with ISPConfig

0

Some configuration settings between ISPConfig and Magento overlap, so it was necessary to fine-tune these settings.

Also make sure that you use suPHP and try to prevent mod_php, which is faster but has some problems.

You can simply copy them and add them to your „Apache Directives“ in the ISPConfig, but do not forget to replace the directory „/var/www/clients/client1/web1/web/„ with yours:

DirectoryIndex index.php

############################################

## adjust memory limit

php_value memory_limit 64M

# lets stick with 30s for now        

# php_value max_execution_time 1800

############################################

## disable magic quotes for php request vars

php_flag magic_quotes_gpc off

############################################

## enable resulting html compression

php_flag zlib.output_compression on

############################################

## enable apache served files compression

## http://developer.yahoo.com/performance/rules.html#gzip

# Insert filter

SetOutputFilter DEFLATE

# Netscape 4.x has some problems…

#BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems

#BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine

#BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# Don’t compress images

SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don’t deliver the wrong content

#Header append Vary User-Agent env=!dont-vary

############################################

## make HTTPS env vars available for CGI mode

SSLOptions StdEnvVars

############################################

## enable rewrites

Options +FollowSymLinks

RewriteEngine on

############################################

## you can put here your magenta root folder

## path relative to web root

RewriteBase /

############################################

## workaround for HTTP authorization

## in CGI environment

# RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

############################################

## always send 404 on missing files in these folders

RewriteCond %{REQUEST_URI} !^/(media|skin|js)/

############################################

## never rewrite for existing files, directories and links

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-l

############################################

## rewrite everything else to index.php

RewriteRule .* index.php [L]

############################################

## Prevent character encoding issues from server overrides

## If you still have problems, use the second line instead

AddDefaultCharset Off

#AddDefaultCharset UTF-8

############################################

## Add default Expires header

## http://developer.yahoo.com/performance/rules.html#expires

ExpiresDefault „access plus 1 year“

Postgres: Remote copy a database between two machines using ssh

0

Sometimes it might be useful to copy a postgres database between two systems. This is not a big hazel and can be done with a simple one-liner (Port 22):

pg_dump -C dbname | bzip2 | ssh  remoteuser@remotehost.de "bunzip2 | psql dbname"

and even if your ssh connection uses a different port (1234) you are good to go:

pg_dump -C dbname | bzip2 | ssh remoteuser@remotehost.de -p 1234 "bunzip2 | psql dbname user"

GIT: Updating the current branch in a non-bare repository is denied…

0

Sometimes there are days when you just forget to configure your git repository on the server and that are the days when you run in awkward errors like that:

By default, updating the current branch in a non-bare repository is denied, because it will make the index and work tree inconsistent…

The fix for this is simple, just configure your git repository on the server as a bare repository:

git config --bool core.bare true

Then remove all files and directories, except for the “.git“ directory.
Mission accomplished.

Go to Top