Menu

#308 Ubuntu environment variable not exposed to service context

v3.5.36
open
nobody
None
5
2018-10-18
2018-10-17
No

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.

Related

Bugs: #308

Discussion

  • Maxime Andrighetto

    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

     
  • Carsten Hilber

    Carsten Hilber - 2018-10-18

    Hi Maxime,

    Thanks for your quick response. Our wrapper.conf file:
    I already configured the dump.

    # Java Application
    wrapper.java.command=java
    
    # Java Main class.
    wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
    
    # Java Classpath (include wrapper.jar)
    wrapper.java.classpath.1=../lib/wrapper.jar
    wrapper.java.classpath.2=../lib/bamboo-agent-bootstrap.jar
    
    # Java Library Path (location of Wrapper.DLL or libwrapper.so)
    wrapper.java.library.path.1=../lib
    
    # The Bamboo Agent home configuration file
    wrapper.java.additional.1=-Dbamboo.home=/opt/bambooagent/bamboo-agent-home
    wrapper.java.additional.2=-Dbamboo.agent.ignoreServerCertName=false
    #set.ATLAS_HOME=/usr/share/atlassian-plugin-sdk-6.3.7
    #wrapper.java.additional.3=-Dlog4j.configuration=
    #wrapper.java.additional.3=-agentlib:yjpagent
    
    # Application parameters.  Add parameters as needed starting from 1
    wrapper.app.parameter.1=com.atlassian.bamboo.agent.bootstrap.AgentBootstrap
    wrapper.app.parameter.2=https://bamboo.agile-it-management.de:443//agentServer/
    wrapper.app.parameter.3=
    
    # Disable shutdown hook so that
    wrapper.disable_shutdown_hook=TRUE
    
    
    # Initial Java Heap Size (in MB)
    wrapper.java.initmemory=256
    
    # Maximum Java Heap Size (in MB)
    wrapper.java.maxmemory=512
    
    
    #********************************************************************
    # Wrapper Logging Properties
    #********************************************************************
    wrapper.working.dir=.
    
    wrapper.console.format=LPTM
    wrapper.console.loglevel=INFO
    wrapper.console.flush=true
    wrapper.logfile=../atlassian-bamboo-agent.log
    wrapper.logfile.format=LPTM
    wrapper.logfile.loglevel=INFO
    wrapper.logfile.maxsize=10m
    wrapper.logfile.maxfiles=10
    wrapper.syslog.loglevel=INFO
    
    # How long should the wrapper wait before it considers an invocation successful?  3 seconds should be long
    # enough for any configuration errors to have been determined.
    wrapper.successful_invocation_time=3
    
    #********************************************************************
    # Wrapper Windows Properties
    #********************************************************************
    # Title to use when running as a console
    wrapper.console.title=Bamboo Remote Agent
    
    # Name of the service
    wrapper.ntservice.name=bamboo-remote-agent
    
    # Display name of the service
    wrapper.ntservice.displayname=Bamboo Remote Agent
    
    # Description of the service
    wrapper.ntservice.description=A remote agent for building Bamboo build plans.
    
    # Mode in which the service is installed.  AUTO_START or DEMAND_START
    wrapper.ntservice.starttype=AUTO_START
    
    # Allow the service to interact with the desktop.
    wrapper.ntservice.interactive=false
    
    wrapper.java.additional.3=-DDISABLE_AGENT_AUTO_CAPABILITY_DETECTION=false
    

    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

     
  • Carsten Hilber

    Carsten Hilber - 2018-10-18

    I forgot to. mention that the service ist started als a sysctl service,
    the servicefile looks like this:

    [Unit]
    Description=Atlassian Bamboo remote agent
    After=syslog.target network.target
    
    [Service]
    Type=forking
    User=bambooagent
    Group=bambooagent
    ExecStart=/opt/bambooagent/bamboo-agent-home/bin/bamboo-agent.sh start
    ExecStop=/opt/bambooagent/bamboo-agent-home/bin/bamboo-agent.sh stop
    
    [Install]
    WantedBy=multi-user.target
    

    and is started with a command like

    systemctl start bambooagent.service

     
    • Maxime Andrighetto

      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:

      I forgot to. mention that the service ist started als a sysctl service,
      the servicefile looks like this:

      [Unit]Description=Atlassian Bamboo remote agentAfter=syslog.target network.target
      [Service]Type=forkingUser=bambooagentGroup=bambooagentExecStart=/opt/bambooagent/bamboo-agent-home/bin/bamboo-agent.sh startExecStop=/opt/bambooagent/bamboo-agent-home/bin/bamboo-agent.sh stop
      [Install]WantedBy=multi-user.target

      and is started with a command like

      systemctl start bambooagent.service

      Status: open
      Group: v3.5.36
      Created: Wed Oct 17, 2018 01:17 PM UTC by Carsten Hilber
      Last Updated: Thu Oct 18, 2018 12:22 PM UTC
      Owner: nobody

      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.


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/wrapper/bugs/308/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #308


Log in to post a comment.

MongoDB Logo MongoDB