Issue with openjdk:17 docker image - java

I'm using the openjdk:17 docker image, the os is Oracle Linux Server v8.5. I ssh into the container with root user and found almost all common commands are not available. I have tried ps, pidof etc but getting command not found error. I'm trying to add a preStop hook to kill the java process gracefully but need a command to find the java process. Any idea how to achieve this?
Here is the output of ls -l /proc/*/exe. There sees to be a number of pid associated to the java process, but I'm sure I only have one. What is the clear way to find the pid and kill it? one liner is preferred
lrwxrwxrwx 1 root root 0 Mar 3 16:45 /proc/1/exe -> /usr/java/openjdk-17/bin/java
lrwxrwxrwx 1 root root 0 Mar 3 20:35 /proc/106/exe -> /usr/bin/bash
lrwxrwxrwx 1 root root 0 Mar 3 20:45 /proc/164/exe -> /usr/java/openjdk-17/bin/jshell
lrwxrwxrwx 1 root root 0 Mar 3 20:45 /proc/185/exe -> /usr/java/openjdk-17/bin/java
lrwxrwxrwx 1 root root 0 Mar 3 21:15 /proc/self/exe -> /usr/bin/coreutils
lrwxrwxrwx 1 root root 0 Mar 3 21:15 /proc/thread-self/exe -> /usr/bin/coreutils

Related

Keep link to /etc/alternatives/jre when switching java

I have 2 java on my server, where I installed java8 first, then java 11
by default, there is no jre -> /etc/alternatives/jre
[root#server-1:jvm]# ls -all
...
lrwxrwxrwx 1 root root 26 Mar 17 09:10 java -> /etc/alternatives/java_sdk
drwxr-xr-x 9 root root 215 Mar 17 09:10 java-11-amazon-corretto
drwxr-xr-x 3 root root 17 Mar 17 07:17 java-1.8.0-amazon-corretto.x86_64
While after I set the default java with alternative command, the link to /etc/alternatives/jre is created automatically
[root#server-1:jvm]# alternatives --config java
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
+ 1 /usr/lib/jvm/java-1.8.0-amazon-corretto.x86_64/jre/bin/java
* 2 /usr/lib/jvm/java-11-amazon-corretto/bin/java
Enter to keep the current selection[+], or type selection number: 2
[root#server-1:jvm]# ls -all
...
lrwxrwxrwx 1 root root 26 Mar 17 09:10 java -> /etc/alternatives/java_sdk
drwxr-xr-x 9 root root 215 Mar 17 09:10 java-11-amazon-corretto
drwxr-xr-x 3 root root 17 Mar 17 07:17 java-1.8.0-amazon-corretto.x86_64
lrwxrwxrwx 1 root root 21 Mar 17 09:21 jre -> /etc/alternatives/jre <<<<< i want to keep this
But once I switch back to java8, the jre -> /etc/alternatives/jre was removed.
How can I keep the link?
UPDATE: example problem what to be solved
A application have to access the cacert file in java, e.g.
***/usr/lib/jvm/java-1.8.0-amazon-corretto.x86_64/jre***/lib/security/cacerts
***/usr/lib/jvm/java-11-amazon-corretto.x86_64***/lib/security/cacerts
So I would like to have the /usr/lib/jvm/jre or /etc/alternatives/jre pointing to the java home
In case of corretto8
/usr/lib/jvm/jre -> /etc/alternatives/jre -> /usr/lib/jvm/java-1.8.0-amazon-corretto.x86_64/jre
In case of corretto11 (which the 'alternative' already did if I switch to )
/usr/lib/jvm/jre -> /etc/alternatives/jre -> /usr/lib/jvm/java-11-amazon-corretto.x86_64

zookeeper Starting error :'JAVA_HOME error in zookeeper.out'

