Monday, October 31, 2011

"Run On Server" not showing up in Eclipse with m2eclipse?

Okay, I went through this problem in Eclipse Indigo for J2EE Developers release that m2eclipse wont show me the Run On Server selection in the Run menu when I import a maven project with war packaging (ie. the maven-archetype-webapp).

Here is how to fix it:
1. Uninstall the current m2eclipse plugin you have in eclipse:
  (a) Go to "Help > Install New Software"
  (b) Click on the "What is already installed?" link
  (c) Select "m2e - Maven Eclipse Integration" and click on the "Uninstall" button
  (d) Restart eclipse when prompted

2. Next, you have to install the m2eclipse:
  (a) Go to "Help > Eclipse Market Place"
  (b) Search for the word m2eclipse
  (c) Select "Maven integration for eclipse"
  (d) Click the "Install" button

3. Install the "Maven Integration for Eclipse WTP"

  (a) Go to "Help > Eclipse Market Place"
  (b) Search for the word m2eclipse
  (c) Select "Maven integration for eclipse WTP
  (d) Click the "Install" button

Restart when prompted.

Now, importing a maven project with war packaging will work out of the box. Enjoy.

Sunday, October 23, 2011

Configuring Eclipse to run with a specific JDK or JRE


1. Open the file eclipse.ini for editing

2. Add the two lines to specify the virtual machine to use (the bolded lines):

-startup
plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar

-vm 
C:\Program Files\Java\jdk1.6.0_29\bin\javaw.exe

--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.100.v20110502

3. Now start eclipse.

Wednesday, October 19, 2011

Wonderful Iphone Icon Generator Online

Give your divs a simplistic nice shadow with css

I loved the middle box shadow in the shopify.com website, and therefore decided to dig it up. The CSS used for it is:

-moz-box-shadow: 0px 0px 15px rgba(0,0,0,0.1);
-webkit-box-shadow: 0px 0px 15px rgba(0,0,0,0.1);
box-shadow: 0px 0px 15px rgba(0,0,0,0.5);

Monday, October 17, 2011

Using mod_jk with Apache 2.2 How to setup a reverse proxy



Advice on mod_jk versus mod_proxy and mod_proxy_ajp
Do not use mod_proxy and mod_proxy_ajp on Apache 2.2 since they are not stable and have caused me some problems. Use mod_jk instead.

Prerequisites & Assumptions Before you continue
I assume you have:
- You already have Apache Webserver 2.2 installed
- You already have Tomcat installed
- You already have a web application on Tomcat with context "jobsapp"
- You are using Redhat Enterprise or CentOS and therefore have yum on your system.

How to get the mod_jk binary for Apache 2.2 on Linux
You wont find it anywhere, you have to compile it, now stop being lazy and start working.

The following steps detail the process:

// Create a temporary source directory, I use /opt/src
mkdir /opt/src
cd /opt/src 


// Get the source package
wget http://mirrors.isu.net.sa/pub/apache//tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.32-src.tar.gz


// Install packages needed to compile the binary
yum install httpd-devel
yum install gcc-c++


// Extract the tar.gz file
tar -zxvf /opt/src/tomcat-connectors-1.2.32-src.tar.gz


// Configure, make, make install
./configure --with-apxs=/usr/sbin/apxs
make
su -c 'make install'

How to configure Apache Webserver with Mod JK

1. Edit the file httpd.conf
vim /etc/httpd/conf/

2. Add this line to load the module:
...
LoadModule jk_module modules/mod_jk.so
...

3. Add also the following lines:

JkWorkersFile   conf/worker.properties
JkLogFile       /var/log/httpd/mod_jk.log
JkLogLevel      debug
JkRequestLogFormat      "%w %U %T"
JkOptions +ForwardURIEscaped +ForwardURICompatUnparsed

After finishing, change JkLogLevel from debug to "error" or "info" so that the log file doesn't grow too much in size.

4. Now create a file names worker.properties inside /etc/httpd/conf/ and add the following lines to it:
vim /etc/httpd/conf/worker.properties

# Worker Properties file for mod_jk
worker.list=tomcat
worker.tomcat.host=localhost
worker.tomcat.port=8009
worker.tomcat.type=ajp13
worker.tomcat.connection_pool_timeout=300




4.5. Make sure to read the mod_jk attributes in this link:
http://tomcat.apache.org/connectors-doc/reference/workers.html

5. Now open the httpd.conf or your virtual host configuration file and add the following lines:

