Puppet manifests to automate Tomcat Deployment


To automate tomcat deployments using Puppet , we have to write manifests for it. Our tomcat deployments uses the following steps

1. unlink war from existing war
2. link to latest war
3. restart application

/data/dist/app is the location for us which contains all the war files.Once a new war file is available we copy the war file to this location and update the link from current war to the latest war. The location which contains the current working war is /data/tomcat/app/deploy/ .

$ls  -lrt  /data/tomcat/jacplus/deploy/
drwxrwsr-x  5 tomcat  admin 4096 May 22  2012 manager
drwxrwsr-x  4 tomcat  admin 4096 Oct 23  2012 whoami
lrwxrwxrwx  1 tomcat  admin    7    Dec 12  2012 ROOT -> app
lrwxrwxrwx  1 user      admin   35   Jun  1    23:11 app.war -> /data/dist/app/app-4.41.war

So, during deployment we unlink current war from /data/tomcat/jacplus/deploy/ and point it to latest war in /data/dist/app/ directory.

e.g
          $ cd /data/tomcat/jacplus/deploy/
          $ unlink app.war
          $ ln  -s  /data/dist/app/app-.war   app.war
          $ /data/bin/tomcat_app.sh restart


So, based on the above deployment rules, our manifests will be as follows:

 node default{
 }

  $version="5.3"

node  'node-003.example.com','node-002.example.com' {

    file{"app.war":
        path   => "/data/dist/app/app-$version.war",
        ensure => present,
        group  =>  'admin',
        owner  => 'tomcat',
        source => "puppet:///modules/repo/app-$version.war",
     }

   # link latest war and restart app
   file{"link":
      path=>"/data/tomcat/app/deploy/app.war",
      ensure=>link,
      target=>"/data/dist/app/app-$version.war",
       }~>exec{"restart":
                    command=>"/apps/bin/tomcat_app.sh restart",
                    user =>'tomcat',
                    subscribe=>File[link],
                    refreshonly => true,
                 }

        }




   

Comments

Popular Posts