When I do
bin/zkServer.sh start #It shows it has started
ZooKeeper JMX enabled by default
Using config: /data/sparkHA/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
Afetr few second when i check status, I got
ZooKeeper JMX enabled by default
Using config: /data/sparkHA/zookeeper-3.4.9/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
My zookeeper.out says
nohup: failed to run command â/usr/bin/java/bin/javaâ: Not a directory
But my JAVA_HOME in bashrc is usr/bin/java, How come one extra /bin/java is added , that results in an invalid directory.
Also echo $JAVA_HOME outputs
/usr/bin/java
How to approach this error. Please Help. Thanks.
Also tried setting JAVA_HOME in zkServer.sh also by following Zookeeper not starting, nohup error but getting same error.
Your JAVA_HOME point to /usr/bin/java file but it should point to root directory of your JDK. For example for me this is:
➜ ~ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home
➜ ~ ll $JAVA_HOME
total 52064
-rw-rw-r-- 1 root wheel 3.2K Oct 1 09:00 COPYRIGHT
-rw-rw-r-- 1 root wheel 40B Oct 1 09:01 LICENSE
-rw-rw-r-- 1 root wheel 159B Oct 1 09:01 README.html
-rwxrwxr-x 1 root wheel 108K Sep 22 22:49 THIRDPARTYLICENSEREADME-JAVAFX.txt
-rw-rw-r-- 1 root wheel 173K Oct 1 09:01 THIRDPARTYLICENSEREADME.txt
drwxrwxr-x 46 root wheel 1.5K Oct 1 09:04 bin
drwxrwxr-x 9 root wheel 306B Oct 1 09:00 db
drwxrwxr-x 9 root wheel 306B Oct 1 09:00 include
-rwxrwxr-x 1 root wheel 4.9M Sep 22 22:49 javafx-src.zip
drwxrwxr-x 10 root wheel 340B Oct 1 09:02 jre
drwxrwxr-x 14 root wheel 476B Oct 1 09:02 lib
drwxrwxr-x 5 root wheel 170B Oct 1 09:01 man
-rw-rw-r-- 1 root wheel 529B Oct 1 09:01 release
-rw-rw-r-- 1 root wheel 20M Oct 1 09:01 src.zip
So, try to set valid path to JDK root directory. I think it should fix your problem.

how do i find where JAVA_OPTS data is stored?

