9

Theres a similar question to this, but cant manage it to work: I want to simply set an env variable, then use it:

execute "start zookeeper" do
    cwd "/opt/zookeeper-3.4.5/bin"
    command "./zkServer.sh start"
    environment "JVMFLAGS" => "-Xmx#{heap_jvm} -Xms#{heap_jvm}"
    user "root"
    action :run
end

I've also tried using bash to "export JVMFLAGS='-blabla'" but still it runs the sh with none set to the variable. Is there some issue preventing my sh script from checking the variable? I could use the sh like a template and replace the ocurrence of JVMFLAGS... But i want to check if theres a better solution..

Alexandre Abreu
  • 1,382
  • 1
  • 13
  • 28

1 Answers1

8

Have you tried setting environment variable through Ruby just before the execute block? Chef actually recommends using ENV (See the note on that page).

ENV['JVMFLAGS'] = "-Xmx#{heap_jvm} -Xms#{heap_jvm}"

Another possibility is to add JVMFLAGS to the command itself.

execute "start zookeeper" do
  [...]
  command "JVMFLAGS=-Xmx#{heap_jvm} -Xms#{heap_jvm} ./zkServer.sh start"
  [...]
end
Draco Ater
  • 20,820
  • 8
  • 62
  • 86
  • 1
    I tried `ENV[...]`, however after running `vagrant provision`, running `export MY_ENV_VAR` shows no variable set. – Kevin Meredith Mar 24 '14 at 17:09
  • And it shouldn't be. The env variables are set only for the current process and its children. – Draco Ater Mar 24 '14 at 19:41
  • 1
    I was looking how to set a **system** env var - http://stackoverflow.com/questions/6284517/how-can-you-use-a-chef-recipe-to-set-an-environment-variable/14917841#comment34443452_14917841. I had been looking for a different answer. – Kevin Meredith Mar 24 '14 at 19:43