Run as root or as vagrant user


#1

I am creating a recipe to build JBoss AS 7.1.3 from source. The recipe works until the Maven build runs out of Java heap space. On the virtual machine I’ve set MAVEN_OPTS and JAVA_OPTS via a .bashrc file:

MAVEN_OPTS=’-Xms1024m -Xmx2048m -XX:MaxPermSize=500m’
JAVA_OPTS=’-Xms1024m -Xmx2048m -XX:MaxPermSize=512m -noverify’

export MAVEN_OPTS JAVA_OPTS …

However these environment settings are for the ‘vagrant’ user on the VM and I suspect that the chef solo provisioner runs things as ‘root’.

I tried adding an export of JAVA_OPTS and MAVEN_OPTS to the recipe to force the memory setting regardless of the active user:


bash “mvn install -DskipTests” do
code <<-EOH
cd /home/vagrant/src/jbossas
export MAVEN_OPTS=’-Xms1024m -Xmx2048m -XX:MaxPermSize=500m’
export JAVA_OPTS=’-Xms1024m -Xmx2048m -XX:MaxPermSize=512m -noverify’
/usr/local/maven3/bin/mvn install -DskipTests -Dcheckstyle.skip=true
EOH
end

But that too resulted in an “out of Java heap space” error.

Obviously I am missing something. How do I ensure that my recipe has the heap space it requires?

Thanks,
Mark Nichols


#2

Try the ‘environment’ parameter to the bash script resource (it’s
actually from the Execute resource, but this inherits that)

bash ‘foo’ do
environment ‘MAVEN_OPTS’ => '-Xms1024m -Xmx2048m -XX:MaxPermSize=500m’
end

etc.

Maybe consider structuring it a little different as well? Write a
shell script or similar, included in your code-base which wraps your
’mvn install’, then just run that from Chef. That way you can re-run
or developers could run it if you’re hooning around by hand anyway.
Just a thought :slight_smile:

–AJ

On 11 May 2013 10:38, Mark H. Nichols chef@zanshin.net wrote:

I am creating a recipe to build JBoss AS 7.1.3 from source. The recipe works
until the Maven build runs out of Java heap space. On the virtual machine
I’ve set MAVEN_OPTS and JAVA_OPTS via a .bashrc file:

MAVEN_OPTS=’-Xms1024m -Xmx2048m -XX:MaxPermSize=500m’

JAVA_OPTS=’-Xms1024m -Xmx2048m -XX:MaxPermSize=512m -noverify’

export MAVEN_OPTS JAVA_OPTS …

However these environment settings are for the ‘vagrant’ user on the VM and
I suspect that the chef solo provisioner runs things as ‘root’.

I tried adding an export of JAVA_OPTS and MAVEN_OPTS to the recipe to force
the memory setting regardless of the active user:

bash “mvn install -DskipTests” do

code <<-EOH

cd /home/vagrant/src/jbossas

export MAVEN_OPTS=’-Xms1024m -Xmx2048m -XX:MaxPermSize=500m’

export JAVA_OPTS=’-Xms1024m -Xmx2048m -XX:MaxPermSize=512m -noverify’

/usr/local/maven3/bin/mvn install -DskipTests -Dcheckstyle.skip=true

EOH

end

But that too resulted in an “out of Java heap space” error.

Obviously I am missing something. How do I ensure that my recipe has the
heap space it requires?

Thanks,
Mark Nichols


#3

I am also having a similar kind of problem, I have my cookbook: where in my
recipe, I am downloading tomcat.tar (this I have placed somewhere in my
other machine). After downloading I extract the same tomcat.tar (suppose in
location /home/ubuntu/tomcat). Now I am simply trying to start tomcat. I
tried the below mentioned ways, but is not able to start/stop.

  1. Modified the ~/.bashrc file from my recipe to export JAVA_HOME,
    CATALINA_HOME,
    What I did is:

ran a bash script inside recipe to simply add the environment variables at
the end of ~/.bashrc and then ran source ~/.bashrc

Now using “execute” resource, ran “/home/ubuntu/tomcat/bin/startup.sh” BUT
IT DO NOT START.

  1. Modified the ~/.bashrc file from my recipe to export JAVA_HOME,
    CATALINA_HOME,
    What I did is:

ran a bash script inside recipe to simply add the environment variables at
the end of ~/.bashrc and then ran source ~/.bashrc

