lunes, abril 01, 2013

Installing TomEE from Puppet



Apache TomEE is an all-Apache stack aimed at Java EE 6 Web Profile certification where Tomcat is top dog. It is the conjunction of Tomcat + Java EE

Puppet is a tool designed to manage the configuration of our systems declaratively. We only have to describe system resources and their state. This description is stored in the core-files of Puppet, which are called Puppet manifests.

In current post we are going to see how to define TomEE as Puppet resource, so it can be installed automatically in all computers that are managed by Puppet. I am using Ubuntu 12.04, but of course this could be adapted to your system.


Because TomEE is written in Java, we obviously need to ensure that a JDK is present in our system, for our example we are going to use OpenJDK 1.6. The way to install a package to our system is using Package resource, which uses underlying package manager to find, download and install it.

Let's create an init.pp manifest file and the first thing we are going to do is create an exec task which updates the package manager with a list of last packages available.


Then we can define a class that is in charge of installing the OpenJDK. A class in Puppet can be understood as a collection of resources that will be seen by Puppet as a unit.


It is pretty intuitive I guess, first of all we are ensuring that openjdk-6-jdk package is already present in system. If it is not installed, then Exec["update-package-list"] resource is executed, and finally the package manager installs OpenJDK into the system. 

After executing this part we can run java -version or javac -version without any problem, OpenJDK is there.

Next step is installing TomEE. Probably TomEE package is not in your distribution package repository in software package format (for example in case of Debian .deb). For this reason we need a different approach to the one followed by OpenJDK. We are going to download tar.gz file from TomEE site and uncompress it to an installation directory.


As with OpenJDK we are creating a class called tomee. First we are creating the directory where TomEE will be installed (tar command requires that destination directory should be already created). 

Then we are downloading TomEE from Apache site using wget command, to finally uncompressing it to already created directory.

Note the use of ->. Puppet does not guarantee the order of execution of defined resources, so you cannot infer "a priori" if TomEE will be downloaded first and then installed or vice versa. To define an order we are using -> operator which sets a priority between resources.

Now we have got Apache TomEE installed on computer, but obviously is not started and stopped automatically, you must execute /opt/tomee-1.5.1/bin/startup.sh to have TomEE available. Let's change this by using service resource. As its name suggests it registers as service an installed server. So inside tomee class define next service resource:


Keep an eye in two points of previous declaration, the first one is the provider/start/stop declarations, provider is set to init, which means we want to use the standard init-style service management, but for example you could use launchd (case of Mac OS X), upstart, windows (for Windows machines), ... see [http://docs.puppetlabs.com/references/latest/type.html#service] for more information. And because TomEE is not implemented as a Linux service by default (basically because has not been installed from a native package like .deb), we need to specify which command should be executed to start and stop TomEE

The second point is that service resource requires to have TomEE unpacked and OpenJDK installed, for this reason require attribute contains two declarations.

See full script here.

Final notes about example:
  • In Puppet, creates attribute inside exec task, is used to know if the resource should be executed or not (case that the file exists, exec will not be executed). In our case we are downloading TomEE in tmp directory. Most OS removes periodically this directory so it is a bad location for downloading it, but for this tutorial it works perfectly because I could re-execute the script every time as a new execution.
  • For simplifications we have add all content inside a single file, in your enterprise I suggest creating a TomEE module so you could share across all your projects.
  • TomEE version should be set as a variable/parameter/hiera so same class can be reused when new version of TomEE is released. 

We keep learning,
Alex.

Ven al desfile de sirenas, de cuerpos bien cebados, sube al séptimo cielo (Ellos Las Prefieren Gordas - Orquesta Mondragon)

Music:  http://www.youtube.com/watch?v=_Z_LTvQcw38

3 comentarios:

Libin Huang dijo...

20160509libinralph lauren outlet
pandora outlet
tiffany outlet
nike huarache
ralph lauren polo
asics
camisetas futbol baratas
basketball shoes,basketball sneakers,lebron james shoes,sports shoes,kobe bryant shoes,kobe sneakers,nike basketball shoes,running shoes,mens sport shoes,nike shoes
cheap nfl jersey
fitflops clearance
timberland boots
michael kors outlet
louis vuitton pas cher
rolex watches for sale
tory burch outlet
adidas wings
coach outlet
michael kors uk
juicy couture outlet
fitflops uk
ralph lauren polo shirts
longchamp solde
tory burch outlet
cazal outlet
toms shoes
ralph lauren outlet
true religion outlet
cazal sunglasses
swarovski outlet
longchamp handbags
michael kors outlet sale
oakley sunglasses
cheap football shirts
longchamp pas cher
adidas trainers

chenlina dijo...

chenlina20160716
coach outlet store online
jordan shoes
christian louboutin shoes
michael kors outlet
cheap jerseys
air jordan 13
cheap jordan shoes
jordan 13
coach outlet clearance
authentic louis vuitton handbags
louis vuitton outlet stores
louis vuitton outlet
nike roshe run
asics outlet
jordan 4 toro
louis vuitton
true religion
ray ban sunglasses outlet
coach outlet store online clearances
nike air max 90
nike outlet store
michael kors handbags
coach outlet
christian louboutin outlet
tory burch outlet online
oakley sunglasses
ralph lauren outlet
gucci outlet
nike air max
kobe 9
louis vuitton handbags
polo ralph lauren outlet
louboutin pas cher
ray ban sunglasses
louis vuitton handbags
true religion jeans
air jordan 8
asics shoes
louis vuitton outlet
nike sb shoes
as

Gege Dai dijo...

nike air max 2015
fitflops clearance
true religion outlet
rolex watches
christian louboutin shoes
vans shoes
mulberry bags
nike uk store
iphone case uk
iphone case
ray ban sunglasses
giuseppe zanotti shoes
converse shoes sale
puma outlet
ysl outlet
prada outlet online
louboutin pas cher
ralph lauren uk
louis vuitton bags cheap
jordan 13
lululemon outlet
christian louboutin outlet
michael kors outlet
michael kors outlet online
louis vuitton outlet
adidas uk store
prada outlet
fitflop sale
hollister
hollister
mcm outlet
ralph lauren uk
tory burch outlet
new balance shoes
cheap oakley sunglasses
czq20160722

Donate If You Can and Find Post Useful