Thursday, January 31, 2013

Tomcat with JMX

If you want to add JMX capability to your tomcat, do the following:


in your $tomcat/conf/server.xml, add the following (in bold)


<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener"   miRegistryPortPlatform="10099" rmiServerPortPlatform="9595" />




In addition, add to your $tomcat/lib/ directory the JAR that gives this JMX capability , called catalina-jmx-remote.jar
I can see that you can find it here:





Wednesday, January 30, 2013

Unlocker - file handling detector

Simple copy/paste from this URL http://www.filehippo.com/download_unlocker/


If you've ever been unable to delete a file in Windows, and can't figure out what program's using it, Unlocker is the solution. Have you ever seen these Windows error messages?
  • Cannot delete folder: It is being used by another person or program
  • Cannot delete file: Access is denied
  • There has been a sharing violation.
  • The source or destination file may be in use.
  • The file is in use by another program or user.
  • Make sure the disk is not full or write-protected and that the file is not currently in use.
Unlocker can help! Simply right-click the folder or file and select Unlocker. If the folder or file is locked, a window listing of lockers will appear. Simply click Unlock All and you are done!






Tuesday, January 1, 2013

Problem during access to JMX bean (attribute / operation)


Once again, I've failed at the exact same place ...
I tried to access a JMX bean programatically ... Everything went well (I'm using this wonderful spring infra for accessing my bean).

BUT ... when you try to access a bean that is not well exposed, according to standard, this won't work:

If you expose an operation (and not as attribute) that looks like
public String getServiceStatus()

since it starts by the prefix get , it doesn't receive argument and it returns a value (not a void).
The standard requires that such method should be at least defined as attribute in the JMX server. If it is not, the javax.management.MBeanServerInvocationHandler   won't be able to access the operation.



You can see that in the invoke() method of this MBeanServerInvocationHandler()


      if (methodName.startsWith("get")
                    && methodName.length() > 3
                    && nargs == 0
                    && !returnType.equals(Void.TYPE)) {
                    return connection.getAttribute(objectName,
                        methodName.substring(3));
                }



So the way I've found for overcoming this obstacle was ... to call another bean :(


Here's an example of Spring usage for accessing JMX bean (it's not mine but it's similar):


<bean id="clientConnector"
      class="org.springframework.jmx.support.MBeanServerConnectionFactoryBean">
  <property name="serviceUrl" value="service:jmx:rmi://remotehost:9875"/>
</bean>

<bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
  <property name="objectName" value="bean:name=testBean"/>
  <property name="proxyInterface" value="org.springframework.jmx.IJmxTestBean"/>
  <property name="server" ref="clientConnector"/>
</bean>

Thursday, December 13, 2012

GIT for beginners (and me)

Starting working with GIT ( I'm currently using SVN and I used in the past ClearCase rip) .
Here are some useful commands :

  • git init    - for initializing the .git/  repository in your current directory
  • git status -  return which files should be committed etc ...
  • git add  - mark files for the repository , so you remember to commit them later on. Those file will become candidate for commit
  • git add \*.java  - will add recursively ALL the java files 
  • git commit -m "My comment about this commit"  - obvious
  • git branch -b BranchName  - switch to the BranchName branch
  • git checkout -b NewBranchName  - copy your current branch into another NewBranchName
  • git branch - show all your defined branches and indicate what is your current branch
  • git reset --hard HEAD  - revert to the HEAD version, overwirting any local change (hard)
  • git merge show_michael  (didn't use it yet)
Here are some good links (as it seems to me now that some bullet in my summary are incorrect)


Another tutorial suggested to me today :
http://pcottle.github.io/learnGitBranching/

And some interesting procedure for working with SVN while working with git:


git stash list  
git stash drop     <<== Delete stash
git stash list  
git status
git stash       <<== save in a stash backup all the dirty files (the one that were not committed. but not the ones which are not yet added only to git )
git stash list
git status
git checkout master   <<== go to master , when your current branch is clean (no stash anymore)
svn update    <<= update with SVN
git status
git add .       <<= this is the quick way to get it all your svn update to your git
git status
git commit -m "svn update"  
git status
git checkout oauth  <<== return back to your working branch 
git status
git merge master oauth  <<== merge, for getting all the SVN update (but using git now)
git status
git stash apply  <<== retrieve the stash dirty files ... 
git status
history

Monday, November 19, 2012

How to synchronize clock between time

In order to synchronize the clock time between servers, you must have one reference server. In our example tlvntp1.tlv.lpnet.com
Then, all your server should refer to it . That's the way to do it:

1) In your file /etc/ntp.conf, you should have the following line:

server tlvntp1.tlv.lpnet.com
My System Administrator did the following shortcut:
echo server tlvntp1.tlv.lpnet.com > /etc/ntp.conf

But be careful with it, since it may delete other synchronization option the file already has.


2) To be synchronized with our IT ntpserver (the one with the good clock time)
service ntpd restart

3) Then ntpq -p
to display what the offset with the synchronized server  (the tlvntp1) 
The offset should reduce after few minutes ....

