How to test JBoss server is started from external java application - java

how can i test from external java application that my server jboss is running ?
I've a JBoss (4.2.3) server and I want know from a stand-alone java application if that server i started or not.
Thanks!
EDIT
I don't have access to the jboss machine and the jmx console is disabled for safety reasons.

You can check inspecting the running processes if you have access to the machine where jboss is running.
If you don't have access to the machine, then you'll have to try to connect to it, checking if it's listening to the http port or if you can reach it via JMX, but then you can't be sure if it's really not running or if some firewall rule is blocking your request.

One of the possible solution if you are running on linux is to execute a shell command like
ps -ef | grep jboss >> somelog.txt
execute it using Runtime class using exec() method in Runtime and check the output of that command from your java program
Surely there might be some other better alternative , but this is just a simple thought

Related

Jetty web server refusing connections on linux

I am in the process of developing a java web application, and am using the web framework Spark which utilizes Jetty (An http server written in java created by eclipse). Spark makes use of Jetty's embedded webserver functionality, essentially creating a Jetty instance within the app. When creating an executable jar of my application and running on windows, all is well and I can connect to my app locally through http://localhost:81 (I am using port 81). Eventually, I'd like the app to run on a linux server, but upon executing the jar on ubuntu, I am unable to connect to the app locally. I only have a moderate understanding of linux, and cannot figure out why this is happening. I am executing the command 'java -jar G2.jar &' in screen, and it seems to be executing properly. I have ensured that the JDK on ubuntu matches the version installed on my windows machine. I have been testing on an AWS ec2 ubuntu instance and an ubuntu vm, and have had no luck on either.
wget:
wget 127.0.0.1:81
--2016-10-24 21:10:24-- http://127.0.0.1:81/
Connecting to 127.0.0.1:81... failed: Connection refused.
curl:
curl 127.0.0.1:81
curl: (7) Failed to connect to 127.0.0.1 port 81: Connection refused
I have flushed iptables, and even disabled ufw with no luck. Both the ec2 instance and vm are fresh ubuntu installs. I am beginning to think the problem is within Jetty, and that it possibly requires different configuration on linux? The issue is, Spark handles the embedded Jetty instance, and I am unfamiliar with how it does so. Has anybody dealt with this type of issue before?
I fixed the issue. I figured that using the '&' at the end of the command to run the app as a background process would work fine, but guess it does not. Instead, I just used sudo without the '&' and it works now.

Profiling tomcat application with VisualVM

