keskiviikko 15. toukokuuta 2013

Final task, my own module. Puppet - Tomcat module

Our final task was to create our own module for puppet. I decided to do something which is useful for myself. Because we did a school project with tomcat I wanted to install tomcat with my module. First we download the tomcat tar file, then extract it, remove the tar, change configuration file from template and finally start the service.

I am using virtualbox on 64bit windows 7 with 12GB ram + AMD 1055t 6 core processor. Linux used for testing, Xubuntu 12.10

I did the work in small pieces. First I created puppet test module which placed simple txt file in temp folder. After that I did downloading, then extracting, removing, template and startup.

Tomcat obviously need Java. So I started by creating openjdk module. As you can see from my modules tree, there are three modules. One for testing, one for java and one for tomcat.


The java module is very simple. Its only task is to install java developement kit. The code goes like this:

 class java {
package { 'openjdk-7-jdk':
 ensure => installed,
 }
}

And to run it:
$ sudo puppet apply --modulepath modules/ -e 'class {"java":}'


Now we have jdk installed and tomcat is ready to be deployed. Of course I had to download tomcat beforehand to get the template file from conf folder which has the tomcat-users.xml file. My tomcat init.pp goes like this:

class tomcat(
$source = 'http://mirrors.axint.net/apache/tomcat/tomcat-7/v7.0.40/bin/apache-tomcat-7.0.40.tar.gz',
$package = 'apache-tomcat-7.0.40.tar.gz',
)

{
exec { 'download-apache-tomcat-7.0.40.tar.gz':
command => "wget $source",
cwd => "/home/$id",
path => '/usr/bin/',
}

exec {'extract-apache-tomcat-7.0.40.tar.gz':
command => "tar -xvf $package", 
cwd => "/home/$id",
path => '/bin/',
require => Exec['download-apache-tomcat-7.0.40.tar.gz'],
}

exec {'remove package':
command => "rm $package", 
cwd => "/home/$id",
path => '/bin/',
require => Exec['extract-apache-tomcat-7.0.40.tar.gz']
}

## TODO change variable for shnigi

file {'/home/shnigi/apache-tomcat-7.0.40/conf/tomcat-users.xml':
ensure => file,
content => template ('tomcat/tomcat-users.erb'),
require => Exec['extract-apache-tomcat-7.0.40.tar.gz'],
}

## TODO fix startup

exec {'start service':
command => "sh startup.sh",
cwd => "/home/shnigi/apache-tomcat-7.0.40/bin/",
path => '/bin/',
require => File['/home/shnigi/apache-tomcat-7.0.40/conf/tomcat-users.xml']
}

}

$ puppet apply --modulepath modules/ -e 'class {"tomcat":}'
 

The problem is that the startup.sh needs probably sudo command and I don't know how to bypass that. Everything else is working correctly, because if I run the startup manually tomcat manager gui shows correctly.

$ cd /home/shnigi/apache-tomcat-7.0.40/conf
$ sudo sh startup.sh

Now surf to http://localhost:8080 and see the tomcat manager-gui =)



Sources: 

Ei kommentteja:

Lähetä kommentti