Adding host name in wrapper.conf - java

I'm using Java Service Wrapper (here) v. 3.2.3 on Linux RHEL 5.4.
I need to add hostname to system properties (see here):
wrapper.java.additional.13=-DHOSTNAME="%WRAPPER_HOSTNAME%"
The problem is that WRAPPER_HOST_NAME Since ver.3.3.2, WRAPPER_HOSTNAME Since ver.3.3.6.
Is there're a way to use external command to get hostname?
Is there any other unique system property I can use across several identical machine?

If running on Windows, try
wrapper.java.additional.13=-DHOSTNAME="%COMPUTERNAME%"

Related

Set TNS Name admin path while running a component from Java

Currently I m running a component (IBM WTX tool) from Java using the jars provided by IBM. In the WTX component I am connecting to a oracle database using tns connect identifier. While the running the component independently the tool picks up the tnsnames.ora of the oracle driver installed in my system and it works fine. But when running the same component from Java it could not resolve the tnsname and fails. Do we need to do any additional setup in Java Side?
I tried System.setProperty("oracle.net.tns_admin",""). But It didn't work.
Can anyone help on the issue?
Regards,
TNS_ADMIN must be set in the environment before the Java process is started. I don't think it can be set from within Java - or at least I haven't seen it done successfully before. Typically I have see this set from a shell script that also launches the Java program.

Tomcat debugging not possible through eclipse

I've made a script called debug.sh and placed it under the bin directory (start it with ./debug.sh) to start Tomcat 8 in debugging mode:
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
bash catalina.sh jpda start
But if it started, there is now message which says, that Tomcat is listening on port 8000. Also if I type
netstat -nat
there is no application listening on port 8000.
What exact configuration do I have to set, to remote debug my Tomcat 8 server which is running on a specific IP or do I have just a little problem in my script?
This answer has been updated following the comments, I did not understand the problem in the first place.
I guess you have followed that doc: this is about developing Tomcat itself.
I am not sure you are using the proper way to configure the port (I don't know your specific configuration details). In a standard environment, the ports are configured in the server.xml (note that several different ports are used by Tomcat for the different services).
To remotely monitor your server, you should use a JMX client. As far as I know, Eclipse doesn't include one (or at least not one documented) - you could code one as this is a Java specification (JSR262). You have one in a standard Java environement (JConsole). By default, JMX is not enabled on Tomcat. If you need to enable it, the fine way is to follow the doc.
Tomcat JMX monitoring and JConsole are both available in most versions of Tomcat and the Java runtime.
The following exchange seems to be about your problem.

Tomcat caches old dns entry of Single Sign On system‏

I have Tomcat 6.0.14 (installed in RedHat Linux 5.5 and with Java 6 update 13) integrated with a SSO (Single Sign On) system.
When SSO fail overs to a different data center (and SSO's IP address changes) the Tomcat continues to stick to the old DNS entry of the SSO system.
I then have to restart the Tomcat container so that it picks the new DNS of the SSO system. I have to restart the Tomcat every time SSO system fails over to different data center.
Is there a way to configure Tomcat to refresh DNS with out restarting when SSO fails over?
The problem here isn't Tomcat specific, but rather specific to the virtual machine. In particular, see the documentation for InetAddress. This answer provides the solution, but I'll give some options for completeness:
There seem to be three options:
Edit the java.security file found in $JRE_HOME/lib/security and change the networkaddress.cache.ttl to something sensible instead of -1 (the default more or less).
Modify the command that launches Tomcat to change the setting, i.e. at the parameter -Dsun.net.inetaddr.ttl=xxx where xxx is some sensible value.
Change it within your app by running: java.security.Security.setProperty("networkaddress.cache.ttl" , "xxx");

Java proxy settings - Ubuntu

How do I set the Java proxy settings in Ubuntu (10.04 or 12.04), from the command line?
What I am aiming at is to get direct connection, but by default it takes it from browser settings which are meant to go via a proxy - just I don't want Java to go via the proxy.
I am running an application server in Ubuntu which serves remote desktop sessions. I can put the Java control panel into the user's desktop, and then they (each individual user) can set the proxy settings under Network Settings. However - this means I have to tell each user to make this setting, which is not workable.
I want it set via some command line or environment variable on the server itself, so it defaults to "direct connection". I am not familiar with Java programming and it won't help much to give me Java code for this, I think it must be possible to set the defaults upon Java startup? Any pointers are welcome.
How can I do this?
Instead of command line you can edit $javaDirectory/jre/lib/net.properties.
Remove # in-front of:
http.proxyHost="proxy host"
http.proxyPort="proxy port"
https.proxyHost="proxy host"
https.proxyPort="proxy port"
and set your proxy there.
You can export the http_proxy environment variable via command line.
Ex:
$ export http_proxy=http://proxy-server:port
There is a environment variable ftp_proxy also, just in case you need it.

Why is there no local MBeanServer if Tomcat runs as a Windows service?

If Tomcat runs as a Windows service (created using the Windows Tomcat installer) you can't simply enable JMX using -Dcom.sun.management.jmxremote. You also need to set -Dcom.sun.management.jmxremote.port=<port>. This is, among other places, explained here: Unable to use JConsole with Tomcat running as windows service
However, I haven't found an explanation anywhere WHY this is the way it is.
I was a bit lost and confused when I wrote the question. Here's what I've learned in the meantime. Usually the Tomcat Windows service runs under the local system account. That's the main reason for all the fuss.
If you simply set -Dcom.sun.management.jmxremote in the service config's JVM settings JMX will be enabled indeed. If you have a JMX client that runs in the same JVM instance (e.g. because it's baked into the application itself) you can get a hold of the MBeanServer like so: MBeanServerFactory.findMBeanServer(<specific-agent-ID-or-null>). However, JConsole won't list this Tomcat process. It's all explained here: https://blogs.oracle.com/nbprofiler/entry/monitoring_java_processes_running_as.
As explained elsewhere, if this is not good enough you also need to set -Dcom.sun.management.jmxremote.port=<port>. Then you can connect to JMX with JConsole using localhost:<port>. From Java code this can be achieved using:
JMXServiceURL target = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:<port>/jmxrmi");
JMXConnector connector = JMXConnectorFactory.connect(target);
connector.getMBeanServerConnection();

Categories