Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Wednesday, November 24, 2010

Install Apache Geronimo (as service) on Ubuntu Linux

Apache Geronimo is an Open Source J2EE server. And it can be installed rather easily on Ubuntu Linux (10.04).

As a reminder, the following instructions presume that one uses its current ubuntu account. For an enterprise environment it is recommended to create a new user account, for example g_user, that will own all the geronimo files and will start and stop the server (will be referred from now on as GERONIMO_OWNER and ${user}) and add this user to the sudoers as needed.


- First step is to install sun java.
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get install sun-java6-jdk


- Second step is to download and extract (install) Geronimo:
Download from :
http://geronimo.apache.org/apache-geronimo-v22-release.html
I downloaded the latest stable release with tomcat:
geronimo-tomcat6-javaee5-2.2-bin.tar.gz

Then md5sum it (to gain problem-solving time):
md5sum geronimo-tomcat6-javaee5-2.2-bin.tar.gz
and crosscheck it with the md5 sum on the site.

Extract the archive:
tar -xvzf geronimo-tomcat6-javaee5-2.2-bin.tar.gz

Rename the extracted directory to something smaller:
mv geronimo-tomcat6-javaee5-2.2 geronimo.2.2
From now on when we will refer to the full path of the geronimo.2.2 directory as ${GERONIMO_HOME}.
 
Open .bashrc file:
gedit /home/${user}/.bashrc

Add JAVA_HOME, JRE_HOME and JAVA_OPTS at the end of .bashrc:
export JAVA_HOME=/usr/lib/jvm/java-6-sun   
export JRE_HOME=/usr/lib/jvm/java-6-sun/jre
export JAVA_OPTS="-Xmx256m -XX:MaxPermSize=128m"
Run .bashrc (just this once):
. .bashrc
Or close the terminal and open a new one.

- Last step is to start the server:
cd ${GERONIMO_HOME}/bin
./geronimo start

And the server is up and running!
You can browse the Administration console at
http://localhost:8080/
Click the link "Administration -> console" on the left.
Provide the default credentials :
system/manager
And geronimo is at your disposal!

To maximize security, it is time to change the default admin username and password. You need to stop geronimo:
cd ${GERONIMO_HOME}/bin
./geronimo.sh stop --user system --password manager
Open user/passwords file
gedit ${GERONIMO_HOME}/var/security/users.properties
and add a new line with the new administrator user and his password like this:
g_admin=g_admin_pass
Next time you start the server the password will be automatically encrypted.
Open permission/groups file:
gedit ${GERONIMO_HOME}/var/security/groups.properties
Assign administration and monitoring privileges only to the new user. Change the two uncommented lines like this:
admin=g_admin
monitor=g_admin
Lastly you should change the file permissions on these files:
chmod -R 600 ${GERONIMO_HOME}/var/security

To create a service in order to automate startup open/create the following file:
sudo gedit /etc/init.d/geronimo2
Add the following code. You only need to set correctly for your system the variables GERONIMO_HOME, GERONIMO_OWNER, GERONIMO_ADMIN and GERONIMO_PASS inside the script.

#!/bin/bash
# chkconfig: 234 20 80
# description: Geronimo Server start/stop script
# processname: geronimo2

JAVA_HOME=/usr/lib/jvm/java-6-sun
JRE_HOME=/usr/lib/jvm/java-6-sun/jre
JAVA_OPTS="-Xmx256m -XX:MaxPermSize=128m"

GERONIMO_HOME=/home/gfuser/geronimo.2.2
GERONIMO_OWNER=g_user
GERONIMO_ADMIN=g_admin
GERONIMO_PASS=g_admin_pass

export JAVA_HOME JRE_HOME JAVA_OPTS GERONIMO_HOME GERONIMO_OWNER GERONIMO_ADMIN GERONIMO_PASS

start() {
  geronimo_state=`ps -ef | grep "geronimo" | grep "/bin/server.jar" | grep -v grep | wc -l`
  if [ $geronimo_state -gt 0 ]; then
    echo "Geronimo is already UP!"
  else 
    echo -n "Starting geronimo: "
    cd $GERONIMO_HOME/bin
    su $GERONIMO_OWNER -c "$GERONIMO_HOME/bin/geronimo.sh start"
    sleep 20
    echo "done."
  fi
}

stop() {
  geronimo_state=`ps -ef | grep "geronimo" | grep "/bin/server.jar" | grep -v grep | wc -l`
  if [ $geronimo_state -gt 0 ]; then
    echo -n "Gracefully stoping geronimo: "
    su $GERONIMO_OWNER -c "$GERONIMO_HOME/bin/geronimo.sh stop --user $GERONIMO_ADMIN --password $GERONIMO_PASS"
    sleep 10
    echo "done."
  else
    echo "Geronimo is already DOWN!"
  fi
}

