Monday, December 10, 2012

Network File System (NFS)

Follow the below syntax to create a Network File System. Please Note you must have the Root access to do this anyway.

Let two host A and B both can be access to each other over the network and you want to create a NFS on B from A.

Example Case:

java installed on machine A and JAVA_HOME on Host A is : /home/java/jdk1.6.0_33 . and you want to use the java on machine B with out installing it on B

ON Host B :

1) create a directory java [Note you can crteate this directory anywhere]. I am taking /mnt as parent directory , so you must be root or you have the sudo access to do so

 ~]# mkdir /mnt/java

2)open the file /etc/fstab and append the below line . Please change the parameter as per your requirements

 ~]# vi /etc/fstab

A:/home/java/jdk1.6.0_33 /mnt/java nfs defaults 0 0

A : Host name or IP address
/home/java/jdk1.6.0_33 : Path on Host A
/mnt/java                       : Path on Host B


On Host A:

1) Open the file /etc/exports and append the below line. Please change the path as per your requirements.

~]# vi /etc/exports

/home/java/jdk1.6.0_33 *(rw,sync,no_root_squash)

2)Start the nfs service. The below command will stop and start the service

 ~]# service nfs restart

3) Start portmnp service

~]# service portmap restart



Final step on Host B:

~]# mount /mnt/java


Now you are done. you can set your JAVA_HOME and PATH on Host B using the path /mnt/java.


Friday, June 22, 2012

Add Ruby Gems to your Jruby Application

In two way you can add Ruby Gems to your JRuby application.

Case 1: In this case we will take the gems for ssh connections i.e. net-ssh. So what ever the gems you want to add in your application , 1st check the required dependencies for that gems. in this case for net-ssh we required

1)jruby-openssl
2)jruby-pageant

Steps:: Case 1:-

1)download the jruby-complete-XXXX.jar file . check with below link for the respective versions.

http://jruby.org/download

you can create a jruby-complete.jar file from source too.
            a) download the jruby source from http://jruby.org/download
                Ex:-  E:\jruby-src-1.6.7.2.zip

            b) unzip it to any local directory
                 Ex:- unzip  jruby-src-1.6.7.2.zip
                         It will create a directory  jruby-1.6.7.2
            c) download and unzip ant if ant is not on your system http://ant.apache.org/bindownload.cgi
            d) set the ANT_HOME and PATH for the ant.
            e) change current directory  to the unzip jruby source directory
                   cd E:\jruby-1.6.7.2
            f) ant jruby-complete

It will create a jruby-complete.jar file which is same as if you follow to download it from the repository link http://jruby.org/download

Let your final jruby-complete.jar file in E:\jruby\jruby-complete.jar

2)  Let download and get the required gems . use the following command to do so

To get jruby-openssl:

java -jar jruby-complete-1.6.7.2.jar -S gem install -i ./jruby-openssl jruby-openssl --no-rdoc --no-ri

To get jruby-pageant:

java -jar jruby-complete-1.6.7.2.jar -S gem install -i ./jruby-pageant jruby-pageant --no-rdoc --no-ri

To Get net-ssh :

java -jar jruby-complete-1.6.7.2.jar -S gem install -i ./net-ssh net-ssh --no-rdoc --no-ri

Now you have all the gems in your current directory i.e. E:\jruby

3) Let push these gems to the jruby-complete.jar file

jar uf jruby-complete-1.6.7.2.jar -C jruby-openssl .
jar uf jruby-complete-1.6.7.2.jar -C jruby-pageant .
jar uf jruby-complete-1.6.7.2.jar -C net-ssh .

4)  Lets check if the gems pushed successfully or not

java -jar jruby-complete-1.6.7.2.jar -S gem list

*** LOCAL GEMS ***

bouncy-castle-java (1.5.0146.1)
jruby-openssl (0.7.7)
jruby-pageant (1.1.1 java)
net-ssh (2.5.2)
rake (0.8.7)
sources (0.0.1)

5)  Let's check if the gems are loading through require or not

java -jar jruby-complete-1.6.7.2.jar -S irb

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'net/ssh'
=> true
irb(main):003:0> exit

-------------------------------End of Case 1--------------------------------------------------------------------
NOTE : you can install and push the gems in a single command also , just use them in the same command syntax with space..
--------------------------------------------------------------------------------------------------------------------
WOW that's it . now all your gems in your jar file.


Steps - Case 2:

case 2 is the traditional one.

1) follow the same step no 1 from Case1
2) now you have the jruby-complete.jar file . and your current directory is
     E:\jruby
     create a directory structure E:\jruby\lib\gems\1.8

Note : Here I used the above path for a separate the gems directory . So it is completely depends on you how you manage your path.

3) java -jar jruby-complete.jar -S install jruby-openssl jruby-pageant net-ssh --no-ri --no-rdoc -i lib/gems/1.8

 The above command will install all the required gems described in the command in the defined path . So here you can replace your destination path


4) Set the GEM_PATH

set GEM_PATH=E:\jruby\lib\gems\1.8

In Linux : export GEM_PATH=`pwd`/lib/gems/1.8

5)  Now follow the Steps No 4 and 5 from Case 1 to get the result.

That's It

------------------------------------------End of Case 2--------------------------------------------------

- Khirod







Tuesday, June 19, 2012

rvd: Unable to create transport on UDP port XXXX

2012-06-19 03:22:26 rvd: Unable to create transport on UDP port XXX. Previously created transport specified network as '192.168.XXX.15;192.168.180.255;192.168.XXX.125' which caused the send address for the port to be bound to 192.168.XXX.125, while current transport specifies network as ';;192.168.XXX.51;;' which requests the send address to be bound to 192.168.XXX.51. You cannot associate the same service parameter with two different network parameters.
./tibrvsend: Failed to initialize transport: Arguments conflict