I am trying to run visualvm under the username tomcat6 because apparently visualvm can only find applications running under its username. So by default it is only finding applications running under my username. I have been able to connect visualvm with tomcat6 through jmx but that lacks the fine granularity of instrumented profiling.
I tried the following to run visualvm under the username tomcat6 but got the following error that I don't understand.
$ sudo -u tomcat6 jvisualvm
No protocol specified
Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:115)
...
If the computer running your application is remote -- like a server -- then you can't run GUI applications without some work. It's probably going to be easier to enable remote access to VisualVM.
You can use two techniques to attach to a remote JVM: using jstatd or using JMX. I'm not sure what you think you are losing by using JMX, but evidently jstatd doesn't give you access to profiling tools, CPU monitor, etc.).
You need to configure your JVM and Tomcat to allow for remote access. That requires 3 steps:
Enable remote JMX. Turns out, there's a guide for that.
Fix the "wandering port" used for RMI. There's a guide for that, too.
(Optional) Arrange for secure remote-access to the server. The easiest way to do that would be to use ssh -Lport:localhost:port with a series of -L arguments to forward multiple ports from your workstation to your server. Map all the ports you had to configure in steps #1 and #2. If you don't do this, you'll need to have non-firewalled access to all the aforementioned ports.
Restart your JVM and connect with JVisualVM.
Update 2022-06-01
Note that the "wandering port" problem has been fixed at the JVM level, so there is no need for application (i.e. Tomcat) support for that. Item #1 for Tomcat 8.5 and later contains updated instructions making item #2 unnecessary with a recent JVM.
Unfortunately only sampling is available in remote mode so JMX will lack instrumentation tools.
Actually your approach to running visualvm under tomcat6 user is correct. You should take a look at this question on how to run X11 applications under sudo.
The easiest way to pass DISPLAY and XAUTHORITY environment variables is to use sudo -E command to preserve current user environment.
Also if you can't see your process under tomcat6 user you should check if CATALINA_TMPDIR is pointing to /tmp. Otherwise you should pass it to visualvm
jvisualvm -J-Djava.io.tmpdir="${CATALINA_TMPDIR}"
Actually there is a lot of alternatives like yourkit or jprofiler shipped with java agents which allows remote instrumentation profiling.
The easiest is to open a remote JXM port on Tomcat in order to be able to remotely (from your desktop computer) connect to your remote Tomcat (on your server) with jvisualvm.
You need to pass the following system properties to your JVM :
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=<whatever_port_you_want>
-Dcom.sun.management.jmxremote.ssl=false
Then open jvisualvm on your local computer (JVM version needs to be the same or newer), File -> Add Remote Host -> Enter the name on the Host. It will create an entry for this host. Right lick on this Entry -> Add JMX connection -> Enter the port -> OK
jvisualvm will then be able to access remotely to your application.
You can also secure the connection if needed by using the following system properties (you need to create the files and locate them where you want :
-Dcom.sun.management.jmxremote.password.file=jmxremote.password
-Dcom.sun.management.jmxremote.access.file=jmxremote.access
These properties needs to be added to the CATALINA_OPTS environment variable. Fr exemple :
export CATALINA_OPTS = "$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8888 "
More info on JMX lies here : https://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html
I tried to do something similar but I was not allowed to install JVisualVM on the server. Having JVisualVM connect to the remote machine never seemed to work correctly. I suspect firewall rules were blocking part of the the network connections.
The only way I found to remotely profile the server was via an ssh tunnel.
Set the JMX port in CATALINA_OPTS on the server
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.port=13333 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false; export CATALINA_OPTS
On your desktop machine open an ssh connection to the server
ssh -D 61444 username#tomcat.server.address
Add a flag to JVisualVM so that it will proxy its network connection
"C:\Program Files\Java\jdk1.7.0_79\bin\jvisualvm.exe" -J-Dnetbeans.system_socks_proxy=localhost:61444 -J-Djava.net.useSystemProxies=true
Have JVisualVM connect to the jmxport and the network traffic is tunneled via ssh.
Good luck.

How much info about JBoss can I get from Linux CLI

How much info can I get about the JBoss instances running on a linux server. I would like to be able to see what modules are loaded in each server, what ports are used and if the loaded apps are working. I would like to do this in a lightway way using only avaliable commands on Linux.
So far all I have is:
pgrep -f jboss
Wich gives me the pid of the java instances running JBoss.
To get some internal informations from a running JBoss instance you can use it's command line interface.
Good point to start would be https://docs.jboss.org/author/display/AS71/CLI+Recipes

Running a Java project remotely

I've got this new project at work. We are using Eclipse for the project. There are two run configurations, server and client. I have to launch the server and the client independently, and connect to the server using the client. Now, it so happens that this has to be done on both Windows and Linux. (four possible combinations: WS-LC, WC-LS, WS-WC, LS-LC, where W-windows, L-linux, C-client and S-server)
I have Linux on my machine (in which Eclipse is running) and run Windows on a VM. Is there a way I can make Eclipse launch the application in the VM?
I understand I have to build the application locally to a shared folder and send a launch command to windows (using openssh?, not sure). What are the best practices used in this scenario.
EDIT: I need to use this during development, to test my changes to the code. The same application provides both client & server. (yes, horrible, i know :X )
You can publish the server functions as JMX Beans using the MBean interface standard. Then use JMX Console to remotely connect to the server JVM and launch the application.
Eclipse has integration points for remote servers, look to "tomcat configuration" for an example of how it integrates with one remote server.
Whether your application can use an existing server integration solution or not depends heavily on details which aren't present. If you want to actually launch a stand-alone Java process from your remote machine, you generally need a program to capture the request and launch the process.

What is Tomcat Running?

I'm trying to see if a WAR I just built is even running inside of Tomcat (7.0.19). I am deploying to a linux box and so my only two options are the Tomcat admin console (web app) or, hopefully, determining webapp status through the terminal.
I already know how to get in through the console web app; I am wondering if there is any way to see the status (ACTIVE/INACTIVE/TERMINATED, etc) of deployed web apps from the terminal.
Thanks in advance.
PSI-Probe is a great application for monitoring your applications deployed to a tomcat instance. It will tell you if an application is running or down. If the application is not deployed, it will simply not be in the list.
curl --user user:pass http://localhost:8080/manager/text/list
It prints
OK - Listed applications for virtual host localhost
/manager:running:0:manager
/docs:running:0:docs
/examples:running:0:examples
/host-manager:running:0:host-manager
/myapp:running:0:myapp
Your user needs the manager-script role. Documentation: Manager App HOW-TO, List_Currently_Deployed_Applications
You can probably do it using JMX.
Find appropriate MBean that shows this information on local tomcat using regular JConsole. If you want to connect JConsole to remote you will probably have some problems with firewall, so you have other solution.
Take command line JMX client and run it on the monitored host through SSH terminal. I used the following command line JMX client: cmdline-jmxclient-0.10.3.jar
wget http://<username>:<password>#<hostname>:<port>/manager/list -O - -q
(Not sure about Tomcat 7 though)

Categories