A CentOS 7 server has Java 7 and tomcat 8 installed. I need to set the permgen space, but typing printenv on the command line does not include JAVA_OPTS in the list of environmental variables. I typed ps to get the list of running processes, and then I typed jmap -heap <pid> with the pid from the running java process, which listed values for MaxPermSize and PermSize among other values.
How do I set new values for these properties in a way that will persist when the system is rebooted, etc.? I hesitate to just create a JAVA_OPTS variable if the server in question has another place where it stores these persistent values.
EDIT:
As per #ChrisRobak's suggestion, I went searching for tomcat conf files. There is no /etc/tomcat directory, but /etc has directories called /etc/java, /etc/.java, /etc/jvm, and /etc/jvm-common. Also, the tomcat conf is as follows:
[root#myserver tomcat]# cd /opt/tomcat/conf
[root#myserver conf]# ls -al
total 280
drwxrwx---. 3 root root 4096 Oct 30 20:02 .
drwxr-xr-x. 14 root root 4096 Oct 30 20:58 ..
drwxrwx---. 7 root root 4096 Oct 30 21:00 Catalina
-rwxrwx---. 1 root root 12624 Nov 2 2014 catalina.policy
-rwxrwx---. 1 root root 6560 Nov 2 2014 catalina.properties
-rwxrwx---. 1 root root 1852 Jan 2 2015 context.xml
-rwxrwx---. 1 root root 3451 Nov 2 2014 logging.properties
-rwxr-x--- 1 root root 5018 Oct 30 21:52 server.xml
-rwxrwx---. 1 root root 1783 Nov 2 2014 tomcat-users.xml
-rwxrwx---. 1 root root 1888 Nov 2 2014 tomcat-users.xsd
-rwxrwx---. 1 root root 168082 Nov 2 2014 web.xml
[root#myserver conf]#
Which file should I look in?
Alternatively, is there a command line way of setting the Java options which will not only be persistent, but also not cause side effects due to conflicts with config files? I would just create a JAVA_OPTS variable if I thought the rest of the server would go to the JAVA_OPTS as the default.
ANSWER?
When none of the config files and scripts seemed to have JAVA_OPTS set, I finally just decided to type the following in the CENTOS 7 terminal:
export JAVA_OPTS="-Xms256m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m"
The result is that the MaxPermSize has been reset. If anyone else has a specific answer to CentOS 7 that is better than this, please alert me.
I think you can persist those in
/etc/tomcat8/tomcat8.conf
or a similar variant, the server i had access to was /etc/tomcat5/tomcat5.conf but i don't know about your version in particular

JConsole location in Linux

I am trying to run jconsole from my machine but I can't find the location of the .sh . I have tried finding it in different directories and setting JAVA_HOME to the jdk.
$which java
/usr/bin/java
$java -version
java version "1.7.0_51"
OpenJDK Runtime Environment (rhel-2.4.4.1.el6_5-x86_64 u51-b02)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
$whereis java
java: /usr/bin/java /etc/java /usr/lib/java /usr/share/java /usr/share/man/man1/java.1.gz
I looked in /usr/lib/jvm and I found
drwxr-xr-x. 3 root root 4096 Apr 23 2013 java-1.5.0-gcj-1.5.0.0
drwxr-xr-x. 3 root root 4096 Jan 27 2014 java-1.6.0-openjdk-1.6.0.0.x86_64
drwxr-xr-x. 3 root root 4096 Feb 5 2014 java-1.7.0-openjdk-1.7.0.51.x86_64
lrwxrwxrwx. 1 root root 21 Feb 5 2014 jre -> /etc/alternatives/jre
lrwxrwxrwx. 1 root root 27 Apr 23 2013 jre-1.5.0 -> /etc/alternatives/jre_1.5.0
lrwxrwxrwx. 1 root root 26 Apr 23 2013 jre-1.5.0-gcj -> java-1.5.0-gcj-1.5.0.0/jre
lrwxrwxrwx. 1 root root 27 Feb 5 2014 jre-1.6.0 -> /etc/alternatives/jre_1.6.0
lrwxrwxrwx. 1 root root 37 Feb 5 2014 jre-1.6.0-openjdk.x86_64 -> java-1.6.0-openjdk- 1.6.0.0.x86_64/jre
lrwxrwxrwx. 1 root root 27 Feb 5 2014 jre-1.7.0 -> /etc/alternatives/jre_1.7.0
lrwxrwxrwx. 1 root root 38 Feb 5 2014 jre-1.7.0-openjdk.x86_64 -> java-1.7.0-openjdk-1.7.0.51.x86_64/jre
lrwxrwxrwx. 1 root root 25 Apr 23 2013 jre-gcj -> /etc/alternatives/jre_gcj
lrwxrwxrwx. 1 root root 29 Feb 5 2014 jre-openjdk -> /etc/alternatives/jre_openjdk
and in java-1.7.0-openjdk-1.7.0.51.x86_64/jre/bin/, I only found
[root#portal01 bin]# ll
total 200
-rwxr-xr-x. 1 root root 9536 Jan 14 2014 java
-rwxr-xr-x. 1 root root 9656 Jan 14 2014 keytool
-rwxr-xr-x. 1 root root 9856 Jan 14 2014 orbd
-rwxr-xr-x. 1 root root 9688 Jan 14 2014 pack200
-rwxr-xr-x. 1 root root 10984 Jan 14 2014 policytool
-rwxr-xr-x. 1 root root 9648 Jan 14 2014 rmid
-rwxr-xr-x. 1 root root 9656 Jan 14 2014 rmiregistry
-rwxr-xr-x. 1 root root 9688 Jan 14 2014 servertool
-rwxr-xr-x. 1 root root 9896 Jan 14 2014 tnameserv
-rwxr-xr-x. 1 root root 92264 Jan 14 2014 unpack200
..even though there are 200 files. How can I find and run jconsole?
jconsole is part of the Java SDK, it appears you only have the JRE installed.
You can run jconsole directly from your terminal by running the command jconsole.
reena#IM-1500:~$ jconsole
It will launch java monitoring console dialog.
From https://serverfault.com/questions/179908/fedora-jconsole-location:
Try running: yum provides */jconsole
that will tell you what package you need as well as where it's located in the package.
Once you set the path of JDK in Linux then this command execute easily might be you had not included the JAVA_HOME with PATH variable.
plz follow this discussion
If you have Java JDK installed in your Linux machine, usually jconsole is located at /usr/bin/ as a symbolic link.
Example from my Linux VM running Centos6
$ which jconsole
/usr/bin/jconsole
$ ls -l /usr/bin/jconsole
lrwxrwxrwx. 1 root root 26 Sep 4 10:05 /usr/bin/jconsole -> /etc/alternatives/jconsole
$ ls -l /etc/alternatives/jconsole
lrwxrwxrwx. 1 root root 51 Sep 4 10:05 /etc/alternatives/jconsole -> /usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin/jconsole
But you mentioned you got the a command not found error when you typed jconsole at the prompt. Can you find if jconsole is available in one of the jdk's bin directory?
$ ls -l /usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin | grep jconsole
If yes, then add this in your PATH environment variable like so
$ export PATH=$PATH:/usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin
or put this in your ~/.bashrc if you are using Bash.
If jconsole is not there, then maybe you need to try another jdk which you have installed or re-install the jdk.
Please install JDK Development Package to get Jconsole

Play! not shutting down H2 correctly

I'm using Play to write a webapp which is deployed in Tomcat. Because the app won't be processing very much data I'm using the default H2 database with Hibernate. When I want to deploy a new version of the app, I shut down tomcat, wipe the old webapp and WAR, add my new WAR, and start back up.
This worked until a few days ago, when I added the database component. Now, I am often unable to redeploy the app. When I delete the old directory, it is automatically regenerated with this structure:
$ ls -laR myapp/
myapp/:
total 24
drwxr-xr-x 3 root root 4096 Aug 24 17:20 .
drwxr-xr-x 13 root root 4096 Aug 24 17:20 ..
drwxr-xr-x 3 root root 4096 Aug 24 17:20 WEB-INF
myapp/WEB-INF:
total 24
drwxr-xr-x 3 root root 4096 Aug 24 17:20 .
drwxr-xr-x 3 root root 4096 Aug 24 17:20 ..
drwxr-xr-x 3 root root 4096 Aug 24 17:20 application
myapp/WEB-INF/application:
total 24
drwxr-xr-x 3 root root 4096 Aug 24 17:20 .
drwxr-xr-x 3 root root 4096 Aug 24 17:20 ..
drwxr-xr-x 3 root root 4096 Aug 24 17:20 db
myapp/WEB-INF/application/db:
total 24
drwxr-xr-x 3 root root 4096 Aug 24 17:20 .
drwxr-xr-x 3 root root 4096 Aug 24 17:20 ..
drwxr-xr-x 2 root root 4096 Aug 24 17:20 h2
myapp/WEB-INF/application/db/h2:
total 24
drwxr-xr-x 2 root root 4096 Aug 24 17:20 .
drwxr-xr-x 3 root root 4096 Aug 24 17:20 ..
-rw-r--r-- 1 root root 100 Aug 24 17:20 play.lock.db
The same happens when the WAR unzips.
I recently noticed a message whiz by in the catalina.out log complaining about my app not shutting down a process called something like "H2 File Lock Watchdog". Based on a brief search of the H2 docs, I think that process is what's interfering with my app.
EDIT
Here's the complaining line in the log file:
SEVERE: The web application [/myapp] appears to have started a thread named [H2 File Lock Watchdog /var/lib/apache-tomcat-6.0.32/webapps/myapp/WEB-INF/application/db/h2/play.lock.db] but has failed to stop it. This is very likely to create a memory leak.
So, how do I kill this process? I can't restart the machine because it's not mine, and I can't find the watchdog with top or ps. I'd prefer a way for Play to shut it down automagically, but I'm not above building it into my deployment script.
Thanks a million if you've read this far!
I shut down tomcat
Are you sure you have shut down tomcat completely? Because the H2 database is sill running. If you shut down the tomcat process, the database is also stopped (because H2 is running within the tomcat process). Except if you run the database in a different process.
Or did you just shut down the web application within tomcat? If that is the case, then at least one database connection was not closed, so that the database keeps running (and creates this .lock.db file).
Now, I don't know the play framework, and can't say how to ensure all database connections are closed.
One way to force the database to close is to run the SQL statement SHUTDOWN.
I can't find the watchdog with top or ps
top and ps only display processes. The H2 watchdog is a thread within a java process. To see the thread, use:
jps -l (to get the list of Java processes)
jstack -l <pid> (to get a full thread dump)

Categories