force_stop() {
  geronimo_state=`ps -ef | grep "geronimo" | grep "/bin/server.jar" | grep -v grep | wc -l`
  if [ $geronimo_state -gt 0 ]; then
    echo -n "Forcefully stoping geronimo: "
    su $GERONIMO_OWNER -c "$GERONIMO_HOME/bin/geronimo.sh stop --force --user $GERONIMO_ADMIN --password $GERONIMO_PASS"
    echo "done."
  else
    echo "Geronimo is already DOWN!"
  fi
}

status() {
  geronimo_state=`ps -ef | grep "geronimo" | grep "/bin/server.jar" | grep -v grep | wc -l`
  if [ $geronimo_state -gt 0 ]; then
    echo "Geronimo is UP!"
  else
    echo "Geronimo is DOWN!"
  fi
}

case "$1" in
  start)
    start
;;
  stop)
    stop
;;
  status)
    status
;;
  force_stop)
    force_stop
;;
  restart)
    stop
    sleep 2
    start
;;
  *)
  echo "Usage: $0 {start|stop|force_stop|restart|status}"
esac

exit 0

Now you need to change the file permissions:
sudo chmod 755 /etc/init.d/geronimo2

Next create the upstart conf file:
sudo gedit /etc/init/geronimo2.conf
and add the following code

# geronimo2

start on runlevel [2345]
stop on runlevel [16]

respawn

pre-start exec /etc/init.d/geronimo2 start
post-stop exec /etc/init.d/geronimo2 stop


Reload upstart configuration:
sudo initctl reload-configuration
Start geronimo service :
sudo initctl start geronimo2

And the geronimo service is securely installed and will be started on every boot.

p.s.
You can find me on fiverr for more personalized requests on any java app server configuration problem or java error that you encounter, with deliverance of less than a day (true!) and money back guarantee if not satisfied.

Tuesday, May 18, 2010

Cuda 3.0 installation on Ubuntu Linux 10.04

I need to point out, that it is somewhat appalling the need to write a new tutorial for every time either a linux version or a product (pick your favourite) version is released. That said, I am off to provide the tutorial.

I had to read many tutorials and walkthroughs, as well as forum threads to succeed in the installation. So some parts might look very familiar!

First of all we will need to install the cuda graphics driver. Afterwards the cuda toolkit, followed by the cuda sdk. Finally we 'll install gcc 4.3 beacuse Cuda cannot cooperate with gcc 4.4 with which Ubuntu 10.04 ships. The linux version I am using is i386. I presume the instructions will work as well with x86_64 kernel.

Go to the official nvidia-CUDA download page:
http://developer.nvidia.com/object/cuda_3_0_downloads.html#Linux

Download the CUDA Toolkit and the CUDA SDK:

CUDA Toolkit for Ubuntu Linux 9.04 (32-bit)
GPU Computing SDK code samples and more

-----------------------------
Installing the NVIDIA driver:
-----------------------------
We'll need the latest cuda development driver available (195.xx), but first we'll uninstall the existing drivers.

1. Uninstall existing NVIDIA drivers and nvidia-glx.

(if you have enabled nvidia in system->administration->hardware drivers, then disable them first and possibly reboot)

sudo apt-get purge nvidia-*

2. Stop gdm service by running

sudo service gdm stop

3. Install drivers from nvidia repository

sudo add-apt-repository ppa:nvidia-vdpau/ppa
sudo apt-get update
sudo apt-get install nvidia-185-modaliases nvidia-glx-185 nvidia-settings
sudo nvidia-xconfig

4. Reboot and log back in.

5. Run

nvidia-settings

to verify that your driver version is at least 195. Look for the driver version in the window:
The 195.xx NVIDIA Driver for use with CUDA.

----------------------------
Installing the CUDA Toolkit:
----------------------------

After having installed the driver we now need to install the CUDA toolkit itself.

1. Run:

sudo sh cudatoolkit_3.0_linux_32_ubuntu9.04.run

2. Press enter to install at the default location.

/usr/local/cuda

3. Register the new library files:

sudo gedit /etc/ld.so.conf.d/cuda.conf &

and add the following to the empty file

/usr/local/cuda/lib

Save the file and close gedit.
Then run:

sudo ldconfig

Create a link to the libcuda.so library:

cd /usr/lib
sudo ln -s nvidia-current/libcuda.so libcuda.so

Also add to the end of your ~/.bashrc file.

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib

restart bash

----------------------------------------------------------
Installing the CUDA SDK and Compiling the Example Programs
----------------------------------------------------------

We will now install the CUDA SDK to our own home directory (we can experiment with the supplied demos):

1. Install SDK to the default location

sh gpucomputingsdk_3.0_linux.run

2. As CUDA does not yet work with GCC 4.4 we will have to install gcc-4.3:

