Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Wednesday, July 13, 2011

Troubleshooting When Cron Job wont Executed

What to check when Cron job/script wont executed? One of the possible answer is maybe the PATH declaration in your script which is not correct. Here are the sample story.

Currently I have to do application profiling in aim to analyst the posible bottleneck in application. The tools that I use like I have mentioned before is JBoss Profiler. Fortunately, this tool can be integrated easily with existing JBoss application server. JBoss profiler itself consist two modules. The first one is several jar files and configurations that is dipped into application server. The second part is small client Java application that will snapshot and produce profile report for current situation of method/function graph call from our application source code.

We have necessity to run the client snapshot application for every particular range time. The mean of this approach is when application that we profile start to run slowly in some particular module and some particular time we can dig to profile report and analyze the possible source of problem. To achieve this requirement we need some job scheduler tools. Because most of server live in Unix environment, we are very lucky because we have well known job scheduler in most Unix box. The scheduler name is Cron.

Scheduling a job with Cron is only the matter of editing crontab definition. Crontab itself is a configuration file that consist a list of job/command that will be executed for every particular time. This is the content of my Cron file. See the last line of the Cron files.


SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
#* * * * * root topCat.sh
#* * * * * root iostatCat.sh
* * * * * root snapshot.sh # this will be run every minute

This is the snapshot.sh script content.


#! /bin/sh
#This script is intended to take profiling snapshot

export PATH=$PATH:/usr/local/jdk1.6.0_20/bin
cd /opt/jboss-profiler-2.0.0.Beta5
# run the profiler snapshot capturer
java -Xmx512m -Djboss-profiler-client.properties=jboss-profiler-client.properties -jar jboss-profiler-client.jar snapshot
# move the produced report to other folder, in this case is to apache html folder so we can see remotely from browser client 
mv 201107* /var/www/html/profiler

#exit 0

I have run this configuration in my local successfully. But when I clone all the setting into the server the process seems not work as expected. I became more curious because after catching the log of cron tail -f /var/log/cron (or /var/log/syslog on ubuntu) the script actually already executed. The other of my confusedness, the script itself is worked perfectly if we executed it directly on the shell.


Jul 13 11:02:01 ID31-ND102 crond[13350]: (root) CMD (snapshot.sh)
Jul 13 11:03:01 ID31-ND102 crond[13368]: (root) CMD (snapshot.sh)
Jul 13 11:04:01 ID31-ND102 crond[13397]: (root) CMD (snapshot.sh)
Jul 13 11:05:01 ID31-ND102 crond[13418]: (root) CMD (snapshot.sh)
Jul 13 11:06:01 ID31-ND102 crond[13447]: (root) CMD (snapshot.sh)
Jul 13 11:07:01 ID31-ND102 crond[13465]: (root) CMD (snapshot.sh)
Jul 13 11:08:01 ID31-ND102 crond[13493]: (root) CMD (snapshot.sh)
Jul 13 11:09:01 ID31-ND102 crond[13512]: (root) CMD (snapshot.sh)
Jul 13 11:10:01 ID31-ND102 crond[13544]: (root) CMD (snapshot.sh)
Jul 13 11:10:01 ID31-ND102 crond[13546]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 13 11:11:01 ID31-ND102 crond[13564]: (root) CMD (snapshot.sh)
Jul 13 11:12:01 ID31-ND102 crond[13593]: (root) CMD (snapshot.sh)
Jul 13 11:13:01 ID31-ND102 crond[13612]: (root) CMD (snapshot.sh)
Jul 13 11:14:01 ID31-ND102 crond[13644]: (root) CMD (snapshot.sh)

Then after some hours of debugging I realize one possible source of problem is in PATH declaration in crontab files.


PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

Because I run java command then I have to add the path declaration to be like this.


PATH=/usr/local/jdk1.6.0_20/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

Then the scheduler can run the script perfectly.

Notes: This command sometime takes long time to run. Please refer to jboss profiler documentation for more information.


java -Xmx512m -Djboss-profiler-client.properties=jboss-profiler-client.properties -jar jboss-profiler-client.jar snapshot

Sunday, August 15, 2010

Samsung Bada Osp::Xml Build Problems

Pasted from my previous blog on 2 August 2010.

Since one last month I discover new mobile platform from Samsung, Bada. With basic skill as amateur Java Programmer I just have very basic skill in c/c++ programming that is used as lingua franca of Bada. Perhaps I know little bit knowledge about pointer. But I lost when need to discover build, link related problem.

