As my colleague Robert described in his article “How to automate OpenCms module import ” we set up an automatic deployment process for one of our projects. However, we experienced some trouble with our way to check whether the app server finished starting up. We were using a simple grep command to observe the server log and it sometimes failed for no apparent reason:
1until tail -n 1 server.log | grep "Started"; do sleep 0.01; done
We wanted to find a better way for solving this issue. I only overheard the conversation passing by, but I didn’t get it out of my head even after hours …
For we are using a JEE compliant server (JBoss) I wanted to probe JMX for it is the designated monitoring interface. I was about to write a little JMX client that probes the desired MBean, but while fiddling with the issue I came across an even easier solution: JBoss offers a little helper out of the box that is up to the task in no time and saved me a late night coding session. It’s a little tool called twiddle:
JBoss’ description is self-explanatory:
“A JMX client to ‘twiddle’ with a remote JBoss server.”
Just what we needed! Now we only had to decide which MBean to probe. As “are u there?” is one of the most basic things to ask for this wasn’t too hard either:
1twiddle.sh get jboss.system:type=Server Started
As soon as this returns true the server is up and running.
Robert immediately pimped our little script accordingly:
1function twiddleTheBoss { 2 echo `twiddle.sh get "jboss.system:type=Server" Started | \ 3 awk -F "=" '{ print $2 }'` 4} 5 6... 7 8local STARTED="starting" 9until [ $STARTED == "true" ]; do 10 sleep 20s 11 STARTED=$(twiddleTheBoss) 12done 13 14...
Easy and reliable, just what we wanted 🙂
More articles
fromNick Prosch
Your job at codecentric?
Jobs
Agile Developer und Consultant (w/d/m)
Alle Standorte
More articles in this subject area
Discover exciting further topics and let the codecentric world inspire you.
Gemeinsam bessere Projekte umsetzen.
Wir helfen deinem Unternehmen.
Du stehst vor einer großen IT-Herausforderung? Wir sorgen für eine maßgeschneiderte Unterstützung. Informiere dich jetzt.
Hilf uns, noch besser zu werden.
Wir sind immer auf der Suche nach neuen Talenten. Auch für dich ist die passende Stelle dabei.
Blog author
Nick Prosch
Head of Feelgood Management
Do you still have questions? Just send me a message.
Do you still have questions? Just send me a message.