sudo apt-get install gcc-4.3 g++-4.3 g++-4.4
sudo update-alternatives --remove-all gcc
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 43 --slave /usr/bin/g++ g++ /usr/bin/g++-4.3 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.3
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 44 --slave /usr/bin/g++ g++ /usr/bin/g++-4.4 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.4
sudo update-alternatives --config gcc ### choose gcc 4.3

3. Install CUDA SDK requirements

sudo apt-get install libglut3-dev libxi-dev libxmu-dev

4. Go to SDK source dir:

cd ~/NVIDIA_GPU_Computing_SDK/C$

5. You should now be able to compile everything by running

make

This should now compile all the examples in the SDK without errors.

---------------------------------------------
Verify Installation
---------------------------------------------

We can now verify that everything is working:

1. Run (from ~/NVIDIA_GPU_Computing_SDK/C):

bin/linux/release/deviceQuery

On my machine I get the following output (depending on your harware, you output may be different. mine is a GeForce 8500 GT):

------------------------------------------------
bin/linux/release/deviceQuery Starting...

CUDA Device Query (Runtime API) version (CUDART static linking)

There is 1 device supporting CUDA

Device 0: "GeForce 8500 GT"
CUDA Driver Version: 3.0
CUDA Runtime Version: 3.0
CUDA Capability Major revision number: 1
CUDA Capability Minor revision number: 1
Total amount of global memory: 536150016 bytes
Number of multiprocessors: 2
Number of cores: 16
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 16384 bytes
Total number of registers available per block: 8192
Warp size: 32
Maximum number of threads per block: 512
Maximum sizes of each dimension of a block: 512 x 512 x 64
Maximum sizes of each dimension of a grid: 65535 x 65535 x 1
Maximum memory pitch: 2147483647 bytes
Texture alignment: 256 bytes
Clock rate: 1.57 GHz
Concurrent copy and execution: Yes
Run time limit on kernels: Yes
Integrated: No
Support host page-locked memory mapping: No
Compute mode: Default (multiple host threads can use this device simultaneously)

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 134566327, CUDA Runtime Version = 3.0, NumDevs = 1, Device = GeForce 8500 GT


PASSED

Press to Quit...
-----------------------------------------------------------
-----------------------------------------------------------

That was it. It was a little hard, but it is worth the effort.

Let us only hope that we will not be obligated to write a new one for every release!!!

Friday, December 4, 2009

Running gwt project error

I thought giving gwt a chance, so I opened a tutorial for gwt and eclipse. Very soon I had the code for a little HelloWorld example ready to run. But when I hit 'run as --> Web Application' there was a sinister error waiting for me!!!

- libstdc++.so.5: cannot open shared object file: No such file or directory

So I thought I'll apt-get my way through! But stdlibc++.so.5 is no longer available on ubuntu 9.10!
So I googled the library and I had to install almost manually. Here is the download mirrors list for libstdc++5 library.

http://packages.ubuntu.com/jaunty/i386/libstdc++5/download.

After downloading and installing it, gwt worked fine. Though my code was a mess! lol.
And I need to add that linux is a beauty. I did not have to restart eclipse. I just hit 'Run' one more time and it worked!

Tuesday, November 24, 2009

Install Google App Engine Plugin for Eclipse

First things first. Google is offering a plugin for Eclipse. So I had to download and install eclipse. The thing is I recently switched to ubuntu linux (9.10) and was so fascinated with its easy-to-use interface that I immediately jumped to Applications --> Ubuntu Software Center and installed eclipse. All went fine. Until I started following google's installation instrunctions for the plugin. The setup would never finish, because there were some missing libraries. I started searching the internet for help. I found that ubuntu's release of eclipse is a slightly different one that lacks update support. I tried using the update sites of the mainstream release of eclipse, but that didn't do the trick either.
I was frustrated. I uninstalled the ubuntu release and downloaded the official release. Things went smoothly, because eclipse doesn't need installing! Only extracting! When I arrived at the installation plugin screen I realised that some things were not viewable. That was really weird. Just as if I was looking at a non stable release! As a consequence, I was unable to install the plugin.
I was even more frustrated, but I didn't quit just yet. I starting searching the internet blindly. With no luck. Then I started looking at all the Google App Engine pages just in case. And there I found it. At a google blog there was one easy step to solve all of my problems! So all I had to do was create a new file in the eclipse home directory with the following lines:

------------

#!/bin/sh
export GDK_NATIVE_WINDOWS=1
./eclipse
------------

and run eclipse through it.
All of my troubles were over. All the instructions for the plugin installation were completing successfully! For your reference the google installation instructions are at the following urls:

http://code.google.com/eclipse/docs/getting_started.html#installing

[http://dl.google.com/eclipse/plugin/3.5]

After a few days I tried repeating the above procedure at a windows xp sp3 machine. I was surprised to find out that the installation process was flawless, without a glitch! This is a clear win for windows! Although eclipse is an open source software, it's installation on an ubuntu machine was far more troublesome that in windows.