This apparently means what is the offset between your current server and the referenced ntp server ( here, for ex, rstm02 and rstm18 etc ...)
michaelz@roor-wto128:~$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+rstm02.lpdomain 64.236.96.53     2 u  162 1024  377    0.320    4.600   0.049
+rstm18.lpdomain 204.9.54.119     2 u  150 1024  377    0.337    5.579   0.063
*rstm09.lpdomain 64.236.96.53     2 u  173 1024  377    0.358    1.196   0.035
 rstm07.lpdomain 172.16.22.71     2 u  551 1024  377    0.777  -42.128   3.369
 rstm06.lpdomain 172.16.22.71     2 u  884 1024  377    2.675  -94.770  96.884


Same, but without host name resolving (-n option)
michaelz@roor-wto128:~$ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+10.16.23.11     64.236.96.53     2 u  168 1024  377    0.320    4.600   0.049
+10.16.22.18     204.9.54.119     2 u  156 1024  377    0.337    5.579   0.063
*10.16.23.21     64.236.96.53     2 u  179 1024  377    0.358    1.196   0.035
 10.16.22.61     172.16.22.71     2 u  557 1024  377    0.777  -42.128   3.369
 10.16.22.71     172.16.22.71     2 u  890 1024  377    2.675  -94.770  96.884


4) Synchronize time between two servers
In order to synchronize the time between two different servers (no need to have an ntp server in between):

ntpdate -u the-second-host-server





To synchronize your Windows with an external NTP server, do the following:
net time \\tlvdc1 /set /y    
where, tlvdc1 is the host  name of yoru NTP server

Monday, October 29, 2012

Change background color in linux/unix terminal xterm

 Useful link for modifying the background color.
Especially useful when working with multiple terminal, on different machines ...


http://unix.stackexchange.com/questions/16120/in-bash-how-can-i-change-the-color-of-my-command-prompt

Put in your ~/.bashrc

# Color mapping
grey='\[\033[1;30m\]'
red='\[\033[0;31m\]'
RED='\[\033[1;31m\]'
green='\[\033[0;32m\]'
GREEN='\[\033[1;32m\]'
yellow='\[\033[0;33m\]'
YELLOW='\[\033[1;33m\]'
purple='\[\033[0;35m\]'
PURPLE='\[\033[1;35m\]'
white='\[\033[0;37m\]'
WHITE='\[\033[1;37m\]'
blue='\[\033[0;34m\]'
BLUE='\[\033[1;34m\]'
cyan='\[\033[0;36m\]'
CYAN='\[\033[1;36m\]'
NC='\[\033[0m\]'
Step 2. Re-define your PS1 variable:
PS1="$yellow[$CYAN\t$yellow][$red\H$yellow][$GREEN\w$grey$yellow]$NC# "
 
 
 or more details also can be found here:
 
https://wiki.archlinux.org/index.php/Color_Bash_Prompt
 

Prompt escapes

The various Bash prompt escapes listed in the manpage:
Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows: \a an ASCII bell character (07) \d the date in "Weekday Month Date" format (e.g., "Tue May 26") \D{format} the format is passed to strftime(3) and the result is inserted into the prompt string an empty format results in a locale-specific time representation. The braces are required \e an ASCII escape character (033) \h the hostname up to the first `.' \H the hostname \j the number of jobs currently managed by the shell \l the basename of the shell's terminal device name \n newline \r carriage return \s the name of the shell, the basename of $0 (the portion following the final slash) \t the current time in 24-hour HH:MM:SS format \T the current time in 12-hour HH:MM:SS format \@ the current time in 12-hour am/pm format \A the current time in 24-hour HH:MM format \u the username of the current user \v the version of bash (e.g., 2.00) \V the release of bash, version + patch level (e.g., 2.00.0) \w the current working directory, with $HOME abbreviated with a tilde \W the basename of the current working directory, with $HOME abbreviated with a tilde \! the history number of this command \# the command number of this command \$ if the effective UID is 0, a #, otherwise a $ \nnn the character corresponding to the octal number nnn \\ a backslash \[ begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt \] end a sequence of non-printing characters
 

Thursday, September 13, 2012

XMing + Putty for remote desktop on ubuntu

Well, I didn't work with Remote Desktop but I was told (Omri) that I can work instead with specific remote application, using XMing + Putty.

Explanation there:
http://www.math.umn.edu/systems_guide/putty_xwin32.html


In few word, start XMing server.
Then, run putty and configure your SSH session to your remote desktop / ubuntu use X-Forwarding.

Then, the putty console can open XTerm and all other graphics ...