Inside bash script resource, ran “/home/ubuntu/tomcat/bin/startup.sh” BUT
IT DO NOT START.

  1. Wrote a shell script and kept at the same location from where I am
    downloading tomcat.tar, downloaded the run_tomcat.sh on to the chef-client
    (using resource remote_file) and then using the “execute” resource running
    the run_tomcat.sh.
    Inside this run_tomcat.sh, I am exporting the environment variables and
    then running the "/home/ubuntu/tomcat/bin/startup.sh"
    BUT IT DO NOT START.

  2. Wrote a shell script and kept at the same location from where I am
    downloading tomcat.tar, downloaded the run_tomcat.sh on to the chef-client
    (using resource remote_file). Set environment variables using “environment
    resource” and run script using “execute” resource.
    Inside this run_tomcat.sh, running the “/home/ubuntu/tomcat/bin/startup.sh”
    *BUT IT DO NOT START.

For point 3 and 4 above the strange thing is that other commands inside
run_tomcat.sh, like extracting war, deleting some directory from the
extracted war executes. BUT TOMCAT DOESN’T START UP.

**

On Sat, May 11, 2013 at 4:16 AM, AJ Christensen aj@junglist.gen.nz wrote:

Try the ‘environment’ parameter to the bash script resource (it’s
actually from the Execute resource, but this inherits that)

bash ‘foo’ do
environment ‘MAVEN_OPTS’ => '-Xms1024m -Xmx2048m -XX:MaxPermSize=500m’
end

etc.

Maybe consider structuring it a little different as well? Write a
shell script or similar, included in your code-base which wraps your
’mvn install’, then just run that from Chef. That way you can re-run
or developers could run it if you’re hooning around by hand anyway.
Just a thought :slight_smile:

–AJ

On 11 May 2013 10:38, Mark H. Nichols chef@zanshin.net wrote:

I am creating a recipe to build JBoss AS 7.1.3 from source. The recipe
works
until the Maven build runs out of Java heap space. On the virtual machine
I’ve set MAVEN_OPTS and JAVA_OPTS via a .bashrc file:

MAVEN_OPTS=’-Xms1024m -Xmx2048m -XX:MaxPermSize=500m’

JAVA_OPTS=’-Xms1024m -Xmx2048m -XX:MaxPermSize=512m -noverify’

export MAVEN_OPTS JAVA_OPTS …

However these environment settings are for the ‘vagrant’ user on the VM
and
I suspect that the chef solo provisioner runs things as ‘root’.

I tried adding an export of JAVA_OPTS and MAVEN_OPTS to the recipe to
force
the memory setting regardless of the active user:

bash “mvn install -DskipTests” do

code <<-EOH

cd /home/vagrant/src/jbossas

export MAVEN_OPTS=’-Xms1024m -Xmx2048m -XX:MaxPermSize=500m’

export JAVA_OPTS=’-Xms1024m -Xmx2048m -XX:MaxPermSize=512m -noverify’

/usr/local/maven3/bin/mvn install -DskipTests -Dcheckstyle.skip=true

EOH

end

But that too resulted in an “out of Java heap space” error.

Obviously I am missing something. How do I ensure that my recipe has the
heap space it requires?

Thanks,
Mark Nichols


Regards,
Chandan


#4

On May 10, 2013, at 5:46 PM, AJ Christensen aj@junglist.gen.nz wrote:

Try the ‘environment’ parameter to the bash script resource (it’s
actually from the Execute resource, but this inherits that)

bash ‘foo’ do
environment ‘MAVEN_OPTS’ => '-Xms1024m -Xmx2048m -XX:MaxPermSize=500m’
end

I added the “environment” setting to my recipe, resulting in this code:

bash “mvn install -DskipTests” do
code <<-EOH
environment ‘MAVEN_OPTS’ => '-Xms1024m -Xmx2048m -XX:MaxPermSize=500m’
environment ‘JAVA_OPTS’ => '-Xms1024m -Xmx2048m -XX:MaxPermSize=512m -noverify’
cd /home/vagrant/src/jbossas
/usr/local/maven3/bin/mvn install -DskipTests -Dcheckstyle.skip=true
EOH
end

However, I’m still getting a Java Heap space error.

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2:01.567s
[INFO] Finished at: Tue May 14 20:13:36 UTC 2013
[INFO] Final Memory: 105M/121M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project jboss-as-clustering-infinispan: Fatal error compiling: Error while executing the compiler. InvocationTargetException: Java heap space -> [Help 1]

