0

I have a glassfish application server that is running under the glassfish user on CentOS 7.2. I have an application that has a deployed application that is needing a custom environment variable (e.g. export App_Home=/opt/App).

The application is reading the environment variables in Java with within glassfish with System.getenv("App_Home").

I was able to get this to work by editing the service.

vi /etc/systemd/system/glassfish.service

Adding EnvironmentFile=/opt/MyApp/MyEnvironmentFile and then in /opt/MyApp/MyEnvironmentFile added App_Home=/opt/MyApp

  1. Is there a way of setting this environment variable with glassfish itself?

  2. Or is there a better way of setting the system property variables instead of editing service files?

I also tried adding exports into the glassfish .bashrc (which is what shell the service seems to be running under) but that didn't seem to get passed down to the application.

chicks
  • 3,639
  • 10
  • 26
  • 36
Kevin Vasko
  • 185
  • 5

1 Answers1

2

apparently there is an asenv.conf file in the glassfish directory. You could edit that (environment file).

bashrc files are used for login shells and as you have already seen for yourself, not useful for services.

natxo asenjo
  • 5,641
  • 2
  • 25
  • 27
  • I thought that was a solution as well too but that doesn't work either. I tried to add my `App_Home...` but when I printed out the System.getenv() from within the application it wasn't listed. – Kevin Vasko Sep 01 '17 at 18:34
  • then you could modify the startserv script and add your variable there (it's a shell script, so something like export MY_AWESOME_VAR="my_awesome_value" should be enought (I just tested it and i can see the variable in /prod/pid#/environ , so I know it works) – natxo asenjo Sep 01 '17 at 20:27
  • In my glassfish.service file the ExecStart= is pointing to a jar file and start-domain which starts the glassfish service. I take it yours is pointing to just a script and not a jar file? – Kevin Vasko Sep 01 '17 at 23:25
  • no, startserv is in the glassfish5/glassfish/bin/ directory of the unpacked latest-web.zip I downloaded from https://javaee.github.io/glassfish/download – natxo asenjo Sep 02 '17 at 06:31
  • My glassfish.service file has the following line and is what starts the service. `ExecStart = /usr/bin/java -jar /home/glassfish/glassfish4/glassfish/lib/client/appserver-cli.jar start-domain` I don't think the file in the startserv script is ever called which results in it never having that export ran. – Kevin Vasko Sep 05 '17 at 16:02
  • you could modify your systemd file, I guess. Then it would just point to the startserv script. But do what suits you, I have already given you an alternative way of passing a variable which was what you were asking for. – natxo asenjo Sep 05 '17 at 17:25
  • I appreciate it. It does give me another option and that is what I ended up doing to try and keep the service clean. I honestly think the more interesting thing you showed was the `/proc/pid#/environ` information. Wasn't aware of that and can see that coming in handy in the future. Appreciate it. I accepted your answer. – Kevin Vasko Sep 05 '17 at 18:05
  • great to know it was helpful. – natxo asenjo Sep 05 '17 at 19:11