In the above case just change the service port number and accordingly on the listener side. The above error is normal. Here the subnet is different So so the UDP port being reserved by some time . after sometime it will be released automatically.

If you do not want to wait upto release just use another service port . careful if the same port may be used by any other service. So better have a grep to /etc/services with the used port. In the most worst case just restart the RVD.




Example :

./tibrvsend -network ";;192.168.188.51" -service XXXX -daemon tcp:7500 Test.message "Hello World"

Next use
./tibrvsend -network ";;192.168.199.156" -service YYYY -daemon tcp:7500 Test.message "Hello World"

tibrvsend to different subnet

The below example will explain you, how to send the message to different subnet.

Let  a network Bcast Address : 192.168.180.255
                              System IP  : 192.168.180.15
                             Host Name : tiger100
                   RVD service port : 7190


Another Network Bcast Address: 192.168.175.255
                             System IP       :192.168.175.51
                             Host Name     : lion100
                       RVD service port : 5991

Here we are going to send the message from tiger100 to lion100

1) check on both system if rvd process is running or not. It should running . else start rvd on both
    
    ps -ef | grep 'rvd'

2) Start the rvd listener on lion100

./tibrvlisten -service 7190  -daemon tcp:7500 Test.message

3) Now send the message from tiger100

./tibrvsend -network ";;192.168.175.51" -service 7190 -daemon tcp:7500 Test.message "Hello World"

That it... Now you the message at lion100.

Friday, June 1, 2012

File.executable? does not in this environment and will return a dummy value

 warning: executable? does not in this environment and will return a dummy value

I face this warning in java5 when executing command in system("command/shell script"). as the system usually check if the shell script is executable or not.

and java5 is required anyway for my application . So did the below changes to avoid the warning.

Before : system("shell Script")
After : output=`#{command}`

Tuesday, May 29, 2012

Global variable in Ruby/JRuby

If anybody wants to create a global variable which can be access to all the ruby class and module through out the project. then follow the example given below:

$globalvariable=

class
   .
   .
   .

end


The value of the globalvariale can be access through out the ruby project.

i.e. puts($globalvariable)

NOTE: "$globalvariable=value" may be display as $globalvariable= . it is a Bug with Blogger. So read it as  "$globalvariable=value"

Monday, May 28, 2012

Log Redirection in Ruby

If you wan to redirect your methods log to a file instead of console and after writing the log to the file the output should back to console then follow the below instructions.

def example()
 oldout=$stdout
 $stdout=File.new("",'a')
.
.
.                   
.
.
$stdout=oldout
end


you can change the type of writing to log file with replace of 'w', 'w+' etc.. depends on your requirements.

Monday, April 16, 2012

Module Example in Ruby Language

The below given example guide you , how to work with ruby module.

1) The ruby module are just like ruby class , which can contain the methods , fields etc..
2) Multiple modules can possible in a file , lets take an example :

create a file testModule.rb , create it any where does not matter. In side the file create the module viz.
here we have created two modules

1)Test
2)Test1

Test contains a simple method as show , So that we can call this method just by using the object of the used class of this module Test

Test1 contains the same method , but the declaration is bit different that is Test1.show . which behaves like a static method, and you have to call this method using the Module name i.e.

"Test1.show" -----------------------------------------------------------------------------------------------------------
File :  testModule.rb
------------------------------------------------------------------------------------------------------------

module Test
    def show
        print "From method Show"
    end
end

module Test1
     def Test1.show
         print " From Method Show from Module Test1"
     end
end

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

Now create another ruby file for ruby class , let demo.rb
------------------------------------------------------------------------------------------------
require File.dirname("File path ")+"/ testModule"

class Demo
include Test
include Test1

   def  demoMethod
      print " from demoMethod"
       Test1.show
   end

end

test=Demo.new
test.demoMethod
test.show


Description : "require" is the keyword which is similar to include and import in c/c++ and java

The required keyword search for the file from $LOAD_PATH , if not not found , there would be a error as file not found, So in this case you can give the file path name followed by the file name.

Test1.demo is just similar as static method call using class name reference in java

If the module name is not used before the method name at the time of defining it, then that method can be called using the used call object. here in the above example it is Demo and test is the object of the Demo class.


Tuesday, March 20, 2012

Tutorials on ruby

The most intresting language after java is ruby , may be something more than java. Honestly I do not want to hurt the java developer anyway. Here is a below sample program which will give you a sample IDEA of ruby language. It is really a pure object oriented language.

class TestClass
 @@fname=""
 @@lname=""
 @@val="Bhubaneswar"
 
 def initialize(fname,lname)
  @fname=fname
  @lname=lname
 end

 def testMethod(val)
  puts("Inside the Method")
  puts("The Global Value is '#{@fname}' and '#{@lname}'")
  @val=val
  puts("The Local Value is '#{@val}'")
  puts("The Local Value is '#{@@val}'")
 end
end
obj=TestClass.new("khirod","Patra")
obj.testMethod("Delhi")


Description: TestClass is the name of the class must be stared with a capital letter. @@fname,@@lname,@@val are the class variable. The class variab;e declared with @@ symbol and the instance variable declared with single @ symbol. In the method testMethod you can see the instance variable i.e. @val . So if you want to access the class variable or the instance variable , you have to prefix with @@ or @ symbol with variable name, Incase if you have same variable name

Questions are welcome...