From the output it appears that the “environment” setting is not working, as the memory is shown as 121M and not the 1024M minimum asked for.

Is it not possible to use Maven to build something during a Chef run?

etc.

Maybe consider structuring it a little different as well? Write a
shell script or similar, included in your code-base which wraps your
’mvn install’, then just run that from Chef. That way you can re-run
or developers could run it if you’re hooning around by hand anyway.
Just a thought :slight_smile:

Ultimately I’d like to have two recipes in the cookbook. One to install a pre-built JBoss AS 7.1.3 binary, and a second one to build it on the fly. The second one would all developers to tweak the build to add or remove debugging options as needed. I am using :shell provisioning elsewhere in my setup. I’m not convinced that using that method would get around this problem however.

– Mark


#5

You’ve got the environment parameters in the bash script itself.

The environment parameter is a parameter to the EXECUTE and SCRIPT
resources e.g.

bash “script with env vars” do
environment( “SOME_KEY” => “SOME_VALUE”, “ANOTHER_KEY” => “ANOTHER_VALUE” )
code <<-EOH
echo 'Env dump’
env
echo 'Env dumped’
env SOME_KEY
env ANOTHER_KEY
echo 'specific keys dumped’
EOH
end

As for whether Maven will honor this, I don’t know, but it’s trivial
to test that Chef can pass environment variables into a new process –
and this definitely does work.

Cheers,

AJ

On 15 May 2013 08:18, Mark H. Nichols chef@zanshin.net wrote:

On May 10, 2013, at 5:46 PM, AJ Christensen aj@junglist.gen.nz wrote:

Try the ‘environment’ parameter to the bash script resource (it’s
actually from the Execute resource, but this inherits that)

bash ‘foo’ do
environment ‘MAVEN_OPTS’ => '-Xms1024m -Xmx2048m -XX:MaxPermSize=500m’
end

I added the “environment” setting to my recipe, resulting in this code:

bash “mvn install -DskipTests” do
code <<-EOH
environment ‘MAVEN_OPTS’ => '-Xms1024m -Xmx2048m -XX:MaxPermSize=500m’
environment ‘JAVA_OPTS’ => '-Xms1024m -Xmx2048m -XX:MaxPermSize=512m
-noverify’
cd /home/vagrant/src/jbossas
/usr/local/maven3/bin/mvn install -DskipTests -Dcheckstyle.skip=true
EOH
end

However, I’m still getting a Java Heap space error.

[INFO] BUILD FAILURE
[INFO]

[INFO] Total time: 2:01.567s
[INFO] Finished at: Tue May 14 20:13:36 UTC 2013
[INFO] Final Memory: 105M/121M
[INFO]

[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile
(default-compile) on project jboss-as-clustering-infinispan: Fatal error
compiling: Error while executing the compiler. InvocationTargetException:
Java heap space -> [Help 1]

From the output it appears that the “environment” setting is not working, as
the memory is shown as 121M and not the 1024M minimum asked for.

Is it not possible to use Maven to build something during a Chef run?

etc.

Maybe consider structuring it a little different as well? Write a
shell script or similar, included in your code-base which wraps your
’mvn install’, then just run that from Chef. That way you can re-run
or developers could run it if you’re hooning around by hand anyway.
Just a thought :slight_smile:

Ultimately I’d like to have two recipes in the cookbook. One to install a
pre-built JBoss AS 7.1.3 binary, and a second one to build it on the fly.
The second one would all developers to tweak the build to add or remove
debugging options as needed. I am using :shell provisioning elsewhere in my
setup. I’m not convinced that using that method would get around this
problem however.

– Mark


#6

On May 14, 2013, at 3:26 PM, AJ Christensen aj@junglist.gen.nz wrote:

You’ve got the environment parameters in the bash script itself.

The environment parameter is a parameter to the EXECUTE and SCRIPT
resources e.g.

bash “script with env vars” do
environment( “SOME_KEY” => “SOME_VALUE”, “ANOTHER_KEY” => “ANOTHER_VALUE” )
code <<-EOH
echo 'Env dump’
env
echo 'Env dumped’
env SOME_KEY
env ANOTHER_KEY
echo 'specific keys dumped’
EOH
end

That did the trick. Thank you.

As for whether Maven will honor this, I don’t know, but it’s trivial
to test that Chef can pass environment variables into a new process –
and this definitely does work.

It appears Maven did honor the environment settings.

Thanks again,
Mark