Thursday, October 8, 2015

How to solve "SEVERE: One or more listener failed to start" error message in Tomcat startup log" when deploy and run OLAT application?

Startup the OpenOlat application on Tomcat server, encounter the error as described below. No clue of what could be the reason.
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
SEVERE: Context [/openolat] startup failed due to previous errors 
Solution
Please refer to http://blog.trifork.com/2011/03/18/debugging-the-dreaded-severe-error-listenerstart-and-severe-error-filterstart-tomcat-error-messages/ for solution After follow the steps as described in the blog, error message as shown below is displayed

org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of clas
s org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanInitializationException: Could not load pr
operties; nested exception is java.io.FileNotFoundException: class path resource
 [olat.local.properties] cannot be opened because it does not exist
        at org.springframework.beans.factory.config.PropertyResourceConfigurer.p
ostProcessBeanFactory(PropertyResourceConfigurer.java:87)
        at org.springframework.context.support.AbstractApplicationContext.invoke
BeanFactoryPostProcessors(AbstractApplicationContext.java:696)
        at org.springframework.context.support.AbstractApplicationContext.invoke
BeanFactoryPostProcessors(AbstractApplicationContext.java:671)
        at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:461)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebA
pplicationContext(ContextLoader.java:410)
        at org.springframework.web.context.ContextLoader.initWebApplicationConte
xt(ContextLoader.java:306)
        at org.springframework.web.context.ContextLoaderListener.contextInitiali
zed(ContextLoaderListener.java:112)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContex
t.java:5003)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContex
t.java:5517)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:87
7)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)

        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1095
)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:
1930)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:47
1)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:615)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.FileNotFoundException: class path resource [olat.local.proper
ties] cannot be opened because it does not exist
        at org.springframework.core.io.ClassPathResource.getInputStream(ClassPat
hResource.java:171)
        at org.springframework.core.io.support.EncodedResource.getInputStream(En
codedResource.java:143)
        at org.springframework.core.io.support.PropertiesLoaderUtils.fillPropert
ies(PropertiesLoaderUtils.java:98)
        at org.springframework.core.io.support.PropertiesLoaderSupport.loadPrope
rties(PropertiesLoaderSupport.java:175)
        at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProp
erties(PropertiesLoaderSupport.java:156)
        at org.springframework.beans.factory.config.PropertyResourceConfigurer.p
ostProcessBeanFactory(PropertyResourceConfigurer.java:78)
        ... 19 more

Tuesday, September 15, 2015

How to resolve MojoExecutionException error when build the OpenOlat project?

Try to download the OpenOlat version 10.3 source code as a gzip file from its portal, unzip the source code and build the project in maven. MojoExecutionException error message as shown below is displayed when "mvn clean package" command is executed.

[ERROR] Failed to execute goal org.openolat.mojo:buildnumber-maven-plugin:1.2.0:
hgchangeset (default) on project openolat-lms: Command failed.
[ERROR] EXECUTION FAILED
[ERROR] Execution of cmd : id failed with exit code: 255.
[ERROR] Working directory was:
[ERROR] D:\Projects\OpenOlat\openolat103
[ERROR] Your Hg installation seems to be valid and complete.
[ERROR] Hg version: 3.5+5 (OK)
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
rg.openolat.mojo:buildnumber-maven-plugin:1.2.0:hgchangeset (default) on project
 openolat-lms: Command failed.
EXECUTION FAILED
  Execution of cmd : id failed with exit code: 255.
  Working directory was:
    D:\Projects\OpenOlat\openolat103
  Your Hg installation seems to be valid and complete.
    Hg version: 3.5+5 (OK)

Reason

The OpenOlet mojo plugin can't be found, please refer to pom.xml

<plugin> 
     <groupid>org.openolat.mojo</groupid>
     <artifactid>buildnumber-maven-plugin</artifactid>
     <version>1.2.0</version>
     <executions>
          <execution>
               <phase>validate</phase>
	       <goals>
	            <goal>hgchangeset</goal>
	       </goals>
	  </execution>
     </executions>
     <configuration>
          <docheck>true</docheck>
	  <doupdate>true</doupdate>
     </configuration>
</plugin>

