Java JPS cannot see running java processes

This one took a lot of digging.

JPS is the java version of linux ps command.  It looks for running java processes.

We installed zookeeper and created a user for the process to run under.  Exhibitor (created and open-sourced by netflix) uses jps to find the zookeeper process.  We ran exhibitor under the same user credentials as zookeeper.

Looking in the exhibitor logs, I could see errors like “jps unable to find zookeeper instance.”  To try to research the issue I tried to run the jps command from the command line.  Using the normal ps command I could see the process but jps could not.  I would su as the new user and run jps.  I couldn’t see the zookeeper process with that user even though I could see with ps.

It turns out that java uses a temporary directory on linux in /tmp/hsperfdata_{username} and jps uses this temporary directory to find java processes.

For whatever reason, the directory had not been created so jps could not find the temporary files.  I’ve seen this has happened to other users, too.

There are two options.

Because exhibitor was running jps internally and I couldn’t change the call, I had to use the first option.  Assume I have created a user called “myAppUser.”  We also created a group like “MyAppGroup” and myAppUser is a member of “MyAppGroup.”

mkdir /tmp/hsperfdata_myAppUser
chown myAppUser.MyAppGroup /tmp/hsperfdata_myAppUser

Option 2

Start java with the following option: -Djava.io.tmpdir=/someDir
Then start jps with -J-Djava.io.tmpdir=/someDir (check jps instructions to verify the syntax)
Make sure your user has rights to /someDir.

Advertisements