[arch-dev-public] JAVA_HOME in systemd
Hi all, I should have posted this a long time ago as suggested by Andy. Basically I would like some advice from the systemd gurus on how to provide a common place to set JAVA_HOME in systemd service files. As you know all Java apps need JAVA_HOME to be set. But as systemd service files do not inherit the shell's environment, all Java service files will need to declare a "Environment=JAVA_HOME=/lib/jvm/java-7-openjdk". Needless to say that this is hardcoding the path and if one wants to change it for another JVM, he/she will have to fix all service files. Hence I was thinking about a common EnvironmentFile to hold this value once and for all. I know these EnvironmentFile _should_ be avoided but I think we are in a case where it could be tolerated. All Java service file could then just refer to it throught "EnvironmentFile=/the/path/to/this/file". Also it could be parsed by /etc/profile.d/jre.sh to set the shell's environment. So is there a simpler to do that in systemd? Or does this sound ok to you? Also if it sounds OK, is there a standard place to put systemd environment files like such? Thanks -- Guillaume
Am 06.02.2013 11:50, schrieb Guillaume ALAUX:
Hence I was thinking about a common EnvironmentFile to hold this value once and for all. I know these EnvironmentFile _should_ be avoided but I think we are in a case where it could be tolerated. All Java service file could then just refer to it throught "EnvironmentFile=/the/path/to/this/file".
This seems like the only way. Such a file would however make all java runtimes conflict, unless you find a very clever way around it.
[2013-02-06 11:59:22 +0100] Thomas Bächler:
Am 06.02.2013 11:50, schrieb Guillaume ALAUX:
Hence I was thinking about a common EnvironmentFile to hold this value once and for all. I know these EnvironmentFile _should_ be avoided but I think we are in a case where it could be tolerated. All Java service file could then just refer to it throught "EnvironmentFile=/the/path/to/this/file".
This seems like the only way. Such a file would however make all java runtimes conflict, unless you find a very clever way around it.
You can always have each Java runtime provide a different file, and include all of them in each Java service file using EnvironmentFile=-/path/to/java/runtime/number/one EnvironmentFile=-/path/to/java/runtime/number/two etc. -- Gaetan
On Wed, Feb 6, 2013 at 1:58 PM, Gaetan Bisson <bisson@archlinux.org> wrote:
You can always have each Java runtime provide a different file, and include all of them in each Java service file using
EnvironmentFile=-/path/to/java/runtime/number/one EnvironmentFile=-/path/to/java/runtime/number/two
etc.
You can also pass a wildcard expression, avoiding hardcoding several files, maybe like this: EnvironmentFile=-/etc/java-runtime.d/* EnvironmentFile=-/etc/java-runtime Needs testing, but could allow the user to set a default runtime via symlink. Alternatively, just EnvironmentFile=/etc/java-runtime and create this symlink at post_install of every java-runtime, if it doesn't exist already. To be tidy, post_remove then deletes the file if java-runtime.d doesn't exist anymore.
participants (4)
-
Gaetan Bisson
-
Guillaume ALAUX
-
Jan Steffens
-
Thomas Bächler