I have a script in /etc/init.d/ called foo.sh that runs six (JAVA) Spring Boot jars. All of the jars require environmental variables to run. This script was added to rc.d via update-rc.d foo.sh defaults. Environmental variables needed were added to /etc/environment/.

Whenever I reboot the server, the script runs but one of the java modules cannot find env variables, the other 5 run correctly. If I try to run the script manually, it has no issues at all. I have ran this a million ways in order to determine if the problem is in the java code, but it is not.

What exactly is happening here and how could I solve it so that on a reboot all jars can access global environmental variables?

1 Answer 1


I cannot tell you exactly why that's happening but I can suggest a couple things.

You can always create a simple test script in that directory and invoke it the same way as the other jars, that simply displays the environment:

echo "$(env)" >/tmp/env-test

Secondly, you can always prepend any environment variables that you want available to a command, like:

FOO=bar mycommand

This is often useful for temporarily running a command using a variable without having to set it.

  • I suppose we could write env vars on the script to see if the vars are defined when the jars are being run? Is that what you mean?
    – Nimchip
    Feb 5, 2020 at 22:06
  • So env variables are not being set up at all while the init.d script runs on boot. I used printenv >/opt/fooapp/env-test
    – Nimchip
    Feb 6, 2020 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.