JkMount     /jobsapp tomcat
JkMount     /jobsapp/* tomcat

6. Also open the ssl httpd conf file which has the following line at the top,
and add the same two lines inside them:

<VirtualHost _default_:443>
...
JkMount     /jobsapp tomcat
JkMount     /jobsapp/* tomcat
...
</VirtualHost>


7. Now restart apache

/etc/init.d/httpd restart

Tuesday, October 11, 2011

Adding deleted files in git

When you type:

git commit -a

Git will add the new, modified and deleted files automatically and commit them

However, there are cases when you want to 'git add' deleted files (that got deleted in your working directory).

I tried:

git add *

But this didn't workout. It only added the modified and created files.

I wanted a way to add the deleted files, I thought of issuing a 'git rm' command:

git rm *

BUT WAIT. THIS WILL DELETE EVERYTHING.

So, what is the solution.

The solution is to use:

git add -u

The -u (show for --update) tells git to compare to the tracked files in git rather than the working directory.

According to the GIT manual:
'git add' man page says about the -u option...
-u
--update
Only match <filepattern> against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed.
If no <filepattern> is given, default to "."; in other words, update all tracked files in the current directory and its subdirectories.

Sunday, October 09, 2011

Making a bash script know its current directory location

I use the following variables at the beginning of my Bash script to get such information:

EXECUTED_FROM_DIR=`pwd`
THIS_SCRIPT_DIR=$(cd $(dirname "$0"); pwd)
cd $THIS_SCRIPT_DIR


#Do different tasks here
...


cd $EXECUTED_FROM_DIR

vim color tuning

A great way to tune color automatically in vim is by calling:

set background=dark

Since the default on linux is "backgroun=light"

I have also placed this inside the /etc/vimrc to have a global effect

Bash Tips

To check if a file exists (The exclamation ! means "not") :
if [ ! -f ${TOMCAT_DIR}/conf/jobsapp.conf ]
then
  echo "Do something"
fi


To check if a script should be run by a specific user:
if [ "$(id -u -n)" != "root" ]; then
   echo "This script must be run as root user" 1>&2
   exit 1
fi

To prompt a user for an action:

read -p "Deploy on Tomcat (y/n)?" CONT
if [ "$CONT" == "y" ]; then
  echo "Deploying on tomcat...";
  echo "Finished deploying on tomcat.";
else
  echo "Copied files, but didn't deploy on tomcat.";
fi


.gitignore by example

A git ignore is a file named ".gitignore" that gets placed in the top level directory of your git workspace.

It informs git to ignore files when adding and committing files.

# Exclude files with an extension
*.jar
*.o
*.a


# Do not exclude required.jar
!required.jar


# ignore the file TODO at the top level directory only
# thus /TODO will be ignored, but src/TODO will not be ignore.
/TODO


# To indicate a directory for ignoring it should end with a "/"


# This line ignores all directories and subdirectories named log/
log/


# This line only ignores the top level directory named build
/build/


# This ignores all files ending with txt inside doc/ directory, but not inside doc/example/
doc/*.txt

Important notes:
1. Files starting with / (slash) mean that you should start from the top level directory
2. The * (star) in doc/*.txt does not mean it will match any directories inside. It will only match top level files inside the doc directory ending with *.txt. Thus doc/example/test.txt will not be matched.

Tracking an /etc directory using GIT version control while preserving file permissions

.. while preserving permissions on the linux file system.

Here's how to do it:
1. Download the post hook file setgitperms from here or directly from here http://repo.or.cz/w/git.git/blob_plain/HEAD:/contrib/hooks/setgitperms.perl

2. Place the script inside your .git/hooks directory. You have two options here:

(Option A) To apply this for all git repositories newly created
Copy the file setgitperms.perl inside the directory:

mv setgitperms.perl /usr/share/git-core/templates/hooks/.

(Option B) To apply this hook for a specific directory only
Copy the file setgitperms.perl inside the directory:
mv setgitperms.perl <Your Project Directory>/.git/hooks/.

3. Although git new releases handles this, just to be safe, make sure to add execute permissions for the hook:
chmod +x setgitperms.perl

4. Inside the hooks directory, create a file named "pre-commit" and place in it the following lines:

#!/bin/sh
SUBDIRECTORY_OK=1 . git-sh-setup
$GIT_DIR/hooks/setgitperms.perl -r


5. Create file named post-merge and post-checkout and place the following content inside each:

#!/bin/sh
SUBDIRECTORY_OK=1 . git-sh-setup
$GIT_DIR/hooks/setgitperms.perl -w


6. Save the files and make sure they are executable using chmod +x:
chmod +x post-merge
chmod +x post-checkout
chmod +x pre-commit

7. Thats it.

Reference: http://serverfault.com/questions/5410/using-revision-control-for-server-configuration-files

Saturday, October 08, 2011

Installing Tomcat 6 on Redhat Enterprise

List of commands that took place:

cd /opt
wget http://mirrors.isu.net.sa/pub/apache/tomcat/tomcat-6/v6.0.33/bin/apache-tomcat-6.0.33.zip
unzip apache-tomcat-6.0.33.zip
ln -s /opt/apache-tomcat-6.0.33 tomcat
yum install java-1.6.0-sun
alternatives --config java



There are 3 programs which provide 'java'.


Selection    Command
-----------------------------------------------
1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
*+ 2           /usr/lib/jvm/jre-1.6.0-sun.x86_64/bin/java
3           /usr/lib/jvm/jre-1.6.0-sun/bin/java


Enter to keep the current selection[+], or type selection number: (Press 2 Then Enter)
vim /etc/init.d/tomcat

While in vim type the following in command mode to avoid extra spaces which pasting:
:set paste

Copy the following text and paste it:

#!/bin/bash # # Init file for SixSigns Tomcat server # # chkconfig: 2345 55 25 # description: SixSigns Tomcat server # # Source function library. . /etc/init.d/functions RUN_AS_USER=tomcat # Adjust run user here CATALINA_HOME=/opt/tomcat start() { echo "Starting Razuna Tomcat: " if [ "x$USER" != "x$RUN_AS_USER" ]; then su - $RUN_AS_USER -c "$CATALINA_HOME/bin/startup.sh" else $CATALINA_HOME/bin/startup.sh fi echo "done." } stop() { echo "Shutting down Razuna Tomcat: " if [ "x$USER" != "x$RUN_AS_USER" ]; then su - $RUN_AS_USER -c "$CATALINA_HOME/bin/shutdown.sh" else $CATALINA_HOME/bin/shutdown.sh fi echo "done." } case "$1" in start) start  ;; stop) stop  ;; restart) stop sleep 10 #echo "Hard killing any remaining threads.." #kill -9 `cat $CATALINA_HOME/work/catalina.pid` start  ;; *) echo "Usage: $0 {start|stop|restart}" esac exit 0

Then write and quit in vim:
:wq

Make sure the file doesn't contain microsoft new lines:
dos2unix /etc/init.d/tomcat

Now change to executable:
chmod +x /etc/init.d/tomcat

Next create a tomcat user:
groupadd tomcat
useradd -g tomcat -d /opt/tomcat tomcat
passwd tomcat
password: tomcat
retype password: tomcat

Reassign permissions to directories:
chown -R tomcat:tomcat /opt/tomcat
chown -R tomcat:tomcat /opt/apache-tomcat-6.0.33
cd /opt/tomcat/bin
chown +x *.sh

Add tomcat to services:
chkconfig --add tomcat
chkconfig --level 345 tomcat on

Start tomcat:
/etc/init.d/tomcat start


Finding ports and processes running on linux port 80

The command:

# To find processes running on port 80
lsof -i :80

A Wonderful CSS Tricks Website

Installing Tomcat 6 on Redhat Linux Enterprise or CentOS

http://wiki.openbluedragon.org/wiki/index.php/Apache_Tomcat_on_CentOS/RedHat

From: 

Install Tomcat

With CentOS/RedHat you could install Tomcat from the YUM repositories, but they only hold the older 5.5.x version. Of course, if you want to have Version 5.5.x installed then you only have to issue a;
yum install tomcat*
But I do recommend that you install Tomcat 6.0.18 (the current version of this writing), since it features better memory handling and some other improvements. The official Tomcat page is your friend in this regard http://tomcat.apache.org/. Luckily, installing Tomcat is straight forward.
  1. Download Tomcat 6.0.18
    1. Browse to http://tomcat.apache.org/download-60.cgi and download the Binary Distribution or click on the direct link here http://apache.mirror.testserver.li/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz. Wget is your friend.
  2. I recommend to install Tomcat in the "/opt" directory. Thus copy the downloaded file into "/opt".
  3. Extract it with
tar xzvf apache-tomcat-6.0.18.tar.gz
  1. For better handling I always create a symbolic link for "tomcat" with
ln -s /opt/apache-tomcat-6.0.18 tomcat
  1. Test Tomcat
    1. Start Tomcat with:
/opt/tomcat/bin/startup.sh
    1. Hit http://localhost:8080. If all is fine you should see the Tomcat homepage.
All should be fine, right? Ok, move on.

Deploy (Install) OpenBD

  1. go into the tomcat folder
    1. cd /opt/tomcat/
  2. download the openbd.war file (be sure to check the OpenBD download site for the latest war file link)
    1. wget http://openbd.viviotech.net/downloader.cfm/id/64/file/openbd.war
  3. once the file has downloaded move it to the tomcat webapps folder where it will automatically deploy
    1. mv /opt/tomcat/openbd.war /opt/tomcat/webapps
  4. once the war file is in webapps Tomcat will pick it up and create an openbd folder
  5. go to the administrator
    1. http://localhost:8080/openbd/bluedragon/administrator
      1. the default bluedragon administrator password is admin

Configure Tomcat to run on startup

Now, that Tomcat and OpenDB runs nicely you might want to have it automatically started when you reboot your system. For that we can use the following script and "chkconfig" command line.
  1. Create a "tomcat" file in "/etc/init.d"
vi /etc/init.d/tomcat
  1. Copy the below startup script
#!/bin/bash
#
# Init file for SixSigns Tomcat server
#
# chkconfig: 2345 55 25
# description: SixSigns Tomcat server
#

# Source function library.
. /etc/init.d/functions

RUN_AS_USER=tomcat # Adjust run user here
CATALINA_HOME=/opt/tomcat

start() {
        echo "Starting Razuna Tomcat: "
        if [ "x$USER" != "x$RUN_AS_USER" ]; then
          su - $RUN_AS_USER -c "$CATALINA_HOME/bin/startup.sh"
        else
          $CATALINA_HOME/bin/startup.sh
        fi
        echo "done."
}
stop() {
        echo "Shutting down Razuna Tomcat: "
        if [ "x$USER" != "x$RUN_AS_USER" ]; then
          su - $RUN_AS_USER -c "$CATALINA_HOME/bin/shutdown.sh"
        else
          $CATALINA_HOME/bin/shutdown.sh
        fi
        echo "done."
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        sleep 10
        #echo "Hard killing any remaining threads.."
        #kill -9 `cat $CATALINA_HOME/work/catalina.pid`
        start
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
esac

exit 0
  1. Save the file (case you forgot "esc + x) :-)
  2. Add the tomcat startup script to the chkconfig with:
chkconfig --add tomcat
  1. Then activate it for your run level. Since I am not running any X Server on my server I only want to run it on level 345. Do it with:
chkconfig --level 345 tomcat on
  1. You can check if Tomcat will startup on reboot with listing the startup scripts with:
chkconfig --list
You should see a;
tomcat         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
  1. If you have done all well, you should now be able to bounce Tomcat with this script as well. Try it with:
/etc/init.d/tomcat restart

Thursday, October 06, 2011

Speeding up mysql restoration of data

Mysql restoration too slow? Try the following steps:

1. Open the file my.ini inside the MySQL installation directory and do the following:

(a) Search for innodb_buffer_pool_size and set it to approx 20% of your RAM. I set it to 500M.
innodb_buffer_pool_size=500M

(b) Search for innodb_flush_log_at_trx_commit and change it from 1 to 2:
innodb_flush_log_at_trx_commit=2

(c) Search for key_buffer_size and set it to approx 20% of your physical RAM.
key_buffer_size=1200M

(d) In your data.sql file you are trying to restore, if it is an innodb tables, try to modify it and add the lines:
SET FOREIGN_KEY_CHECKS=0 // At the beginning

...
SET FOREIGN_KEY_CHECKS=1 // At the end of the file

Now restart MySQL service.

Start restoring data. It will be approximately a magnitude of 50 times faster.

The Robot Two Leg Problem in Guice DI


Sunday, October 02, 2011

Maven, configuring an http proxy


Go to your user directory (ie. /home/babbas or /c/Users/babbas) then goto ".m2" directory and create a file named settings.xml. Inside that file copy the contents below:

<?xml version="1.0"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>iproxy.isu.net.sa</host>
<port>8080</port>
<username/>
<password/>
<nonProxyHosts/>
<id/>
</proxy>
</proxies>
</settings>


Installing GIT on Linux Redhat or CentOS 5

First is first:

wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -Uvh epel-release-5-4.noarch.rpm
yum install git

Next steps, configure git configuraiton:

git config --global user.name "Basil Abbas"
git config --global user.email "basil@isu.net.sa"
git config --global color.ui auto

Creating a bare repository on a remote server:

mkdir project_directory
cd project_directory
git init --bare

Cloning the bare remote repository on a development machine:

cd /home/babbas
git clone ssh://hostname/path/to/project_directory






Saturday, October 01, 2011

VIM ignoring case search

Just type:
:set ignorecase



and to return back to normal:
:set noignorecase


If you would like to search case insensitive one time only without changing the mode in vim, for example lets search for the word "earth" case insensitively:

/\cearth

The \c character tells vim that the search should be case insensitive.