One time I need to build application that have parse xml. I put the xml code in OnInitializing method that is extends from Osp::Ui::Controls::Form and I also not forget to include FXml.h at my header file and using namespace Osp::Xml in my cpp file. Here is snapshot of the code:

result MyXmlForm::OnInitializing(void) {
xmlDoc* doc = null;
xmlXPathContextPtr xpathCtx;
xmlXPathObjectPtr xpathObj;

doc = xmlReadFile(“/Home/test.xml”, null, 0); // error here
if (doc == NULL) {
AppLog(“Failed to load xml doc!”);
}

xpathCtx = xmlXPathNewContext(doc); // error
if (xpathCtx == NULL) {
AppLog(“Error: unable to create new XPATH context”);
xmlFreeDoc(doc); //error
return (E_IO);
}

xpathObj = xmlXPathEvalExpression((xmlChar*) “//title”, xpathCtx); //error
if (xpathObj == NULL) {
AppLog(“Error: unable to evaluate xpath expression”);
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
return (E_IO);
}

get_xpath_titles(xpathObj->nodesetval);

xmlFreeDoc(doc); // error
xmlCleanupParser(); // error

return E_SUCCESS;
}



Here are the errors:
undefined reference to `xmlReadFile'
undefined reference to `xmlFreeDoc’
undefined reference to `xmlXPathNewContext’
undefined reference to `xmlXPathEvalExpression’
undefined reference to `xmlXPathFreeContext’
undefined reference to `xmlCleanupParser’

This evening I spent about two hour to make above code work. Like I have said, Bada itself actually has provide xml library with namespace Osp::Xml which is subset from libxml2. When I finish type the code I stuck when have to face undefined reference to bla bla bla error relate to method call from Osp::Xml. I already make sure that I have include FXml.h in my header declaration and also state using namespace Osp::Xml in my source code. After spending sometime researching with very minimum information from Bada Documentation and also all internet site I found I need to link FXml library in project properties. Then build problem dissapear and my code can run smooth now. Yippie.

Saturday, August 14, 2010

Programming Language whose write JVM

This post is pasted from my previous blog posted 15 June 2008.

One of interesting point that is considered as the advantage of Java programming language is its portability. The jargon for that ability is really famous. Write once run anywhere (WORA). Although it will be needed hard work to write code which is really portable, I think the statement is not too exaggerate. Since it design phase, Java is prepared to be much portable. We can see the fact surround us. There are so many Java. In our computer desktop, laptop, expensive server, standard mobile phone, PDA, set top boxes and many more.

For who has read several first chapter of Java introductory book will know how that portability will be achieved. Different than former programming language, Java offer different approach in developing code. Running code in Java is consist of two phases which are, compiling source code and interpreting it’s result. Compiling phases use javac tool which change java source code with .java extension into intermediate code named bytecode with .class extension. Later this bytecode will be interpreted by java tool so we get the software run.

Different than other programming language, bytecode is not run straight above operating system or platform. Bytecode run over stuff called Java Virtual Machine (JVM). At that stuff .class file is interpreted a.k.a run by java.exe (in windoze) tool . Various platform has it’s own JVM. Windoze has its JVM, so that Linux, Solaris and other operating system. Also mobile phone, PDA, set top boxes has JVM. That’s why bytecode can run in various place and the portability is really approachable.

The question is, who act as a tittle of this post, what programming language has written that JVM. I believe rarely introductory java book will discuss much about inner mechanism of JVM. Several complex hardware level or compiler construction book perhaps will have wide portion for this topic. But I will prefer go to cinema and watch fun movie rather make my head dizzy reading such book.

So what the answer? This post will be useless by asking without answering. Ok here you go. After reading one of Good rarely Introductory Java book like I said above (the title is Java in 60 minutes A Day by Rich Rapossa from Willey) I found that JVM is written by C++. After all of advantage is offered by Java it still have to admit superiority of old complex difficult of C++. Yeah when reach the necessity of speed and hardware accessing such as needed by JVM, C++ is always needed.

My mind then imagine, if later there will be new programming language is founded. Let’s call that Sumatera programming language (Sumatera is another island in Indonesia such Java). Sumatera run above Virtual machine called Sumatera Virtual Machine (SVM). SVM abruptly coded by Java. And JVM coded with C++. I thing only crazy people will create that.

Just joke.