The proper way to build OpenOlat should be
  • Install TortoiseHg version 3.5
  • Clone the OpenOlat source code from http://hg.openolat.org/openolat103
  • Rebuild the project with "mvn clean package" command, you should be able to build the war file.



Sunday, September 6, 2015

How to shutdown the Apache web server process running at the background in Mac machine?

Run the command below to shutdown Apache Web Server background process in your mac machine

sudo killall httpd
sudo launchctl unload /System/Library/LaunchDaemons/org.apache.httpd.plist

Monday, August 17, 2015

How to reset your first installed mysql database password?

  • For newly installed mysql database, the default database password is empty
  • In order to reset the password, type in the "mysql" command at terminal window. 
  • Type in the command below to reset the password
mysql > UPDATE mysql.user SET password=password('password') WHERE user='root' AND host='localhost';
  • If the error message as shown below is displayed
ERROR 1227 (42000): Access denied; you need (at least one of) the RELOAD privilege(s) for this operation
  • Add the 2 parameter to my.cnf file
[mysqld]
skip-grant-tables
skip-networking
  • Restart mysql services
  • Type in command "mysql" to login into mysql, rerun the command below, you should be able to reset your root password
mysql > UPDATE mysql.user SET password=password('password') WHERE user='root' AND host='localhost';
mysql > FLUSH PRIVILEGES; 

Tuesday, August 11, 2015

How to delete external app from LaunchPad?

  • For external application that displayed at LaunchPad, long click doesn't called up the cross symbol to allow the user to delete away the app.
  • Below are some alternative way that I have come across from internet that might be useful
  • Launch the "Terminal" window
# cd ~/Library/Application\ Support/Dock
# ls
  • By listing the files in the folder, you will be able to find the database file
  • Run the command below to delete away the application from LaunchPad
# sqlite3 [DATABASENAME].db "DELETE from apps WHERE title='[APPNAME]';"

[DATABASENAME] represent the database name that we discovered at previous steps
[APPNAME] represent the name of the app
  • Run the command below to restart the launchpad. Voila, the external application is removed from LaunchPad.
# killall Dock

Monday, August 10, 2015

How to setup "Basic" authentication to phpPgAdmin at Apache web server?


  • Run the command below to add user to ".htpasswd" file


# htpasswd [DIRECTORY]/.htpasswd [USERNAME]

[DIRECTORY] represent the folder that store the password
[USERNAME] represent the user login id

Note: Password/Retype password will be prompted after the command above has been executed


  • Open configuration file httpd.conf , add the configuration as described below

<Directory "/var/www/phpPgAdmin">
    AuthName "Secure Area"
    AuthType Basic
    AuthUserFile [DIRECTORY]/.htpasswd
    require valid-user
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>


Restart Apache server, voila, your phpPgAdmin is protected now.


Wednesday, July 15, 2015

Technic to monitor Apache server performance

iftop tool installation

Enter the command below

# wget http://pkgs.repoforge.org/iftop/iftop-0.17-1.el6.rf.x86_64.rpm
# rpm -ivh iftop-0.17-1.el6.rf.x86_64.rpm

Run the "iftop" command to launch the tool to monitor the network card

Check the number of CPU

Enter the command below

# nproc

nmon tool installation

Enter the command below

# wget http://nmon.sourceforge.net/docs/MPG_nmon_for_Linux_14a_binaries.zip
# unzip MPG_nmon_for_Linux_14a_binaries.zip
# ./nmon_x86_64_centos5

Scripts to check Apache connection

Came across the script below from internet and found out it is helpful to monitor the number of concurrent connection to Apache server. Just show it for sharing purpose

#!/bin/bash

