java system preferences under different users in l

2020-02-25 07:09发布

I'm trying to run multiple jvms (including tomcat) under different users on one linux box. I'm not seeing too many issues, but in catalina.out I keep seeing this:

May 30, 2014 1:16:16 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 7626 ms
May 30, 2014 1:16:37 PM java.util.prefs.FileSystemPreferences$2 run
WARNING: Could not create system preferences directory. System preferences are unusable.
May 30, 2014 1:16:55 PM java.util.prefs.FileSystemPreferences checkLockFile0ErrorCode
WARNING: Could not lock System prefs. Unix error code -158097957.
May 30, 2014 1:16:55 PM java.util.prefs.FileSystemPreferences syncWorld
WARNING: Couldn't flush system prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.

I did some digging/reading and deduced the following:

An administrator with root access must create the system preferences directory /etc/.java/.systemPrefs with drwxr-xr-x access.

Java's looking for /etc/.java/.systemPrefs/.system.lock and /etc/.java/.systemPrefs/.systemRootModFile

Manually creating the above files (use "touch" to create empty files) and their containing directories should fix. Rights to the files should be 544, rights to their directories should be 755, owner and group are root for all.

But

I am not root, getting someone to run root is expensive and I have multiple users running jvms, does that mean i have to create those files and set up permissions just so that all users have access with those privileges?

Has anyone ever run into this issue and if they have is there a simpler solution i am missing?

3条回答
做自己的国王
2楼-- · 2020-02-25 07:54

Set these settings per user:

mkdir -p ~/.java/.systemPrefs
mkdir ~/.java/.userPrefs
chmod -R 755 ~/.java
export JAVA_OPTS="-Djava.util.prefs.systemRoot=/home/user/.java -Djava.util.prefs.userRoot=/home/user/.java/.userPrefs"
  <run appl>

Without creating the directories, some Java virtual machines default to /etc/.

See also: Java - Setting Preferences backingstore directory

查看更多
别忘想泡老子
3楼-- · 2020-02-25 08:03

My thinking is that even though you have different users, the JVM still reads tomcat as one user since it's the same process. Perhaps what you need is a user management mechanism? Log in and log out

查看更多
▲ chillily
4楼-- · 2020-02-25 08:08

I fixed this by setting the permissions of my Bash program executing to 755

ls abc.sh
chmod 755 abc.sh
查看更多
登录 后发表回答