We set up a java application to use a system variable $HOME to be used by the java code.
Unfortunatly the variable is not transported to the context unless I specify it in the wrapper.conf.
We don't want to edit the wrapper.conf every time the system variable is chaged. On windows this is the expected behavior, that's why I expect this to happen on linux as well.
Thank you for your post.
I am not quite sure to understand the issue. Is it correct that, on Linux, when you set the $HOME in your session (before launching the Wrapper), the variable is not accessible from your Java code? Normally, the environment variables existing before the Wrapper is launched should be accessible to the Wrapper and its child processes, so to your Java Applicaiton. Could you please specify how you set the variable and detail the step to reproduce the issue?
In your configuration file, please set wrapper.environment.dump.loglevel=INFO (or wrapper.environment.dump=TRUE, if you use a version older than 3.5.36). This will list all the environment variables visible to the Wrapper. Does the $HOME variable shows in the list? Can you please post the line for this variable?
Best Regards,
Maxime
Hi Maxime,
Thanks for your quick response. Our wrapper.conf file:
I already configured the dump.
here's the dump from the log:
INFO | wrapper | 2018/10/18 12:16:29 | Environment variables (Source | Name=Value) BEGIN:
INFO | wrapper | 2018/10/18 12:16:29 | P---- | HOME=/opt/bambooagent
INFO | wrapper | 2018/10/18 12:16:29 | P---- | JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
INFO | wrapper | 2018/10/18 12:16:29 | P---- | LANG=en_US.UTF-8
INFO | wrapper | 2018/10/18 12:16:29 | P---- | LOGNAME=bambooagent
INFO | wrapper | 2018/10/18 12:16:29 | P---- | OLDPWD=/
INFO | wrapper | 2018/10/18 12:16:29 | P---- | PATH=/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin
INFO | wrapper | 2018/10/18 12:16:29 | P---- | PWD=/opt/bambooagent/bamboo-agent-home/bin
INFO | wrapper | 2018/10/18 12:16:29 | P---- | SHELL=
INFO | wrapper | 2018/10/18 12:16:29 | P---- | USER=bambooagent
INFO | wrapper | 2018/10/18 12:16:29 | ---W- | WRAPPER_ARCH=x86
INFO | wrapper | 2018/10/18 12:16:29 | ---W- | WRAPPER_BIN_DIR=/opt/bambooagent/bamboo-agent-home/bin
INFO | wrapper | 2018/10/18 12:16:29 | ---W- | WRAPPER_BITS=64
INFO | wrapper | 2018/10/18 12:16:29 | ---W- | WRAPPER_CONF_DIR=/opt/bambooagent/bamboo-agent-home/conf
INFO | wrapper | 2018/10/18 12:16:29 | ---W- | WRAPPER_EDITION=Community
INFO | wrapper | 2018/10/18 12:16:29 | ---W- | WRAPPER_FILE_SEPARATOR=/
INFO | wrapper | 2018/10/18 12:16:29 | ---W- | WRAPPER_HOST_NAME=bamboo-agent-prod01
INFO | wrapper | 2018/10/18 12:16:29 | ---W- | WRAPPER_HOSTNAME=bamboo-agent-prod01
INFO | wrapper | 2018/10/18 12:16:29 | P--W- | WRAPPER_INIT_DIR=/opt/bambooagent/bamboo-agent-home/bin
INFO | wrapper | 2018/10/18 12:16:29 | ---W- | WRAPPER_LANG=en
INFO | wrapper | 2018/10/18 12:16:29 | ---W- | WRAPPER_OS=linux
INFO | wrapper | 2018/10/18 12:16:29 | ---W- | WRAPPER_PATH_SEPARATOR=:
INFO | wrapper | 2018/10/18 12:16:29 | ---W- | WRAPPER_PID=8387
INFO | wrapper | 2018/10/18 12:16:29 | ---W- | WRAPPER_VERSION=3.5.36
INFO | wrapper | 2018/10/18 12:16:29 | ---W- | WRAPPER_WORKING_DIR=/opt/bambooagent/bamboo-agent-home/bin
INFO | wrapper | 2018/10/18 12:16:29 | Environment variables END:
In the question I mistakenly used $HOME, but it is actually $ATLAS_HOME that is missing.
Here's the context when asking bash:
declare -x ATLAS_HOME="/usr/share/atlassian-plugin-sdk-6.3.7"
declare -x DERBY_HOME="/usr/lib/jvm/java-8-oracle/db"
declare -x HOME="/root"
declare -x J2REDIR="/usr/lib/jvm/java-8-oracle/jre"
declare -x J2SDKDIR="/usr/lib/jvm/java-8-oracle"
declare -x JAVA_HOME="/usr/lib/jvm/java-8-oracle"
declare -x LANG="en_US.UTF-8"
declare -x LESSCLOSE="/usr/bin/lesspipe %s %s"
declare -x LESSOPEN="| /usr/bin/lesspipe %s"
declare -x LOGNAME="root"
The ATLAS_HOME is set in /etc/environment, so it is globally available.
Thanks
Carsten
I forgot to. mention that the service ist started als a sysctl service,
the servicefile looks like this:
and is started with a command like
systemctl start bambooagent.service
Carsten
Thank you for your reply.
Usually services don't read /etc/environment, so that's why your variable
is not visible to the Wrapper when it is running as a daemon. If you run
the Wrapper as a console application, you should see it though.
I would suggest two solutions:
Solution 1) You can edit the script file to specify that /etc/environment
should be read when systemd starts.
In the systemdInstall() function, after:
echo "[Service]" >> "${SYSTEMD_SERVICE_FILE}"
Please add the following line:
echo "EnvironmentFile=/etc/environment" >> "${SYSTEMD_SERVICE_FILE}"
Then reinstall and restart your service for the change to take effect. Your
variable should now be visible.
In a future version of the Wrapper we may add a variable on the top of the
script to control whether to use EnvironmentFile or not. It should probably
be FALSE by default to ensure backward compatibility and compatibility with
other service management tools.
Solution 2) On the top of the script file, you can specify a script file
to source by setting the FILES_TO_SOURCE variable. Note that
/etc/environment is not a script file, so you should create a separate
script that your service would use.
Example: FILES_TO_SOURCE=/etc/default/servicename
Please let me know if this works for you.
Best Regards,
Maxime
On Thu, Oct 18, 2018 at 9:37 PM, Carsten Hilber chilber@users.sourceforge.net wrote:
Related
Bugs: #308