Deploying .war files?

Hi everyone,
I’m fairly new to Chef. I downloaded and deployed the tomcat cookbook to a
node, and now I’m trying to add a recipe? or another cookbook, I’m not sure
really…to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the webapps
directory, and scp a file to the right spot…then start tomcat.

I looked briefly at the deploy resource, but that’s from a version control
system…we don’t keep builds in version control, only the source…the binary
builds are on a server, so I don’t think that’s what I want.

If anyone can point me in the right direction to get this going, that would be
greatly appreciated.

Thanks.

-Matt

I need to do the same thing but haven't written it yet. Here's my plan

  • hopefully others can critique.

Firstly, you don't want to stop tomcat. Chef runs every 20 minutes or
so (or whenever you set it for) so it would stop your server every 20
minutes. Instead, you should work out if the file on your file server
has changed and then do the update. In my case, my build artifacts
have a build id. I plan to store the desired build id in a data bag *.
The deployed data bag goes into the node data. Then, on the chef run
it can compare and then run the update if required.

When you do the update you don't need to stop tomcat. Instead you
download the WAR to a temp directory then go to the webapps dir and
delete the directory for your webapp as well as the old WAR. Then you
copy the WAR in. (You can't download directly because then Tomcat
un-jars it before it's downloaded). Tomcat then un-jars it and starts
it up for you.

Cheers,
Edward

  • Amusingly, I forgot the name for data bag and my mind came up with
    drop bag. Once a trail runner, always a trail runner... :slight_smile:

On Mon, Jun 20, 2011 at 8:25 PM, mdrobnak@ringleaderdigital.com wrote:

Hi everyone,
I'm fairly new to Chef. I downloaded and deployed the tomcat cookbook to a
node, and now I'm trying to add a recipe? or another cookbook, I'm not sure
really...to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the webapps
directory, and scp a file to the right spot..then start tomcat.

I looked briefly at the deploy resource, but that's from a version control
system...we don't keep builds in version control, only the source..the binary
builds are on a server, so I don't think that's what I want.

If anyone can point me in the right direction to get this going, that would be
greatly appreciated.

Thanks.

-Matt

could you use something like capistrano for java?

On Mon, Jun 20, 2011 at 11:32 PM, Edward Sargisson esarge@pobox.com wrote:

I need to do the same thing but haven't written it yet. Here's my plan

  • hopefully others can critique.

Firstly, you don't want to stop tomcat. Chef runs every 20 minutes or
so (or whenever you set it for) so it would stop your server every 20
minutes. Instead, you should work out if the file on your file server
has changed and then do the update. In my case, my build artifacts
have a build id. I plan to store the desired build id in a data bag *.
The deployed data bag goes into the node data. Then, on the chef run
it can compare and then run the update if required.

When you do the update you don't need to stop tomcat. Instead you
download the WAR to a temp directory then go to the webapps dir and
delete the directory for your webapp as well as the old WAR. Then you
copy the WAR in. (You can't download directly because then Tomcat
un-jars it before it's downloaded). Tomcat then un-jars it and starts
it up for you.

Cheers,
Edward

  • Amusingly, I forgot the name for data bag and my mind came up with
    drop bag. Once a trail runner, always a trail runner... :slight_smile:

On Mon, Jun 20, 2011 at 8:25 PM, mdrobnak@ringleaderdigital.com wrote:

Hi everyone,
I'm fairly new to Chef. I downloaded and deployed the tomcat cookbook to
a
node, and now I'm trying to add a recipe? or another cookbook, I'm not
sure
really...to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the
webapps
directory, and scp a file to the right spot..then start tomcat.

I looked briefly at the deploy resource, but that's from a version
control
system...we don't keep builds in version control, only the source..the
binary
builds are on a server, so I don't think that's what I want.

If anyone can point me in the right direction to get this going, that
would be
greatly appreciated.

Thanks.

-Matt

Hi

On Tue, Jun 21, 2011 at 6:35 AM, Ken Mazaika kmazaika@gmail.com wrote:

could you use something like capistrano for java?

I actually used capistrano to deploy wars to tomcat. It only took a couple
of hours to create a custom capfile. I used the following procedure:

  • Used the tomcat api to uninstall the war (so it'll remove all the
    working temp files as well). something like:

def run_undeploy_command context
run "curl -s --user #{tomcat_user}:#{tomcat_password}
http://localhost:8080/manager/undeploy?path=/#{context}" do |c, s, d|
raise %{Cannot undeploy #{context} => "#{d}"} unless d.start_with? "OK"
end
end

  • Stopped tomcat
  • Copied the new war to the webapps directory
  • Started tomcat

This was a server where chef was not running as a service so I didn't have
to worry about chef starting tomcat in while I'm copying the war. You can
copy the war and then restart tomcat. Another option would be to use the api
to deploy the new war and then restart tomcat (the reason I'm always
restarting tomcat is to avoid PermGen memory errors).

HTH

On Mon, Jun 20, 2011 at 11:32 PM, Edward Sargisson esarge@pobox.comwrote:

I need to do the same thing but haven't written it yet. Here's my plan

  • hopefully others can critique.

Firstly, you don't want to stop tomcat. Chef runs every 20 minutes or
so (or whenever you set it for) so it would stop your server every 20
minutes. Instead, you should work out if the file on your file server
has changed and then do the update. In my case, my build artifacts
have a build id. I plan to store the desired build id in a data bag *.
The deployed data bag goes into the node data. Then, on the chef run
it can compare and then run the update if required.

When you do the update you don't need to stop tomcat. Instead you
download the WAR to a temp directory then go to the webapps dir and
delete the directory for your webapp as well as the old WAR. Then you
copy the WAR in. (You can't download directly because then Tomcat
un-jars it before it's downloaded). Tomcat then un-jars it and starts
it up for you.

Cheers,
Edward

  • Amusingly, I forgot the name for data bag and my mind came up with
    drop bag. Once a trail runner, always a trail runner... :slight_smile:

On Mon, Jun 20, 2011 at 8:25 PM, mdrobnak@ringleaderdigital.com wrote:

Hi everyone,
I'm fairly new to Chef. I downloaded and deployed the tomcat cookbook to
a
node, and now I'm trying to add a recipe? or another cookbook, I'm not
sure
really...to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the
webapps
directory, and scp a file to the right spot..then start tomcat.

I looked briefly at the deploy resource, but that's from a version
control
system...we don't keep builds in version control, only the source..the
binary
builds are on a server, so I don't think that's what I want.

If anyone can point me in the right direction to get this going, that
would be
greatly appreciated.

Thanks.

-Matt

--
Haim

The java_webapp recipe in the application cookbook [0][1] was created to
accomplish just this task!

The Java Quick Start [1] has a full working example of using this recipe to
deploy a Java webapp, including setting up an environment
specific context.xml with database connection information.

Seth

--
Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo

[0] http://community.opscode.com/cookbooks/application
[1] https://github.com/opscode/cookbooks/blob/master/application/README.md
[2] Chef Support for Automation & DevOps | Chef

On Mon, Jun 20, 2011 at 11:35 PM, Ken Mazaika kmazaika@gmail.com wrote:

could you use something like capistrano for java?

On Mon, Jun 20, 2011 at 11:32 PM, Edward Sargisson esarge@pobox.comwrote:

I need to do the same thing but haven't written it yet. Here's my plan

  • hopefully others can critique.

Firstly, you don't want to stop tomcat. Chef runs every 20 minutes or
so (or whenever you set it for) so it would stop your server every 20
minutes. Instead, you should work out if the file on your file server
has changed and then do the update. In my case, my build artifacts
have a build id. I plan to store the desired build id in a data bag *.
The deployed data bag goes into the node data. Then, on the chef run
it can compare and then run the update if required.

When you do the update you don't need to stop tomcat. Instead you
download the WAR to a temp directory then go to the webapps dir and
delete the directory for your webapp as well as the old WAR. Then you
copy the WAR in. (You can't download directly because then Tomcat
un-jars it before it's downloaded). Tomcat then un-jars it and starts
it up for you.

Cheers,
Edward

  • Amusingly, I forgot the name for data bag and my mind came up with
    drop bag. Once a trail runner, always a trail runner... :slight_smile:

On Mon, Jun 20, 2011 at 8:25 PM, mdrobnak@ringleaderdigital.com wrote:

Hi everyone,
I'm fairly new to Chef. I downloaded and deployed the tomcat cookbook to
a
node, and now I'm trying to add a recipe? or another cookbook, I'm not
sure
really...to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the
webapps
directory, and scp a file to the right spot..then start tomcat.

I looked briefly at the deploy resource, but that's from a version
control
system...we don't keep builds in version control, only the source..the
binary
builds are on a server, so I don't think that's what I want.

If anyone can point me in the right direction to get this going, that
would be
greatly appreciated.

Thanks.

-Matt

I appreciate everyone's input so far.

Seth, I totally missed the application cookbook. I'll look into that and hopefully can get at least 1 piece running with Chef!

I love the premise, but all of the configuration management systems seem to have a bit of a steep climb before it becomes easy and powerful. :slight_smile:

Thanks again.

-Matt

On Jun 21, 2011, at 12:10 AM, Seth Chisamore wrote:

The java_webapp recipe in the application cookbook [0][1] was created to accomplish just this task!

The Java Quick Start [1] has a full working example of using this recipe to deploy a Java webapp, including setting up an environment specific context.xml with database connection information.

Seth

--
Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo

[0] http://community.opscode.com/cookbooks/application
[1] https://github.com/opscode/cookbooks/blob/master/application/README.md
[2] Chef Support for Automation & DevOps | Chef

On Mon, Jun 20, 2011 at 11:35 PM, Ken Mazaika <kmazaika@gmail.commailto:kmazaika@gmail.com> wrote:
could you use something like capistrano for java?

On Mon, Jun 20, 2011 at 11:32 PM, Edward Sargisson <esarge@pobox.commailto:esarge@pobox.com> wrote:
I need to do the same thing but haven't written it yet. Here's my plan

  • hopefully others can critique.

Firstly, you don't want to stop tomcat. Chef runs every 20 minutes or
so (or whenever you set it for) so it would stop your server every 20
minutes. Instead, you should work out if the file on your file server
has changed and then do the update. In my case, my build artifacts
have a build id. I plan to store the desired build id in a data bag *.
The deployed data bag goes into the node data. Then, on the chef run
it can compare and then run the update if required.

When you do the update you don't need to stop tomcat. Instead you
download the WAR to a temp directory then go to the webapps dir and
delete the directory for your webapp as well as the old WAR. Then you
copy the WAR in. (You can't download directly because then Tomcat
un-jars it before it's downloaded). Tomcat then un-jars it and starts
it up for you.

Cheers,
Edward

  • Amusingly, I forgot the name for data bag and my mind came up with
    drop bag. Once a trail runner, always a trail runner... :slight_smile:

On Mon, Jun 20, 2011 at 8:25 PM, <mdrobnak@ringleaderdigital.commailto:mdrobnak@ringleaderdigital.com> wrote:

Hi everyone,
I'm fairly new to Chef. I downloaded and deployed the tomcat cookbook to a
node, and now I'm trying to add a recipe? or another cookbook, I'm not sure
really...to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the webapps
directory, and scp a file to the right spot..then start tomcat.

I looked briefly at the deploy resource, but that's from a version control
system...we don't keep builds in version control, only the source..the binary
builds are on a server, so I don't think that's what I want.

If anyone can point me in the right direction to get this going, that would be
greatly appreciated.

Thanks.

-Matt

A couple other thoughts for you:

  • We do this by keeping builds as maven (http://maven.apache.org/)
    artifacts in a nexus repository (http://nexus.sonatype.org/) and
    deploy with a custom artifact deployer cookbook. With nexus you have a
    nice API you can use to determine the right build to deploy and
    compare to what was deployed. Although we haven't released that
    cookbook yet, if you're having issues, I'll prod my teammate that
    wrote it to help you.

  • Keep in mind if you end up doing live deployments (i.e. don't
    restart tomcat) you may run into memory issues. I've had problems with
    pretty much every java container trying to do live deploys. Basically
    the JVM leaks memory and eventually you hang the JVM. Since the
    failure happens indeterminately, I decided better to deal with
    restarts and have a repeatable process then to attempt a live deploy
    that may fail randomly, if infrequently. However, I've heard tomcat 7
    tries to work around this issues and maybe its better?

KC

On Tue, Jun 21, 2011 at 4:44 AM, Matthew Drobnak
mdrobnak@ringleaderdigital.com wrote:

I appreciate everyone's input so far.
Seth, I totally missed the application cookbook. I'll look into that and
hopefully can get at least 1 piece running with Chef!
I love the premise, but all of the configuration management systems seem to
have a bit of a steep climb before it becomes easy and powerful. :slight_smile:
Thanks again.
-Matt

On Jun 21, 2011, at 12:10 AM, Seth Chisamore wrote:

The java_webapp recipe in the application cookbook [0][1] was created to
accomplish just this task!
The Java Quick Start [1] has a full working example of using this recipe to
deploy a Java webapp, including setting up an environment
specific context.xml with database connection information.
Seth

Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo
[0] http://community.opscode.com/cookbooks/application
[1] https://github.com/opscode/cookbooks/blob/master/application/README.md
[2] Chef Support for Automation & DevOps | Chef

On Mon, Jun 20, 2011 at 11:35 PM, Ken Mazaika kmazaika@gmail.com wrote:

could you use something like capistrano for java?

On Mon, Jun 20, 2011 at 11:32 PM, Edward Sargisson esarge@pobox.com
wrote:

I need to do the same thing but haven't written it yet. Here's my plan

  • hopefully others can critique.

Firstly, you don't want to stop tomcat. Chef runs every 20 minutes or
so (or whenever you set it for) so it would stop your server every 20
minutes. Instead, you should work out if the file on your file server
has changed and then do the update. In my case, my build artifacts
have a build id. I plan to store the desired build id in a data bag *.
The deployed data bag goes into the node data. Then, on the chef run
it can compare and then run the update if required.

When you do the update you don't need to stop tomcat. Instead you
download the WAR to a temp directory then go to the webapps dir and
delete the directory for your webapp as well as the old WAR. Then you
copy the WAR in. (You can't download directly because then Tomcat
un-jars it before it's downloaded). Tomcat then un-jars it and starts
it up for you.

Cheers,
Edward

  • Amusingly, I forgot the name for data bag and my mind came up with
    drop bag. Once a trail runner, always a trail runner... :slight_smile:

On Mon, Jun 20, 2011 at 8:25 PM, mdrobnak@ringleaderdigital.com wrote:

Hi everyone,
I'm fairly new to Chef. I downloaded and deployed the tomcat cookbook
to a
node, and now I'm trying to add a recipe? or another cookbook, I'm not
sure
really...to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the
webapps
directory, and scp a file to the right spot..then start tomcat.

I looked briefly at the deploy resource, but that's from a version
control
system...we don't keep builds in version control, only the source..the
binary
builds are on a server, so I don't think that's what I want.

If anyone can point me in the right direction to get this going, that
would be
greatly appreciated.

Thanks.

-Matt

Specifically on the process management front, we're using jetty. We
tried the hot deploy and it pretty much became unreliable after 5 or
so deploys a day.

We've since moved to using supervisord to manage our jetty processes.
We just do a full restart at deploy time. It's sequentially done in
jenkins right now so we don't lose all of our capacity at once. We
pull the war + appropriate configs from S3.

On Tue, Jun 21, 2011 at 1:57 PM, KC Braunschweig
kcbraunschweig@gmail.com wrote:

A couple other thoughts for you:

  • We do this by keeping builds as maven (http://maven.apache.org/)
    artifacts in a nexus repository (http://nexus.sonatype.org/) and
    deploy with a custom artifact deployer cookbook. With nexus you have a
    nice API you can use to determine the right build to deploy and
    compare to what was deployed. Although we haven't released that
    cookbook yet, if you're having issues, I'll prod my teammate that
    wrote it to help you.

  • Keep in mind if you end up doing live deployments (i.e. don't
    restart tomcat) you may run into memory issues. I've had problems with
    pretty much every java container trying to do live deploys. Basically
    the JVM leaks memory and eventually you hang the JVM. Since the
    failure happens indeterminately, I decided better to deal with
    restarts and have a repeatable process then to attempt a live deploy
    that may fail randomly, if infrequently. However, I've heard tomcat 7
    tries to work around this issues and maybe its better?

KC

On Tue, Jun 21, 2011 at 4:44 AM, Matthew Drobnak
mdrobnak@ringleaderdigital.com wrote:

I appreciate everyone's input so far.
Seth, I totally missed the application cookbook. I'll look into that and
hopefully can get at least 1 piece running with Chef!
I love the premise, but all of the configuration management systems seem to
have a bit of a steep climb before it becomes easy and powerful. :slight_smile:
Thanks again.
-Matt

On Jun 21, 2011, at 12:10 AM, Seth Chisamore wrote:

The java_webapp recipe in the application cookbook [0][1] was created to
accomplish just this task!
The Java Quick Start [1] has a full working example of using this recipe to
deploy a Java webapp, including setting up an environment
specific context.xml with database connection information.
Seth

Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo
[0] http://community.opscode.com/cookbooks/application
[1] https://github.com/opscode/cookbooks/blob/master/application/README.md
[2] Chef Support for Automation & DevOps | Chef

On Mon, Jun 20, 2011 at 11:35 PM, Ken Mazaika kmazaika@gmail.com wrote:

could you use something like capistrano for java?

On Mon, Jun 20, 2011 at 11:32 PM, Edward Sargisson esarge@pobox.com
wrote:

I need to do the same thing but haven't written it yet. Here's my plan

  • hopefully others can critique.

Firstly, you don't want to stop tomcat. Chef runs every 20 minutes or
so (or whenever you set it for) so it would stop your server every 20
minutes. Instead, you should work out if the file on your file server
has changed and then do the update. In my case, my build artifacts
have a build id. I plan to store the desired build id in a data bag *.
The deployed data bag goes into the node data. Then, on the chef run
it can compare and then run the update if required.

When you do the update you don't need to stop tomcat. Instead you
download the WAR to a temp directory then go to the webapps dir and
delete the directory for your webapp as well as the old WAR. Then you
copy the WAR in. (You can't download directly because then Tomcat
un-jars it before it's downloaded). Tomcat then un-jars it and starts
it up for you.

Cheers,
Edward

  • Amusingly, I forgot the name for data bag and my mind came up with
    drop bag. Once a trail runner, always a trail runner... :slight_smile:

On Mon, Jun 20, 2011 at 8:25 PM, mdrobnak@ringleaderdigital.com wrote:

Hi everyone,
I'm fairly new to Chef. I downloaded and deployed the tomcat cookbook
to a
node, and now I'm trying to add a recipe? or another cookbook, I'm not
sure
really...to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the
webapps
directory, and scp a file to the right spot..then start tomcat.

I looked briefly at the deploy resource, but that's from a version
control
system...we don't keep builds in version control, only the source..the
binary
builds are on a server, so I don't think that's what I want.

If anyone can point me in the right direction to get this going, that
would be
greatly appreciated.

Thanks.

-Matt

I've also found that doing multiple deploys via Tomcat API doesn't work well
so I'm using a build based approach with all new instances.. to do this
I've created a custom Bootstrap template for EC2. I've added the following
which gets slurped up and read in my recipe. I then pull the appropriate
file from S3. My web layer knows about all of the different builds
available and can direct different clients to the correct build for their DB
state...

(
cat <<'EOP'
build: <%= ENV['BUILD'] %>
EOP
) > /tmp/build.yml

---- spinner script ---

#!/bin/bash
echo

if test -z "$1"
then
echo "No build number passed"
echo "Usage: "
echo "sledgehammer_app_prod.sh "
else
echo "Starting Production Server w/ Build #: $1."
BUILD=$1 knife ec2 server create
-I ami-04c9306d
-f m1.large
-S production
-E production
-G application_layer,chef_client,production
-x ubuntu
--template-file ~/chef-repo/templates/sledgehammer_app.erb
-i ~/.ssh/production.pem
-r
recipe[sledgehammer_app],recipe[zabbix::client],recipe[splunk::light_forwarder]
fi

On Tue, Jun 21, 2011 at 1:04 PM, John E. Vincent (lusis) <lusis.org+
chef-list@gmail.com> wrote:

Specifically on the process management front, we're using jetty. We
tried the hot deploy and it pretty much became unreliable after 5 or
so deploys a day.

We've since moved to using supervisord to manage our jetty processes.
We just do a full restart at deploy time. It's sequentially done in
jenkins right now so we don't lose all of our capacity at once. We
pull the war + appropriate configs from S3.

On Tue, Jun 21, 2011 at 1:57 PM, KC Braunschweig
kcbraunschweig@gmail.com wrote:

A couple other thoughts for you:

  • We do this by keeping builds as maven (http://maven.apache.org/)
    artifacts in a nexus repository (http://nexus.sonatype.org/) and
    deploy with a custom artifact deployer cookbook. With nexus you have a
    nice API you can use to determine the right build to deploy and
    compare to what was deployed. Although we haven't released that
    cookbook yet, if you're having issues, I'll prod my teammate that
    wrote it to help you.

  • Keep in mind if you end up doing live deployments (i.e. don't
    restart tomcat) you may run into memory issues. I've had problems with
    pretty much every java container trying to do live deploys. Basically
    the JVM leaks memory and eventually you hang the JVM. Since the
    failure happens indeterminately, I decided better to deal with
    restarts and have a repeatable process then to attempt a live deploy
    that may fail randomly, if infrequently. However, I've heard tomcat 7
    tries to work around this issues and maybe its better?

KC

On Tue, Jun 21, 2011 at 4:44 AM, Matthew Drobnak
mdrobnak@ringleaderdigital.com wrote:

I appreciate everyone's input so far.
Seth, I totally missed the application cookbook. I'll look into that and
hopefully can get at least 1 piece running with Chef!
I love the premise, but all of the configuration management systems seem
to
have a bit of a steep climb before it becomes easy and powerful. :slight_smile:
Thanks again.
-Matt

On Jun 21, 2011, at 12:10 AM, Seth Chisamore wrote:

The java_webapp recipe in the application cookbook [0][1] was created to
accomplish just this task!
The Java Quick Start [1] has a full working example of using this recipe
to
deploy a Java webapp, including setting up an environment
specific context.xml with database connection information.
Seth

Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo
[0] http://community.opscode.com/cookbooks/application
[1]
https://github.com/opscode/cookbooks/blob/master/application/README.md
[2] Chef Support for Automation & DevOps | Chef

On Mon, Jun 20, 2011 at 11:35 PM, Ken Mazaika kmazaika@gmail.com
wrote:

could you use something like capistrano for java?

On Mon, Jun 20, 2011 at 11:32 PM, Edward Sargisson esarge@pobox.com
wrote:

I need to do the same thing but haven't written it yet. Here's my plan

  • hopefully others can critique.

Firstly, you don't want to stop tomcat. Chef runs every 20 minutes or
so (or whenever you set it for) so it would stop your server every 20
minutes. Instead, you should work out if the file on your file server
has changed and then do the update. In my case, my build artifacts
have a build id. I plan to store the desired build id in a data bag *.
The deployed data bag goes into the node data. Then, on the chef run
it can compare and then run the update if required.

When you do the update you don't need to stop tomcat. Instead you
download the WAR to a temp directory then go to the webapps dir and
delete the directory for your webapp as well as the old WAR. Then you
copy the WAR in. (You can't download directly because then Tomcat
un-jars it before it's downloaded). Tomcat then un-jars it and starts
it up for you.

Cheers,
Edward

  • Amusingly, I forgot the name for data bag and my mind came up with
    drop bag. Once a trail runner, always a trail runner... :slight_smile:

On Mon, Jun 20, 2011 at 8:25 PM, mdrobnak@ringleaderdigital.com
wrote:

Hi everyone,
I'm fairly new to Chef. I downloaded and deployed the tomcat
cookbook
to a
node, and now I'm trying to add a recipe? or another cookbook, I'm
not
sure
really...to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the
webapps
directory, and scp a file to the right spot..then start tomcat.

I looked briefly at the deploy resource, but that's from a version
control
system...we don't keep builds in version control, only the
source..the
binary
builds are on a server, so I don't think that's what I want.

If anyone can point me in the right direction to get this going,
that
would be
greatly appreciated.

Thanks.

-Matt

--
Charles Sullivan
charlie.sullivan@gmail.com

Yeah we actually do something similar specific for bootstrapping new
nodes. We have a cookbook per application (around 7 or so now) and
each cookbook has a "bootstrap" recipe. This is part of the bootstrap
and then is removed from the run_list after it's online. This also
does things like add the node to our ELB pool.

Everything after that is a Jenkins push.

On Tue, Jun 21, 2011 at 2:16 PM, Charles Sullivan
charlie.sullivan@gmail.com wrote:

I've also found that doing multiple deploys via Tomcat API doesn't work well
so I'm using a build based approach with all new instances.. to do this
I've created a custom Bootstrap template for EC2. I've added the following
which gets slurped up and read in my recipe. I then pull the appropriate
file from S3. My web layer knows about all of the different builds
available and can direct different clients to the correct build for their DB
state...
(
cat <<'EOP'
build: <%= ENV['BUILD'] %>
EOP
) > /tmp/build.yml

---- spinner script ---
#!/bin/bash
echo
if test -z "$1"
then
echo "No build number passed"
echo "Usage: "
echo "sledgehammer_app_prod.sh "
else
echo "Starting Production Server w/ Build #: $1."
BUILD=$1 knife ec2 server create
-I ami-04c9306d
-f m1.large
-S production
-E production
-G application_layer,chef_client,production
-x ubuntu
--template-file ~/chef-repo/templates/sledgehammer_app.erb
-i ~/.ssh/production.pem
-r
recipe[sledgehammer_app],recipe[zabbix::client],recipe[splunk::light_forwarder]
fi

On Tue, Jun 21, 2011 at 1:04 PM, John E. Vincent (lusis)
lusis.org+chef-list@gmail.com wrote:

Specifically on the process management front, we're using jetty. We
tried the hot deploy and it pretty much became unreliable after 5 or
so deploys a day.

We've since moved to using supervisord to manage our jetty processes.
We just do a full restart at deploy time. It's sequentially done in
jenkins right now so we don't lose all of our capacity at once. We
pull the war + appropriate configs from S3.

On Tue, Jun 21, 2011 at 1:57 PM, KC Braunschweig
kcbraunschweig@gmail.com wrote:

A couple other thoughts for you:

  • We do this by keeping builds as maven (http://maven.apache.org/)
    artifacts in a nexus repository (http://nexus.sonatype.org/) and
    deploy with a custom artifact deployer cookbook. With nexus you have a
    nice API you can use to determine the right build to deploy and
    compare to what was deployed. Although we haven't released that
    cookbook yet, if you're having issues, I'll prod my teammate that
    wrote it to help you.

  • Keep in mind if you end up doing live deployments (i.e. don't
    restart tomcat) you may run into memory issues. I've had problems with
    pretty much every java container trying to do live deploys. Basically
    the JVM leaks memory and eventually you hang the JVM. Since the
    failure happens indeterminately, I decided better to deal with
    restarts and have a repeatable process then to attempt a live deploy
    that may fail randomly, if infrequently. However, I've heard tomcat 7
    tries to work around this issues and maybe its better?

KC

On Tue, Jun 21, 2011 at 4:44 AM, Matthew Drobnak
mdrobnak@ringleaderdigital.com wrote:

I appreciate everyone's input so far.
Seth, I totally missed the application cookbook. I'll look into that
and
hopefully can get at least 1 piece running with Chef!
I love the premise, but all of the configuration management systems
seem to
have a bit of a steep climb before it becomes easy and powerful. :slight_smile:
Thanks again.
-Matt

On Jun 21, 2011, at 12:10 AM, Seth Chisamore wrote:

The java_webapp recipe in the application cookbook [0][1] was created
to
accomplish just this task!
The Java Quick Start [1] has a full working example of using this
recipe to
deploy a Java webapp, including setting up an environment
specific context.xml with database connection information.
Seth

Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo
[0] http://community.opscode.com/cookbooks/application

[1] https://github.com/opscode/cookbooks/blob/master/application/README.md
[2] Chef Support for Automation & DevOps | Chef

On Mon, Jun 20, 2011 at 11:35 PM, Ken Mazaika kmazaika@gmail.com
wrote:

could you use something like capistrano for java?

On Mon, Jun 20, 2011 at 11:32 PM, Edward Sargisson esarge@pobox.com
wrote:

I need to do the same thing but haven't written it yet. Here's my
plan

  • hopefully others can critique.

Firstly, you don't want to stop tomcat. Chef runs every 20 minutes or
so (or whenever you set it for) so it would stop your server every 20
minutes. Instead, you should work out if the file on your file server
has changed and then do the update. In my case, my build artifacts
have a build id. I plan to store the desired build id in a data bag
*.
The deployed data bag goes into the node data. Then, on the chef run
it can compare and then run the update if required.

When you do the update you don't need to stop tomcat. Instead you
download the WAR to a temp directory then go to the webapps dir and
delete the directory for your webapp as well as the old WAR. Then you
copy the WAR in. (You can't download directly because then Tomcat
un-jars it before it's downloaded). Tomcat then un-jars it and starts
it up for you.

Cheers,
Edward

  • Amusingly, I forgot the name for data bag and my mind came up with
    drop bag. Once a trail runner, always a trail runner... :slight_smile:

On Mon, Jun 20, 2011 at 8:25 PM, mdrobnak@ringleaderdigital.com
wrote:

Hi everyone,
I'm fairly new to Chef. I downloaded and deployed the tomcat
cookbook
to a
node, and now I'm trying to add a recipe? or another cookbook, I'm
not
sure
really...to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the
webapps
directory, and scp a file to the right spot..then start tomcat.

I looked briefly at the deploy resource, but that's from a version
control
system...we don't keep builds in version control, only the
source..the
binary
builds are on a server, so I don't think that's what I want.

If anyone can point me in the right direction to get this going,
that
would be
greatly appreciated.

Thanks.

-Matt

--
Charles Sullivan
charlie.sullivan@gmail.com

Ok, so I did the following:

Created a role called spark_server:

{
"name": "spark_server",
"default_attributes": {
},
"json_class": "Chef::Role",
"env_run_lists": {
},
"run_list": [
"recipe[application]"
],
"description": "Spark Tomcat Server",
"chef_type": "role",
"override_attributes": {
}
}

Created data bag apps:

{
"group": "nogroup",
"server_roles": [
"spark_server"
],
"databases": {
"_default": {
"max_active": "100",
"port": "1433",
"username": "user",
"adapter": "sqlserver",
"max_idle": "30",
"database": "appname",
"driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"max_wait": "10000",
"password": "awesome_password"
},
"dev": {
"max_active": "100",
"port": "1433",
"username": "user",
"adapter": "sqlserver",
"max_idle": "30",
"database": "appname",
"driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"max_wait": "10000",
"password": "apppass"
}
},
"id": "AppName",
"mysql_repl_password": {
"_default": "mysql_repl"
},
"type": {
"spark_server": [
"java_webapp",
"tomcat"
]
},
"war": {
"_default": {
"checksum": "06880edebbf24c4000da4d45d26aa97ddc2a6ad1ae3e4365c755fdb5a1ad481a",
"source": "http://redacted/spark_server.war"
}
},
"mysql_root_password": {
"_default": "mysql_root"
},
"mysql_debian_password": {
"_default": "mysql_debian"
},
"deploy_to": "/srv/spark_server",
"owner": "nobody"
}

These are the cookbooks I have installed:

apache2 0.99.4
application 0.99.11
apt 1.1.2
build-essential 1.0.0
chef-client 0.99.5
gunicorn 1.0.0
java 1.1.0
jpackage 0.10.0
mysql 1.0.6
openssl 1.0.0
passenger_apache2 0.99.0
php 1.0.0
python 1.0.2
runit 0.14.2
tomcat 0.10.3
unicorn 1.0.0
xml 1.0.0

So at this point:
I have a node, with Tomcat installed. But, I have /srv/spark_sever/releases/.war plus a shared/logs, shared/pids,shared/system directories which are empty. /etc/tomcat6/Catalina/localhost/ROOT.xml points to /srv/spark_server/shared/AppName.xml, which does not exist.
/var/lib/tomcat6/webapps is empty (ROOT was deleted by the java_webapp recipe...), so there's nothing actually running.

So two things:
What happened to my context.xml file?
How can I deploy to a named context instead of the ROOT context?

Thanks.

-Matt

From: Matthew Drobnak [mailto:mdrobnak@ringleaderdigital.com]
Sent: Tuesday, June 21, 2011 7:45 AM
To: chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Re: Deploying .war files?

I appreciate everyone's input so far.

Seth, I totally missed the application cookbook. I'll look into that and hopefully can get at least 1 piece running with Chef!

I love the premise, but all of the configuration management systems seem to have a bit of a steep climb before it becomes easy and powerful. :slight_smile:

Thanks again.

-Matt

On Jun 21, 2011, at 12:10 AM, Seth Chisamore wrote:

The java_webapp recipe in the application cookbook [0][1] was created to accomplish just this task!

The Java Quick Start [1] has a full working example of using this recipe to deploy a Java webapp, including setting up an environment specific context.xml with database connection information.

Seth

--
Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo

[0] http://community.opscode.com/cookbooks/application
[1] https://github.com/opscode/cookbooks/blob/master/application/README.md
[2] Chef Support for Automation & DevOps | Chef

On Mon, Jun 20, 2011 at 11:35 PM, Ken Mazaika <kmazaika@gmail.commailto:kmazaika@gmail.com> wrote:
could you use something like capistrano for java?

On Mon, Jun 20, 2011 at 11:32 PM, Edward Sargisson <esarge@pobox.commailto:esarge@pobox.com> wrote:
I need to do the same thing but haven't written it yet. Here's my plan

  • hopefully others can critique.

Firstly, you don't want to stop tomcat. Chef runs every 20 minutes or
so (or whenever you set it for) so it would stop your server every 20
minutes. Instead, you should work out if the file on your file server
has changed and then do the update. In my case, my build artifacts
have a build id. I plan to store the desired build id in a data bag *.
The deployed data bag goes into the node data. Then, on the chef run
it can compare and then run the update if required.

When you do the update you don't need to stop tomcat. Instead you
download the WAR to a temp directory then go to the webapps dir and
delete the directory for your webapp as well as the old WAR. Then you
copy the WAR in. (You can't download directly because then Tomcat
un-jars it before it's downloaded). Tomcat then un-jars it and starts
it up for you.

Cheers,
Edward

  • Amusingly, I forgot the name for data bag and my mind came up with
    drop bag. Once a trail runner, always a trail runner... :slight_smile:

On Mon, Jun 20, 2011 at 8:25 PM, <mdrobnak@ringleaderdigital.commailto:mdrobnak@ringleaderdigital.com> wrote:

Hi everyone,
I'm fairly new to Chef. I downloaded and deployed the tomcat cookbook to a
node, and now I'm trying to add a recipe? or another cookbook, I'm not sure
really...to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the webapps
directory, and scp a file to the right spot..then start tomcat.

I looked briefly at the deploy resource, but that's from a version control
system...we don't keep builds in version control, only the source..the binary
builds are on a server, so I don't think that's what I want.

If anyone can point me in the right direction to get this going, that would be
greatly appreciated.

Thanks.

-Matt

Hi,

I did a example installation with the application cookbook here:

http://www.iteh.at/en/blog/2011/04/16/data-driven-deployment-of-a-java-web-application-with-chef-solo/

cu edi

On 22.06.2011, at 20:11, Matthew Drobnak wrote:

Ok, so I did the following:

Created a role called spark_server:

{
"name": "spark_server",
"default_attributes": {
},
"json_class": "Chef::Role",
"env_run_lists": {
},
"run_list": [
"recipe[application]"
],
"description": "Spark Tomcat Server",
"chef_type": "role",
"override_attributes": {
}
}

Created data bag apps:

{
"group": "nogroup",
"server_roles": [
"spark_server"
],
"databases": {
"_default": {
"max_active": "100",
"port": "1433",
"username": "user",
"adapter": "sqlserver",
"max_idle": "30",
"database": "appname",
"driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"max_wait": "10000",
"password": "awesome_password"
},
"dev": {
"max_active": "100",
"port": "1433",
"username": "user",
"adapter": "sqlserver",
"max_idle": "30",
"database": "appname",
"driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"max_wait": "10000",
"password": "apppass"
}
},
"id": "AppName",
"mysql_repl_password": {
"_default": "mysql_repl"
},
"type": {
"spark_server": [
"java_webapp",
"tomcat"
]
},
"war": {
"_default": {
"checksum": "06880edebbf24c4000da4d45d26aa97ddc2a6ad1ae3e4365c755fdb5a1ad481a",
"source": "http://redacted/spark_server.war"
}
},
"mysql_root_password": {
"_default": "mysql_root"
},
"mysql_debian_password": {
"_default": "mysql_debian"
},
"deploy_to": "/srv/spark_server",
"owner": "nobody"
}

These are the cookbooks I have installed:

apache2 0.99.4
application 0.99.11
apt 1.1.2
build-essential 1.0.0
chef-client 0.99.5
gunicorn 1.0.0
java 1.1.0
jpackage 0.10.0
mysql 1.0.6
openssl 1.0.0
passenger_apache2 0.99.0
php 1.0.0
python 1.0.2
runit 0.14.2
tomcat 0.10.3
unicorn 1.0.0
xml 1.0.0

So at this point:
I have a node, with Tomcat installed. But, I have /srv/spark_sever/releases/.war plus a shared/logs, shared/pids,shared/system directories which are empty. /etc/tomcat6/Catalina/localhost/ROOT.xml points to /srv/spark_server/shared/AppName.xml, which does not exist.
/var/lib/tomcat6/webapps is empty (ROOT was deleted by the java_webapp recipe…), so there’s nothing actually running.

So two things:
What happened to my context.xml file?
How can I deploy to a named context instead of the ROOT context?

Thanks.

-Matt

From: Matthew Drobnak [mailto:mdrobnak@ringleaderdigital.com]
Sent: Tuesday, June 21, 2011 7:45 AM
To: chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Re: Deploying .war files?

I appreciate everyone's input so far.

Seth, I totally missed the application cookbook. I'll look into that and hopefully can get at least 1 piece running with Chef!

I love the premise, but all of the configuration management systems seem to have a bit of a steep climb before it becomes easy and powerful. :slight_smile:

Thanks again.

-Matt

On Jun 21, 2011, at 12:10 AM, Seth Chisamore wrote:

The java_webapp recipe in the application cookbook [0][1] was created to accomplish just this task!

The Java Quick Start [1] has a full working example of using this recipe to deploy a Java webapp, including setting up an environment specific context.xml with database connection information.

Seth

--
Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo

[0] http://community.opscode.com/cookbooks/application
[1] https://github.com/opscode/cookbooks/blob/master/application/README.md
[2] Chef Support for Automation & DevOps | Chef

On Mon, Jun 20, 2011 at 11:35 PM, Ken Mazaika kmazaika@gmail.com wrote:
could you use something like capistrano for java?

On Mon, Jun 20, 2011 at 11:32 PM, Edward Sargisson esarge@pobox.com wrote:
I need to do the same thing but haven't written it yet. Here's my plan

  • hopefully others can critique.

Firstly, you don't want to stop tomcat. Chef runs every 20 minutes or
so (or whenever you set it for) so it would stop your server every 20
minutes. Instead, you should work out if the file on your file server
has changed and then do the update. In my case, my build artifacts
have a build id. I plan to store the desired build id in a data bag *.
The deployed data bag goes into the node data. Then, on the chef run
it can compare and then run the update if required.

When you do the update you don't need to stop tomcat. Instead you
download the WAR to a temp directory then go to the webapps dir and
delete the directory for your webapp as well as the old WAR. Then you
copy the WAR in. (You can't download directly because then Tomcat
un-jars it before it's downloaded). Tomcat then un-jars it and starts
it up for you.

Cheers,
Edward

  • Amusingly, I forgot the name for data bag and my mind came up with
    drop bag. Once a trail runner, always a trail runner... :slight_smile:

On Mon, Jun 20, 2011 at 8:25 PM, mdrobnak@ringleaderdigital.com wrote:

Hi everyone,
I'm fairly new to Chef. I downloaded and deployed the tomcat cookbook to a
node, and now I'm trying to add a recipe? or another cookbook, I'm not sure
really...to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the webapps
directory, and scp a file to the right spot..then start tomcat.

I looked briefly at the deploy resource, but that's from a version control
system...we don't keep builds in version control, only the source..the binary
builds are on a server, so I don't think that's what I want.

If anyone can point me in the right direction to get this going, that would be
greatly appreciated.

Thanks.

-Matt

--
DI Edmund Haselwanter, edmund@haselwanter.com, http://edmund.haselwanter.com/
http://www.iteh.at | Facebook | http://at.linkedin.com/in/haselwanteredmund

Hi,

I've uploaded a reworked application and tomcat cookbook

http://www.iteh.at/en/blog/2011/06/23/deployment-of-java-web-applications-with-chef-from-opscode/
https://github.com/iteh/vagrant-demos/tree/master/vagrant-java-application-reworked

which allows for something like this:

load a json or do a search like in the application cookbook

https://github.com/iteh/vagrant-demos/blob/master/vagrant-java-application-reworked/databags/apps/java_app.json

app = JSON.parse(File.open( File.join( File.dirname(FILE), \ "../databags/my_webapp.json")).read)

node.run_state[:current_app] = app

application_java_webapp “my_webapp”
application_tomcat “my_webapp_tomcat”

node.run_state.delete(:current_app)

it uses a tomcat_context LWRP with shasum checking

tomcat_context app['path'] do
config "#{app['deploy_to']}/shared/#{app['id']}.xml"
checksum app['war'][node.app_environment]['checksum']
admin node["tomcat"]["admin"]
password node["tomcat"]["password"]
action [:update,:start]
end

might need some tuning and cleanup

i think the definition should move to a LWRP too

cu edi

On 22.06.2011, at 20:11, Matthew Drobnak wrote:

Ok, so I did the following:

Created a role called spark_server:

{
"name": "spark_server",
"default_attributes": {
},
"json_class": "Chef::Role",
"env_run_lists": {
},
"run_list": [
"recipe[application]"
],
"description": "Spark Tomcat Server",
"chef_type": "role",
"override_attributes": {
}
}

Created data bag apps:

{
"group": "nogroup",
"server_roles": [
"spark_server"
],
"databases": {
"_default": {
"max_active": "100",
"port": "1433",
"username": "user",
"adapter": "sqlserver",
"max_idle": "30",
"database": "appname",
"driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"max_wait": "10000",
"password": "awesome_password"
},
"dev": {
"max_active": "100",
"port": "1433",
"username": "user",
"adapter": "sqlserver",
"max_idle": "30",
"database": "appname",
"driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"max_wait": "10000",
"password": "apppass"
}
},
"id": "AppName",
"mysql_repl_password": {
"_default": "mysql_repl"
},
"type": {
"spark_server": [
"java_webapp",
"tomcat"
]
},
"war": {
"_default": {
"checksum": "06880edebbf24c4000da4d45d26aa97ddc2a6ad1ae3e4365c755fdb5a1ad481a",
"source": "http://redacted/spark_server.war"
}
},
"mysql_root_password": {
"_default": "mysql_root"
},
"mysql_debian_password": {
"_default": "mysql_debian"
},
"deploy_to": "/srv/spark_server",
"owner": "nobody"
}

These are the cookbooks I have installed:

apache2 0.99.4
application 0.99.11
apt 1.1.2
build-essential 1.0.0
chef-client 0.99.5
gunicorn 1.0.0
java 1.1.0
jpackage 0.10.0
mysql 1.0.6
openssl 1.0.0
passenger_apache2 0.99.0
php 1.0.0
python 1.0.2
runit 0.14.2
tomcat 0.10.3
unicorn 1.0.0
xml 1.0.0

So at this point:
I have a node, with Tomcat installed. But, I have /srv/spark_sever/releases/.war plus a shared/logs, shared/pids,shared/system directories which are empty. /etc/tomcat6/Catalina/localhost/ROOT.xml points to /srv/spark_server/shared/AppName.xml, which does not exist.
/var/lib/tomcat6/webapps is empty (ROOT was deleted by the java_webapp recipe…), so there’s nothing actually running.

So two things:
What happened to my context.xml file?
How can I deploy to a named context instead of the ROOT context?

Thanks.

-Matt

From: Matthew Drobnak [mailto:mdrobnak@ringleaderdigital.com]
Sent: Tuesday, June 21, 2011 7:45 AM
To: chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Re: Deploying .war files?

I appreciate everyone's input so far.

Seth, I totally missed the application cookbook. I'll look into that and hopefully can get at least 1 piece running with Chef!

I love the premise, but all of the configuration management systems seem to have a bit of a steep climb before it becomes easy and powerful. :slight_smile:

Thanks again.

-Matt

On Jun 21, 2011, at 12:10 AM, Seth Chisamore wrote:

The java_webapp recipe in the application cookbook [0][1] was created to accomplish just this task!

The Java Quick Start [1] has a full working example of using this recipe to deploy a Java webapp, including setting up an environment specific context.xml with database connection information.

Seth

--
Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo

[0] http://community.opscode.com/cookbooks/application
[1] https://github.com/opscode/cookbooks/blob/master/application/README.md
[2] Chef Support for Automation & DevOps | Chef

On Mon, Jun 20, 2011 at 11:35 PM, Ken Mazaika kmazaika@gmail.com wrote:
could you use something like capistrano for java?

On Mon, Jun 20, 2011 at 11:32 PM, Edward Sargisson esarge@pobox.com wrote:
I need to do the same thing but haven't written it yet. Here's my plan

  • hopefully others can critique.

Firstly, you don't want to stop tomcat. Chef runs every 20 minutes or
so (or whenever you set it for) so it would stop your server every 20
minutes. Instead, you should work out if the file on your file server
has changed and then do the update. In my case, my build artifacts
have a build id. I plan to store the desired build id in a data bag *.
The deployed data bag goes into the node data. Then, on the chef run
it can compare and then run the update if required.

When you do the update you don't need to stop tomcat. Instead you
download the WAR to a temp directory then go to the webapps dir and
delete the directory for your webapp as well as the old WAR. Then you
copy the WAR in. (You can't download directly because then Tomcat
un-jars it before it's downloaded). Tomcat then un-jars it and starts
it up for you.

Cheers,
Edward

  • Amusingly, I forgot the name for data bag and my mind came up with
    drop bag. Once a trail runner, always a trail runner... :slight_smile:

On Mon, Jun 20, 2011 at 8:25 PM, mdrobnak@ringleaderdigital.com wrote:

Hi everyone,
I'm fairly new to Chef. I downloaded and deployed the tomcat cookbook to a
node, and now I'm trying to add a recipe? or another cookbook, I'm not sure
really...to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the webapps
directory, and scp a file to the right spot..then start tomcat.

I looked briefly at the deploy resource, but that's from a version control
system...we don't keep builds in version control, only the source..the binary
builds are on a server, so I don't think that's what I want.

If anyone can point me in the right direction to get this going, that would be
greatly appreciated.

Thanks.

-Matt

--
DI Edmund Haselwanter, edmund@haselwanter.com, http://edmund.haselwanter.com/
http://www.iteh.at | Facebook | http://at.linkedin.com/in/haselwanteredmund

Matt,
The context.xml should have been created as "/srv/spark_server/shared/AppName.xml" [0], but that will only happen if a database master is found in the search [1]. This file is then symlinked over [2] into the tomcat context dir. It appears you are missing the 'database_master_role' value in your data bag item, this would cause the search to return no results.

Right now the application::java_webapp recipe only supports deploying wars into the root of the container. Mostly because in our initial customer use cases they were deploying single apps into smaller horizontally scaled app servers. Deploying into the root context makes automating the configuration of the load balancing layer much easier.

Seth

--
Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo

[0] https://github.com/opscode/cookbooks/blob/master/application/recipes/java_webapp.rb#L87
[1] https://github.com/opscode/cookbooks/blob/master/application/recipes/java_webapp.rb#L78
[2] https://github.com/opscode/cookbooks/blob/master/application/recipes/tomcat.rb#L31

On Wednesday, June 22, 2011 at 2:11 PM, Matthew Drobnak wrote:

Ok, so I did the following:

Created a role called spark_server:

{
"name": "spark_server",
"default_attributes": {
},
"json_class": "Chef::Role",
"env_run_lists": {
},
"run_list": [
"recipe[application]"
],
"description": "Spark Tomcat Server",
"chef_type": "role",
"override_attributes": {
}
}

Created data bag apps:

{
"group": "nogroup",
"server_roles": [
"spark_server"
],
"databases": {
"_default": {
"max_active": "100",
"port": "1433",
"username": "user",
"adapter": "sqlserver",
"max_idle": "30",
"database": "appname",
"driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"max_wait": "10000",
"password": "awesome_password"
},
"dev": {
"max_active": "100",
"port": "1433",
"username": "user",
"adapter": "sqlserver",
"max_idle": "30",
"database": "appname",
"driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"max_wait": "10000",
"password": "apppass"
}
},
"id": "AppName",
"mysql_repl_password": {
"_default": "mysql_repl"
},
"type": {
"spark_server": [
"java_webapp",
"tomcat"
]
},
"war": {
"_default": {
"checksum": "06880edebbf24c4000da4d45d26aa97ddc2a6ad1ae3e4365c755fdb5a1ad481a",
"source": "http://redacted/spark_server.war"
}
},
"mysql_root_password": {
"_default": "mysql_root"
},
"mysql_debian_password": {
"_default": "mysql_debian"
},
"deploy_to": "/srv/spark_server",
"owner": "nobody"
}

These are the cookbooks I have installed:

apache2 0.99.4
application 0.99.11
apt 1.1.2
build-essential 1.0.0
chef-client 0.99.5
gunicorn 1.0.0
java 1.1.0
jpackage 0.10.0
mysql 1.0.6
openssl 1.0.0
passenger_apache2 0.99.0
php 1.0.0
python 1.0.2
runit 0.14.2
tomcat 0.10.3
unicorn 1.0.0
xml 1.0.0

So at this point:
I have a node, with Tomcat installed. But, I have /srv/spark_sever/releases/.war plus a shared/logs, shared/pids,shared/system directories which are empty. /etc/tomcat6/Catalina/localhost/ROOT.xml points to /srv/spark_server/shared/AppName.xml, which does not exist.
/var/lib/tomcat6/webapps is empty (ROOT was deleted by the java_webapp recipe…), so there’s nothing actually running.

So two things:
What happened to my context.xml file?
How can I deploy to a named context instead of the ROOT context?

Thanks.

-Matt

From: Matthew Drobnak [mailto:mdrobnak@ringleaderdigital.com]
Sent: Tuesday, June 21, 2011 7:45 AM
To: chef@lists.opscode.com (mailto:chef@lists.opscode.com)
Subject: [chef] Re: Re: Re: Re: Deploying .war files?

I appreciate everyone's input so far.

Seth, I totally missed the application cookbook. I'll look into that and hopefully can get at least 1 piece running with Chef!

I love the premise, but all of the configuration management systems seem to have a bit of a steep climb before it becomes easy and powerful. :slight_smile:

Thanks again.

-Matt

On Jun 21, 2011, at 12:10 AM, Seth Chisamore wrote:

The java_webapp recipe in the application cookbook [0][1] was created to accomplish just this task!

The Java Quick Start [1] has a full working example of using this recipe to deploy a Java webapp, including setting up an environment specific context.xml with database connection information.

Seth

--
Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo

[0] http://community.opscode.com/cookbooks/application

[1] https://github.com/opscode/cookbooks/blob/master/application/README.md

[2] Chef Support for Automation & DevOps | Chef

On Mon, Jun 20, 2011 at 11:35 PM, Ken Mazaika <kmazaika@gmail.com (mailto:kmazaika@gmail.com)> wrote:
could you use something like capistrano for java?

On Mon, Jun 20, 2011 at 11:32 PM, Edward Sargisson <esarge@pobox.com (mailto:esarge@pobox.com)> wrote:
I need to do the same thing but haven't written it yet. Here's my plan

  • hopefully others can critique.

Firstly, you don't want to stop tomcat. Chef runs every 20 minutes or
so (or whenever you set it for) so it would stop your server every 20
minutes. Instead, you should work out if the file on your file server
has changed and then do the update. In my case, my build artifacts
have a build id. I plan to store the desired build id in a data bag *.
The deployed data bag goes into the node data. Then, on the chef run
it can compare and then run the update if required.

When you do the update you don't need to stop tomcat. Instead you
download the WAR to a temp directory then go to the webapps dir and
delete the directory for your webapp as well as the old WAR. Then you
copy the WAR in. (You can't download directly because then Tomcat
un-jars it before it's downloaded). Tomcat then un-jars it and starts
it up for you.

Cheers,
Edward

  • Amusingly, I forgot the name for data bag and my mind came up with
    drop bag. Once a trail runner, always a trail runner... :slight_smile:

On Mon, Jun 20, 2011 at 8:25 PM, <mdrobnak@ringleaderdigital.com (mailto:mdrobnak@ringleaderdigital.com)> wrote:

Hi everyone,
I'm fairly new to Chef. I downloaded and deployed the tomcat cookbook to a
node, and now I'm trying to add a recipe? or another cookbook, I'm not sure
really...to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the webapps
directory, and scp a file to the right spot..then start tomcat.

I looked briefly at the deploy resource, but that's from a version control
system...we don't keep builds in version control, only the source..the binary
builds are on a server, so I don't think that's what I want.

If anyone can point me in the right direction to get this going, that would be
greatly appreciated.

Thanks.

-Matt

Seth,

Thanks for the response.

I did figure out the data bag item issue shortly after...at which point I tried to create a node and manually specify fqdn and ip address, since it's SQL Server, production, and not ready to install chef on quite yet. :wink:

At that point, when I tried updating the client definition...I killed my server. The node list never returned. It could be I tried editing it in the Web UI between exporting the client as json and re-importing it...

So I learned a lesson: Don't mess with nodes manually, LOL. What should I do in this situation? Is installing the Chef client the only way around it, or should I modify the recipe to take an override from json?

I'm going to look at the mods made by Haselwanter Edmund to see if that gets me what I need.

-Matt

-----Original Message-----
From: Seth Chisamore [mailto:schisamo@opscode.com]
Sent: Thursday, June 23, 2011 10:59 AM
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: Re: Re: Re: Deploying .war files?

Matt,
The context.xml should have been created as "/srv/spark_server/shared/AppName.xml" [0], but that will only happen if a database master is found in the search [1]. This file is then symlinked over [2] into the tomcat context dir. It appears you are missing the 'database_master_role' value in your data bag item, this would cause the search to return no results.

Right now the application::java_webapp recipe only supports deploying wars into the root of the container. Mostly because in our initial customer use cases they were deploying single apps into smaller horizontally scaled app servers. Deploying into the root context makes automating the configuration of the load balancing layer much easier.

Seth

--
Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo

[0] https://github.com/opscode/cookbooks/blob/master/application/recipes/java_webapp.rb#L87
[1] https://github.com/opscode/cookbooks/blob/master/application/recipes/java_webapp.rb#L78
[2] https://github.com/opscode/cookbooks/blob/master/application/recipes/tomcat.rb#L31

On Wednesday, June 22, 2011 at 2:11 PM, Matthew Drobnak wrote:

Ok, so I did the following:

Created a role called spark_server:

{
"name": "spark_server",
"default_attributes": {
},
"json_class": "Chef::Role",
"env_run_lists": {
},
"run_list": [
"recipe[application]"
],
"description": "Spark Tomcat Server",
"chef_type": "role",
"override_attributes": {
}
}

Created data bag apps:

{
"group": "nogroup",
"server_roles": [
"spark_server"
],
"databases": {
"_default": {
"max_active": "100",
"port": "1433",
"username": "user",
"adapter": "sqlserver",
"max_idle": "30",
"database": "appname",
"driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"max_wait": "10000",
"password": "awesome_password"
},
"dev": {
"max_active": "100",
"port": "1433",
"username": "user",
"adapter": "sqlserver",
"max_idle": "30",
"database": "appname",
"driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"max_wait": "10000",
"password": "apppass"
}
},
"id": "AppName",
"mysql_repl_password": {
"_default": "mysql_repl"
},
"type": {
"spark_server": [
"java_webapp",
"tomcat"
]
},
"war": {
"_default": {
"checksum": "06880edebbf24c4000da4d45d26aa97ddc2a6ad1ae3e4365c755fdb5a1ad481a",
"source": "http://redacted/spark_server.war"
}
},
"mysql_root_password": {
"_default": "mysql_root"
},
"mysql_debian_password": {
"_default": "mysql_debian"
},
"deploy_to": "/srv/spark_server",
"owner": "nobody"
}

These are the cookbooks I have installed:

apache2 0.99.4
application 0.99.11
apt 1.1.2
build-essential 1.0.0
chef-client 0.99.5
gunicorn 1.0.0
java 1.1.0
jpackage 0.10.0
mysql 1.0.6
openssl 1.0.0
passenger_apache2 0.99.0
php 1.0.0
python 1.0.2
runit 0.14.2
tomcat 0.10.3
unicorn 1.0.0
xml 1.0.0

So at this point:
I have a node, with Tomcat installed. But, I have /srv/spark_sever/releases/.war plus a shared/logs, shared/pids,shared/system directories which are empty. /etc/tomcat6/Catalina/localhost/ROOT.xml points to /srv/spark_server/shared/AppName.xml, which does not exist.
/var/lib/tomcat6/webapps is empty (ROOT was deleted by the java_webapp recipe…), so there’s nothing actually running.

So two things:
What happened to my context.xml file?
How can I deploy to a named context instead of the ROOT context?

Thanks.

-Matt

From: Matthew Drobnak [mailto:mdrobnak@ringleaderdigital.com]
Sent: Tuesday, June 21, 2011 7:45 AM
To: chef@lists.opscode.com (mailto:chef@lists.opscode.com)
Subject: [chef] Re: Re: Re: Re: Deploying .war files?

I appreciate everyone's input so far.

Seth, I totally missed the application cookbook. I'll look into that and hopefully can get at least 1 piece running with Chef!

I love the premise, but all of the configuration management systems seem to have a bit of a steep climb before it becomes easy and powerful. :slight_smile:

Thanks again.

-Matt

On Jun 21, 2011, at 12:10 AM, Seth Chisamore wrote:

The java_webapp recipe in the application cookbook [0][1] was created to accomplish just this task!

The Java Quick Start [1] has a full working example of using this recipe to deploy a Java webapp, including setting up an environment specific context.xml with database connection information.

Seth

--
Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo

[0] http://community.opscode.com/cookbooks/application

[1] https://github.com/opscode/cookbooks/blob/master/application/README.md

[2] Chef Support for Automation & DevOps | Chef

On Mon, Jun 20, 2011 at 11:35 PM, Ken Mazaika <kmazaika@gmail.com (mailto:kmazaika@gmail.com)> wrote:
could you use something like capistrano for java?

On Mon, Jun 20, 2011 at 11:32 PM, Edward Sargisson <esarge@pobox.com (mailto:esarge@pobox.com)> wrote:
I need to do the same thing but haven't written it yet. Here's my plan

  • hopefully others can critique.

Firstly, you don't want to stop tomcat. Chef runs every 20 minutes or
so (or whenever you set it for) so it would stop your server every 20
minutes. Instead, you should work out if the file on your file server
has changed and then do the update. In my case, my build artifacts
have a build id. I plan to store the desired build id in a data bag *.
The deployed data bag goes into the node data. Then, on the chef run
it can compare and then run the update if required.

When you do the update you don't need to stop tomcat. Instead you
download the WAR to a temp directory then go to the webapps dir and
delete the directory for your webapp as well as the old WAR. Then you
copy the WAR in. (You can't download directly because then Tomcat
un-jars it before it's downloaded). Tomcat then un-jars it and starts
it up for you.

Cheers,
Edward

  • Amusingly, I forgot the name for data bag and my mind came up with
    drop bag. Once a trail runner, always a trail runner... :slight_smile:

On Mon, Jun 20, 2011 at 8:25 PM, <mdrobnak@ringleaderdigital.com (mailto:mdrobnak@ringleaderdigital.com)> wrote:

Hi everyone,
I'm fairly new to Chef. I downloaded and deployed the tomcat cookbook to a
node, and now I'm trying to add a recipe? or another cookbook, I'm not sure
really...to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the webapps
directory, and scp a file to the right spot..then start tomcat.

I looked briefly at the deploy resource, but that's from a version control
system...we don't keep builds in version control, only the source..the binary
builds are on a server, so I don't think that's what I want.

If anyone can point me in the right direction to get this going, that would be
greatly appreciated.

Thanks.

-Matt

Edmund,
I was looking over your enhancements/changes in the application and tomcat cookbooks...good stuff!

I def want to move all recipes in the application cookbook over to LWRPs (vs definitions as you mention). I would also really like to merge in your tomcat_context LWRP, this would make deploying multiple WARs into a single tomcat instance easier!
Seth

--
Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo

On Thursday, June 23, 2011 at 10:01 AM, Haselwanter Edmund wrote:

Hi,

I've uploaded a reworked application and tomcat cookbook

http://www.iteh.at/en/blog/2011/06/23/deployment-of-java-web-applications-with-chef-from-opscode/
https://github.com/iteh/vagrant-demos/tree/master/vagrant-java-application-reworked

which allows for something like this:

load a json or do a search like in the application cookbook

https://github.com/iteh/vagrant-demos/blob/master/vagrant-java-application-reworked/databags/apps/java_app.json

app = JSON.parse(File.open( File.join( File.dirname(FILE), \ "../databags/my_webapp.json")).read)

node.run_state[:current_app] = app

application_java_webapp “my_webapp”
application_tomcat “my_webapp_tomcat”

node.run_state.delete(:current_app)

it uses a tomcat_context LWRP with shasum checking

tomcat_context app['path'] do
config "#{app['deploy_to']}/shared/#{app['id']}.xml"
checksum app['war'][node.app_environment]['checksum']
admin node["tomcat"]["admin"]
password node["tomcat"]["password"]
action [:update,:start]
end

might need some tuning and cleanup

i think the definition should move to a LWRP too

cu edi

On 22.06.2011, at 20:11, Matthew Drobnak wrote:

Ok, so I did the following:

Created a role called spark_server:

{
"name": "spark_server",
"default_attributes": {
},
"json_class": "Chef::Role",
"env_run_lists": {
},
"run_list": [
"recipe[application]"
],
"description": "Spark Tomcat Server",
"chef_type": "role",
"override_attributes": {
}
}

Created data bag apps:

{
"group": "nogroup",
"server_roles": [
"spark_server"
],
"databases": {
"_default": {
"max_active": "100",
"port": "1433",
"username": "user",
"adapter": "sqlserver",
"max_idle": "30",
"database": "appname",
"driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"max_wait": "10000",
"password": "awesome_password"
},
"dev": {
"max_active": "100",
"port": "1433",
"username": "user",
"adapter": "sqlserver",
"max_idle": "30",
"database": "appname",
"driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"max_wait": "10000",
"password": "apppass"
}
},
"id": "AppName",
"mysql_repl_password": {
"_default": "mysql_repl"
},
"type": {
"spark_server": [
"java_webapp",
"tomcat"
]
},
"war": {
"_default": {
"checksum": "06880edebbf24c4000da4d45d26aa97ddc2a6ad1ae3e4365c755fdb5a1ad481a",
"source": "http://redacted/spark_server.war"
}
},
"mysql_root_password": {
"_default": "mysql_root"
},
"mysql_debian_password": {
"_default": "mysql_debian"
},
"deploy_to": "/srv/spark_server",
"owner": "nobody"
}

These are the cookbooks I have installed:

apache2 0.99.4
application 0.99.11
apt 1.1.2
build-essential 1.0.0
chef-client 0.99.5
gunicorn 1.0.0
java 1.1.0
jpackage 0.10.0
mysql 1.0.6
openssl 1.0.0
passenger_apache2 0.99.0
php 1.0.0
python 1.0.2
runit 0.14.2
tomcat 0.10.3
unicorn 1.0.0
xml 1.0.0

So at this point:
I have a node, with Tomcat installed. But, I have /srv/spark_sever/releases/.war plus a shared/logs, shared/pids,shared/system directories which are empty. /etc/tomcat6/Catalina/localhost/ROOT.xml points to /srv/spark_server/shared/AppName.xml, which does not exist.
/var/lib/tomcat6/webapps is empty (ROOT was deleted by the java_webapp recipe…), so there’s nothing actually running.

So two things:
What happened to my context.xml file?
How can I deploy to a named context instead of the ROOT context?

Thanks.

-Matt

From: Matthew Drobnak [mailto:mdrobnak@ringleaderdigital.com]
Sent: Tuesday, June 21, 2011 7:45 AM
To: chef@lists.opscode.com (mailto:chef@lists.opscode.com)
Subject: [chef] Re: Re: Re: Re: Deploying .war files?

I appreciate everyone's input so far.

Seth, I totally missed the application cookbook. I'll look into that and hopefully can get at least 1 piece running with Chef!

I love the premise, but all of the configuration management systems seem to have a bit of a steep climb before it becomes easy and powerful. :slight_smile:

Thanks again.

-Matt

On Jun 21, 2011, at 12:10 AM, Seth Chisamore wrote:

The java_webapp recipe in the application cookbook [0][1] was created to accomplish just this task!

The Java Quick Start [1] has a full working example of using this recipe to deploy a Java webapp, including setting up an environment specific context.xml with database connection information.

Seth

--
Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo

[0] http://community.opscode.com/cookbooks/application

[1] https://github.com/opscode/cookbooks/blob/master/application/README.md

[2] Chef Support for Automation & DevOps | Chef

On Mon, Jun 20, 2011 at 11:35 PM, Ken Mazaika <kmazaika@gmail.com (mailto:kmazaika@gmail.com)> wrote:
could you use something like capistrano for java?

On Mon, Jun 20, 2011 at 11:32 PM, Edward Sargisson <esarge@pobox.com (mailto:esarge@pobox.com)> wrote:
I need to do the same thing but haven't written it yet. Here's my plan

  • hopefully others can critique.

Firstly, you don't want to stop tomcat. Chef runs every 20 minutes or
so (or whenever you set it for) so it would stop your server every 20
minutes. Instead, you should work out if the file on your file server
has changed and then do the update. In my case, my build artifacts
have a build id. I plan to store the desired build id in a data bag *.
The deployed data bag goes into the node data. Then, on the chef run
it can compare and then run the update if required.

When you do the update you don't need to stop tomcat. Instead you
download the WAR to a temp directory then go to the webapps dir and
delete the directory for your webapp as well as the old WAR. Then you
copy the WAR in. (You can't download directly because then Tomcat
un-jars it before it's downloaded). Tomcat then un-jars it and starts
it up for you.

Cheers,
Edward

  • Amusingly, I forgot the name for data bag and my mind came up with
    drop bag. Once a trail runner, always a trail runner... :slight_smile:

On Mon, Jun 20, 2011 at 8:25 PM, <mdrobnak@ringleaderdigital.com (mailto:mdrobnak@ringleaderdigital.com)> wrote:

Hi everyone,
I'm fairly new to Chef. I downloaded and deployed the tomcat cookbook to a
node, and now I'm trying to add a recipe? or another cookbook, I'm not sure
really...to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the webapps
directory, and scp a file to the right spot..then start tomcat.

I looked briefly at the deploy resource, but that's from a version control
system...we don't keep builds in version control, only the source..the binary
builds are on a server, so I don't think that's what I want.

If anyone can point me in the right direction to get this going, that would be
greatly appreciated.

Thanks.

-Matt

--
DI Edmund Haselwanter, edmund@haselwanter.com (mailto:edmund@haselwanter.com), http://edmund.haselwanter.com/
http://www.iteh.at | Facebook | http://at.linkedin.com/in/haselwanteredmund

On 23.06.2011, at 17:04, Matthew Drobnak wrote:

Seth,

Thanks for the response.

I did figure out the data bag item issue shortly after...at which point I tried to create a node and manually specify fqdn and ip address, since it's SQL Server, production, and not ready to install chef on quite yet. :wink:

At that point, when I tried updating the client definition...I killed my server. The node list never returned. It could be I tried editing it in the Web UI between exporting the client as json and re-importing it...

So I learned a lesson: Don't mess with nodes manually, LOL. What should I do in this situation? Is installing the Chef client the only way around it, or should I modify the recipe to take an override from json?

I'm going to look at the mods made by Haselwanter Edmund to see if that gets me what I need.

You can set the context in my improved version. Try the vagrant box example and play with it. You could create another app by adding a role and a databag item (just copy and modify the files)

cu edi

--
DI Edmund Haselwanter, edmund@haselwanter.com, http://edmund.haselwanter.com/
http://www.iteh.at | Facebook | http://at.linkedin.com/in/haselwanteredmund

On 23.06.2011, at 17:21, Seth Chisamore wrote:

Edmund,
I was looking over your enhancements/changes in the application and tomcat cookbooks...good stuff!

Thx! put some work into it :wink:

I def want to move all recipes in the application cookbook over to LWRPs (vs definitions as you mention). I would also really like to merge in your tomcat_context LWRP, this would make deploying multiple WARs into a single tomcat instance easier!

it has a proper license to do so :wink:

For the LWRP thing. I was missing this http://tickets.opscode.com/browse/CHEF-1946
Is there a proposed release date for 0.10.2 ? chef | RubyGems.org | your community gem host is still 0.10.0

Seth

--
Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo

On Thursday, June 23, 2011 at 10:01 AM, Haselwanter Edmund wrote:

Hi,

I've uploaded a reworked application and tomcat cookbook

http://www.iteh.at/en/blog/2011/06/23/deployment-of-java-web-applications-with-chef-from-opscode/
https://github.com/iteh/vagrant-demos/tree/master/vagrant-java-application-reworked

which allows for something like this:

load a json or do a search like in the application cookbook

https://github.com/iteh/vagrant-demos/blob/master/vagrant-java-application-reworked/databags/apps/java_app.json

app = JSON.parse(File.open( File.join( File.dirname(FILE), \ "../databags/my_webapp.json")).read)

node.run_state[:current_app] = app

application_java_webapp “my_webapp”
application_tomcat “my_webapp_tomcat”

node.run_state.delete(:current_app)

it uses a tomcat_context LWRP with shasum checking

tomcat_context app['path'] do
config "#{app['deploy_to']}/shared/#{app['id']}.xml"
checksum app['war'][node.app_environment]['checksum']
admin node["tomcat"]["admin"]
password node["tomcat"]["password"]
action [:update,:start]
end

might need some tuning and cleanup

i think the definition should move to a LWRP too

cu edi

On 22.06.2011, at 20:11, Matthew Drobnak wrote:

Ok, so I did the following:

Created a role called spark_server:

{
"name": "spark_server",
"default_attributes": {
},
"json_class": "Chef::Role",
"env_run_lists": {
},
"run_list": [
"recipe[application]"
],
"description": "Spark Tomcat Server",
"chef_type": "role",
"override_attributes": {
}
}

Created data bag apps:

{
"group": "nogroup",
"server_roles": [
"spark_server"
],
"databases": {
"_default": {
"max_active": "100",
"port": "1433",
"username": "user",
"adapter": "sqlserver",
"max_idle": "30",
"database": "appname",
"driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"max_wait": "10000",
"password": "awesome_password"
},
"dev": {
"max_active": "100",
"port": "1433",
"username": "user",
"adapter": "sqlserver",
"max_idle": "30",
"database": "appname",
"driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"max_wait": "10000",
"password": "apppass"
}
},
"id": "AppName",
"mysql_repl_password": {
"_default": "mysql_repl"
},
"type": {
"spark_server": [
"java_webapp",
"tomcat"
]
},
"war": {
"_default": {
"checksum": "06880edebbf24c4000da4d45d26aa97ddc2a6ad1ae3e4365c755fdb5a1ad481a",
"source": "http://redacted/spark_server.war"
}
},
"mysql_root_password": {
"_default": "mysql_root"
},
"mysql_debian_password": {
"_default": "mysql_debian"
},
"deploy_to": "/srv/spark_server",
"owner": "nobody"
}

These are the cookbooks I have installed:

apache2 0.99.4
application 0.99.11
apt 1.1.2
build-essential 1.0.0
chef-client 0.99.5
gunicorn 1.0.0
java 1.1.0
jpackage 0.10.0
mysql 1.0.6
openssl 1.0.0
passenger_apache2 0.99.0
php 1.0.0
python 1.0.2
runit 0.14.2
tomcat 0.10.3
unicorn 1.0.0
xml 1.0.0

So at this point:
I have a node, with Tomcat installed. But, I have /srv/spark_sever/releases/.war plus a shared/logs, shared/pids,shared/system directories which are empty. /etc/tomcat6/Catalina/localhost/ROOT.xml points to /srv/spark_server/shared/AppName.xml, which does not exist.
/var/lib/tomcat6/webapps is empty (ROOT was deleted by the java_webapp recipe…), so there’s nothing actually running.

So two things:
What happened to my context.xml file?
How can I deploy to a named context instead of the ROOT context?

Thanks.

-Matt

From: Matthew Drobnak [mailto:mdrobnak@ringleaderdigital.com]
Sent: Tuesday, June 21, 2011 7:45 AM
To: chef@lists.opscode.com (mailto:chef@lists.opscode.com)
Subject: [chef] Re: Re: Re: Re: Deploying .war files?

I appreciate everyone's input so far.

Seth, I totally missed the application cookbook. I'll look into that and hopefully can get at least 1 piece running with Chef!

I love the premise, but all of the configuration management systems seem to have a bit of a steep climb before it becomes easy and powerful. :slight_smile:

Thanks again.

-Matt

On Jun 21, 2011, at 12:10 AM, Seth Chisamore wrote:

The java_webapp recipe in the application cookbook [0][1] was created to accomplish just this task!

The Java Quick Start [1] has a full working example of using this recipe to deploy a Java webapp, including setting up an environment specific context.xml with database connection information.

Seth

--
Opscode, Inc.
Seth Chisamore, Senior Technical Evangelist
IRC, Skype, Twitter, Github: schisamo

[0] http://community.opscode.com/cookbooks/application

[1] https://github.com/opscode/cookbooks/blob/master/application/README.md

[2] Chef Support for Automation & DevOps | Chef

On Mon, Jun 20, 2011 at 11:35 PM, Ken Mazaika <kmazaika@gmail.com (mailto:kmazaika@gmail.com)> wrote:
could you use something like capistrano for java?

On Mon, Jun 20, 2011 at 11:32 PM, Edward Sargisson <esarge@pobox.com (mailto:esarge@pobox.com)> wrote:
I need to do the same thing but haven't written it yet. Here's my plan

  • hopefully others can critique.

Firstly, you don't want to stop tomcat. Chef runs every 20 minutes or
so (or whenever you set it for) so it would stop your server every 20
minutes. Instead, you should work out if the file on your file server
has changed and then do the update. In my case, my build artifacts
have a build id. I plan to store the desired build id in a data bag *.
The deployed data bag goes into the node data. Then, on the chef run
it can compare and then run the update if required.

When you do the update you don't need to stop tomcat. Instead you
download the WAR to a temp directory then go to the webapps dir and
delete the directory for your webapp as well as the old WAR. Then you
copy the WAR in. (You can't download directly because then Tomcat
un-jars it before it's downloaded). Tomcat then un-jars it and starts
it up for you.

Cheers,
Edward

  • Amusingly, I forgot the name for data bag and my mind came up with
    drop bag. Once a trail runner, always a trail runner... :slight_smile:

On Mon, Jun 20, 2011 at 8:25 PM, <mdrobnak@ringleaderdigital.com (mailto:mdrobnak@ringleaderdigital.com)> wrote:

Hi everyone,
I'm fairly new to Chef. I downloaded and deployed the tomcat cookbook to a
node, and now I'm trying to add a recipe? or another cookbook, I'm not sure
really...to deploy our web app that should run on Tomcat.

I basically want the node to stop tomcat, delete everything in the webapps
directory, and scp a file to the right spot..then start tomcat.

I looked briefly at the deploy resource, but that's from a version control
system...we don't keep builds in version control, only the source..the binary
builds are on a server, so I don't think that's what I want.

If anyone can point me in the right direction to get this going, that would be
greatly appreciated.

Thanks.

-Matt

--
DI Edmund Haselwanter, edmund@haselwanter.com (mailto:edmund@haselwanter.com), http://edmund.haselwanter.com/
http://www.iteh.at | Facebook | http://at.linkedin.com/in/haselwanteredmund

--
DI Edmund Haselwanter, edmund@haselwanter.com, http://edmund.haselwanter.com/
http://www.iteh.at | Facebook | http://at.linkedin.com/in/haselwanteredmund

Edmund, I just got your version from git, and I'm going to try and merge your context changes in..

I'll let you know how it goes.

Thanks a lot.

-Matt

-----Original Message-----
From: Haselwanter Edmund [mailto:edmund@haselwanter.com]
Sent: Thursday, June 23, 2011 12:26 PM
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: RE: Re: Re: Re: Re: Deploying .war files?

On 23.06.2011, at 17:04, Matthew Drobnak wrote:

Seth,

Thanks for the response.

I did figure out the data bag item issue shortly after...at which point I tried to create a node and manually specify fqdn and ip address, since it's SQL Server, production, and not ready to install chef on quite yet. :wink:

At that point, when I tried updating the client definition...I killed my server. The node list never returned. It could be I tried editing it in the Web UI between exporting the client as json and re-importing it...

So I learned a lesson: Don't mess with nodes manually, LOL. What should I do in this situation? Is installing the Chef client the only way around it, or should I modify the recipe to take an override from json?

I'm going to look at the mods made by Haselwanter Edmund to see if that gets me what I need.

You can set the context in my improved version. Try the vagrant box example and play with it. You could create another app by adding a role and a databag item (just copy and modify the files)

cu edi

--
DI Edmund Haselwanter, edmund@haselwanter.com, http://edmund.haselwanter.com/
http://www.iteh.at | Facebook | http://at.linkedin.com/in/haselwanteredmund

I ended up not using the new version yet. I'm still understanding the complexities of things like LWRPs, so I tried just some simple modifications. Here's what I ended up with:

diff --git a/cookbooks/application/recipes/java_webapp.rb b/cookbooks/application/recipes/java_webapp.rb
index b008289..e9e7f92 100644
--- a/cookbooks/application/recipes/java_webapp.rb
+++ b/cookbooks/application/recipes/java_webapp.rb
@@ -80,12 +80,20 @@ if app["database_master_role"]
if rows.length == 1
dbm = rows[0]
end

  • if app["database_master_details"]
  •  dbm = app["database_master_details"][node.chef_environment]
    
  • end
    end

Assuming we have one...

if dbm
template "#{app['deploy_to']}/shared/#{app['id']}.xml" do

  •  source "context.xml.erb"
    
  •  if app["databases"][node.chef_environment]["adapter"] == "sqlserver"
    
  •     source "sqlserver.context.xml.erb"
    
  •  else
    
  •     source "context.xml.erb"
    
  •  end
    
  •  owner app["owner"]
     group app["group"]
     mode "644"
    

@@ -93,6 +101,7 @@ if app["database_master_role"]
:host => dbm['fqdn'],
:app => app['id'],
:database => app['databases'][node.chef_environment],

  •    :path => app['path'],
       :war => "#{app['deploy_to']}/releases/#{app['war'][node.chef_environment]['checksum']}.war"
     )
    
    end
    diff --git a/cookbooks/application/recipes/tomcat.rb b/cookbooks/application/recipes/tomcat.rb
    index f8a4d37..a7fe226 100644
    --- a/cookbooks/application/recipes/tomcat.rb
    +++ b/cookbooks/application/recipes/tomcat.rb
    @@ -23,17 +23,17 @@ include_recipe "tomcat"

remove ROOT application

TODO create a LWRP to enable/disable tomcat apps

-directory "#{node['tomcat']['webapp_dir']}/ROOT" do
+directory "#{node['tomcat']['webapp_dir']}#{app['path']}" do
recursive true
action :delete

  • not_if "test -L #{node['tomcat']['context_dir']}/ROOT.xml"
  • not_if "test -L #{node['tomcat']['context_dir']}/#{app['id']}.xml"
    end
    -link "#{node['tomcat']['context_dir']}/ROOT.xml" do
    +link "#{node['tomcat']['context_dir']}/#{app['id']}.xml" do
    to "#{app['deploy_to']}/shared/#{app['id']}.xml"
    notifies :restart, resources(:service => "tomcat")
    end

-if ::File.symlink?(::File.join(node['tomcat']['context_dir'], "ROOT.xml"))
+if ::File.symlink?(::File.join(node['tomcat']['context_dir'], "#{app['id']}.xml"))
d = resources(:remote_file => app['id'])
d.notifies :restart, resources(:service => "tomcat")
end
diff --git a/cookbooks/application/templates/default/context.xml.erb b/cookbooks/application/templates/default/context.xml.erb
index d6301af..0d94d5a 100644
--- a/cookbooks/application/templates/default/context.xml.erb
+++ b/cookbooks/application/templates/default/context.xml.erb
@@ -1,4 +1,4 @@
-<Context docBase="<%= @war %>" path="/"
+

diff --git a/data_bags/apps/spark_server.json b/data_bags/apps/spark_server.json
new file mode 100644
index 0000000..00df21c
--- /dev/null
+++ b/data_bags/apps/spark_server.json
@@ -0,0 +1,65 @@
+{

  • "id": "AppName",
  • "server_roles": [
  •  "spark_server"
    
  •  ],
    
  • "type": {
  •  "spark_server": [
    
  •    "java_webapp",
    
  •    "tomcat"
    
  •    ]
    
  • },
  • "path": [
  •  "/AppName"
    
  • ],
  • "database_master_role": [
  •  "spark_database_master"
    
  • ],
  • "database_master_details": {
  •  "_default": {
    
  •    "fqdn": "redacted.abc.local"
    
  •  }
    
  • },
  • "war": {
  •  "_default": {
    
  •    "source": "http://redacted/spark_server.war",
    
  •    "checksum": "06880edebbf24c4000da4d45d26aa97ddc2a6ad1ae3e4365c755fdb5a1ad481a"
    
  •  }
    
  • },
  • "databases": {
  •  "_default": {
    
  •    "max_active": "100",
    
  •    "max_idle": "30",
    
  •    "max_wait": "10000",
    
  •    "username": "redacted",
    
  •    "adapter": "sqlserver",
    
  •    "driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
    
  •    "port" : "3273",
    
  •    "password": "redacted",
    
  •    "database": "appname"
    
  •  },
    
  •  "dev": {
    
  •    "max_active": "100",
    
  •    "max_idle": "30",
    
  •    "max_wait": "10000",
    
  •    "username": "redacted",
    
  •    "adapter": "sqlserver",
    
  •    "driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
    
  •    "port" : "1433",
    
  •    "password": "redacted",
    
  •    "database": "appname"
    
  •  }
    
  • },
  • "mysql_root_password": {
  •  "_default": "mysql_root"
    
  • },
  • "mysql_debian_password": {
  •  "_default": "mysql_debian"
    
  • },
  • "mysql_repl_password": {
  •  "_default": "mysql_repl"
    
  • },
  • "deploy_to": "/srv/spark_server",
  • "owner": "nobody",
  • "group": "nogroup"
    +}
    diff --git a/roles/spark_server.rb b/roles/spark_server.rb
    new file mode 100644
    index 0000000..cdc3df9
    --- /dev/null
    +++ b/roles/spark_server.rb
    @@ -0,0 +1,12 @@
    +name "spark_server"
    +description "Spark Tomcat Server"
    +run_list(
  • "recipe[application]",
  • "recipe[spark_server]"
    +)

+default_attributes(

  • :tomcat => {
  • :java_options => "-Xms384M -Xmx1536M"
  • }
    +)

And then the spark_server recipe has this for default.rb:

cookbook_file "/etc/tomcat6/AppName.dtd" do
source "AppName.dtd"
mode "0644"
notifies :restart, resources(:service => "tomcat")
end

cookbook_file "/etc/tomcat6/appname.properties" do
source "appname.properties"
mode "0644"
notifies :restart, resources(:service => "tomcat")
end

cookbook_file "/etc/tomcat6/custom-reports-csv.ini" do
source "custom-reports-csv.ini"
mode "0644"
notifies :restart, resources(:service => "tomcat")
end

cookbook_file "/etc/tomcat6/custom-reports-html.ini" do
source "custom-reports-html.ini"
mode "0644"
notifies :restart, resources(:service => "tomcat")
end

cookbook_file "/etc/tomcat6/div-superuser-map.ini" do
source "div-superuser-map.ini"
mode "0644"
notifies :restart, resources(:service => "tomcat")
end

cookbook_file "/etc/tomcat6/div-user-map.ini" do
source "div-user-map.ini"
mode "0644"
notifies :restart, resources(:service => "tomcat")
end

cookbook_file "/etc/tomcat6/load-balancer.properties" do
source "load-balancer.properties"
mode "0644"
notifies :restart, resources(:service => "tomcat")
end

cookbook_file "/etc/tomcat6/log4j.dtd" do
source "log4j.dtd"
mode "0644"
notifies :restart, resources(:service => "tomcat")
end

cookbook_file "/etc/tomcat6/log4j.xml" do
source "log4j.xml"
mode "0644"
notifies :restart, resources(:service => "tomcat")
end

Obviously the cookbook_file for appname.properties will be changing to a template based on my other email..

Items to do:
Fix the SQLServer context hack thing. I think I can use some ruby in the template to say if drivername = sqlserver put this line, otherwise the default, right?
Get my template & script working for appname.properties

After that, I think I've got my first piece of infrastructure Chef'd!

Thanks for everyone's help so far.

-Matt

-----Original Message-----
From: Matthew Drobnak [mailto:mdrobnak@ringleaderdigital.com]
Sent: Thursday, June 23, 2011 12:39 PM
To: chef@lists.opscode.com
Subject: [chef] RE: Re: RE: Re: RE: Re: Re: Re: Re: Deploying .war files?

Edmund, I just got your version from git, and I'm going to try and merge your context changes in..

I'll let you know how it goes.

Thanks a lot.

-Matt

-----Original Message-----
From: Haselwanter Edmund [mailto:edmund@haselwanter.com]
Sent: Thursday, June 23, 2011 12:26 PM
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: RE: Re: Re: Re: Re: Deploying .war files?

On 23.06.2011, at 17:04, Matthew Drobnak wrote:

Seth,

Thanks for the response.

I did figure out the data bag item issue shortly after...at which point I tried to create a node and manually specify fqdn and ip address, since it's SQL Server, production, and not ready to install chef on quite yet. :wink:

At that point, when I tried updating the client definition...I killed my server. The node list never returned. It could be I tried editing it in the Web UI between exporting the client as json and re-importing it...

So I learned a lesson: Don't mess with nodes manually, LOL. What should I do in this situation? Is installing the Chef client the only way around it, or should I modify the recipe to take an override from json?

I'm going to look at the mods made by Haselwanter Edmund to see if that gets me what I need.

You can set the context in my improved version. Try the vagrant box example and play with it. You could create another app by adding a role and a databag item (just copy and modify the files)

cu edi

--
DI Edmund Haselwanter, edmund@haselwanter.com, http://edmund.haselwanter.com/
http://www.iteh.at | Facebook | http://at.linkedin.com/in/haselwanteredmund