[ $# -eq 0 ] && { echo "Usage: $0 " ; exit 1; }

while true
do
        clear;
        echo "Number of Apache Active Connections:";
        netstat -an | grep 443 | grep tcp | grep -v 0.0.0.0 | grep -v ::: | cut -d':' -f2 | cut -d' ' -f12 | sort | wc -l;
        echo;
        #echo "Current Active IP's:";
        netstat -an | grep 443 | grep tcp | grep -v 0.0.0.0 | grep -v ::: | cut -d':' -f2 | cut -d' ' -f12 | sort;
        sleep $1;
done

Simple Shell scripts to load test the Apache server

The scripts download sample.pdf from Apache to time the download time and produce CSV report.

#!/bin/bash

for ((i=1; i <= 200 ; i++))
do
    curl -s -w "iPad($i)",%{time_connect},%{time_starttransfer},%{time_total}\\n  -o "sample$i.pdf" https://[SERVER_NAME]/sample.pdf >> report.csv &
done

Wednesday, April 29, 2015

How to detecting PHP-CGI vulnerabilities (CVE-2012-1823)?

System Environment

ZenMap: 6.47
PHP version: 5.3.3
Redhat 2.6
[IP ADDRESS]: The server IP address

Verify the PHP-CGI vulnerabilities

1. In order to find and detect any PHP-CGI vulnerabilities, download ZenMap scanner from https://nmap.org/download.html.

2. Type in the command as described below in the ZenMap scanner.

nmap -p 80 --script http-vuln-cve2012-1823 [IP ADDRESS]

3. Or type in the command as described below in the ZenMap scanner.

nmap -p 80 --script http-vuln-cve2012-1823 --script-args uri=/login.php IP [IP ADDRESS]

4. Click on "Scan" button, the scanning process will start. If no vulnerabilities found, no error message will be displayed.



5. If vulnerabilities is found, "Vulnerabilities" warning message will be displayed

Investigation

For Redhat version 2.6, “CVE-2012-1823 - Apache / PHP5.x Remote Code Execution Exploit” vulnerability has been patched in Redhat security patch “RHSA-2012:0546-1”

In order to confirm that the Linux server has been patched properly, run the command below to check

yum list installed > /tmp/yum-list.txt



Tuesday, April 7, 2015

How to enable garbage collection in Tomcat?

System Environment

Tomcat version: 7.0.40
Redhat: 2.6
gcviewer: 1.35
[TOMCAT_HOME]: Tomcat home directory
[SERVICE_NAME]: Tomcat service name

Configuration (Linux)

The garbage collection in Tomcat can be enabled through the steps as listed below:

1. Look for "setenv.sh" file at "[TOMCAT_HOME]\bin" directory.
2. Add in the entries below to "setenv.sh".

CATALINA_OPTS="-XX:+PrintGCDetails -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCApplicationConcurrentTime -XX:+PrintHeapAtGC -Xloggc:[TOMCAT_HOME]/logs/gc.log"

3. Restart the Tomcat instance, check the [TOMCAT_HOME]/logs directory, gc.log file is generated.

Open and observe the garbage collection log

1. Browse to "http://sourceforge.net/projects/gcviewer/files/" to download gcviewer.
2. Open the garbage collection log file. You will be able to analyze garbage collection log and the memory usage by Tomcat.


Configuration (Window)

Assume the Tomcat service has been configured, you can run the command below in [TOMCAT_HOME]\bin to install service name
service install [SERVICE_NAME]

1. Double click "tomcat7w.exe" located at  [TOMCAT_HOME]\bin directory, the screen as shown below will be displayed. Select "Java" tab.


2. Append the text below to "Java Options" textbox
-XX:+PrintGCTimeStamps
-XX:+PrintGCDetails
-XX:+PrintGCApplicationStoppedTime
-XX:+PrintGCApplicationConcurrentTime
-XX:+PrintHeapAtGC
-Xloggc:[TOMCAT_HOME]\logs\gc.log

3. The log file will be generated at [TOMCAT_HOME]\logs folder

4. Open log file with gcviewer, the memory usage will be displayed as shown in the screen below




Wednesday, March 18, 2015

How to setup Solr on Linux machine (1) ?

System Environment
Linux Version: 2.6.32-358.23.2.el6.x86_64
Solr Version: 5.0.0
Postgresql database version: 8.4

Configure a new Core

1. Copy the basic configuration from "/opt/solr-5.0.0/server/solr/configsets/basic_configs" directory to "/opt/solr-5.0.0/server/solr/configsets" directory.

# cd /opt/solr-5.0.0/server/solr/configsets
# cp -rf basic_configs ../
2. Rename the directory as new application name, for example, "myapp".

# cd ..
# mv basic_configs myapp
3. Open the server admin module "http://localhost:8983/solr/", fill in the information

name: myapp
instanceDir: myapp
dataDir: data
config: solrconfig.xml
schema: schema.xml


4. Click on "Add Core" button, new core will be added.

Index data from Postgresql database use data import handler

1. Download Posgresql database driver (postgresql-8.4-703.jdbc4.jar) and place it in "/opt/solr-5.0.0/contrib/dataimporthandler/lib" directory.

2. Make sure jar files as listed below exists in "/opt/solr-5.0.0/dist" directory.
- solr-dataimporthandler-5.0.0.jar
- solr-dataimporthandler-extras-5.0.0.jar

3. To index the data from "booktown" database "books" table, edit solrconfig.xml located at "/opt/solr-5.0.0/server/solr/myapp/conf" directory

<lib dir="/opt/solr-5.0.0/contrib/dataimporthandler/lib" regex=".*\.jar"/>
<lib dir="/opt/solr-5.0.0/dist/" regex="solr-dataimporthandler-.*\.jar"/>
...
...
...
<requesthandler class="org.apache.solr.handler.dataimport.DataImportHandler" name="/dataimport">
 <lst name="defaults">
  <str name="config">db-data-config.xml</str>
 </lst>
</requesthandler>

4.Create db-data-config.xml at  "/opt/solr-5.0.0/server/solr/myapp/conf" directory. Below are sample configuration file.

<dataConfig>
  <dataSource type="JdbcDataSource" 
              driver="org.postgresql.Driver"
              url="jdbc:postgresql://localhost:5432/booktown" 
              user="solr" 
              password="solr"/>
  <document>
    <entity name="books"  
      pk="id"
      query="select id, title from books"
      deltaImportQuery="SELECT id, title from books WHERE id='${dih.delta.id}'"
      >
       <field column="id" name="id"/>
       <field column="title" name="title"/>       
    </entity>
  </document>
</dataConfig>

5. Edit schema.xml located at "/opt/solr-5.0.0/server/solr/myapp/conf".

<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
<field name="title" type="text_general" indexed="true" stored="true"/>

6. Open the Solr browser, select "myapp" in the dropdown box. Click on "Data Import" and "Execute" button. Click on "Refresh status" button. Data from Postgresql will be indexed.


7. Click on "Query" menu follow by "Execute Query" button. The search will be displayed.








Tuesday, March 17, 2015

How to setup Solr on Linux machine?

System Environment
Linux Version: 2.6.32-358.23.2.el6.x86_64
Solr Version: 5.0.0

Need to upgrade JDK to version 1.7.0.55 and above for Solr to work

1. Download JDK version 1.7.0_75 (jdk-7u75-linux-x64.tar.gz)
2. Copy jdk-7u75-linux-x64.tar.gz to "/usr/lib" directory
3. Run the command to untar the zip files
tar xzf jdk-7u75-linux-x64.tar.gz
4. Run  the command below to install the JDK
alternatives --install /usr/bin/java java /usr/lib/jdk1.7.0_75/bin/java 2
5. Run the command below to select the java command to use
alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
   2           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
   3           /usr/lib/jdk1.7.0_75/bin/java

Enter to keep the current selection[+], or type selection number: 3
6. Run the command below to install

alternatives --install /usr/bin/jar jar /usr/lib/jdk1.7.0_75/bin/jar 2
alternatives --install /usr/bin/javac javac /usr/lib/jdk1.7.0_75/bin/javac 2
alternatives --set jar /usr/lib/jdk1.7.0_75/bin/jar
alternatives --set javac /usr/lib/jdk1.7.0_75/bin/javac 

Solr Installation

1. Download Solr from Apache website. Note: "solr-5.0.0.tgz" has been downloaded
2. Copy solr-5.0.0.tgz to "/opt" directory
3. Run the command below to unzip the Solr installer
tar zxf solr-5.0.0.tgz
3. Run the command below to start the Solr instance. The default port is 8983
# cd /opt/solr-5.0.0/
# bin/solr start
4. To shutdown the Solr instance, run the command below.
# bin/solr stop

Open Firewall to allow port 8983

1. Run the command below to open port 8983 on the machine
# iptables -I INPUT -p tcp -m tcp --dport 8983 -j ACCEPT
#service iptables save
2. Type the URL (http://[server_address]:8983/) in any browser, Solr admin screen will be displayed.