Recently one of my colleague called me up with a problem statement where he was finding difficulty configuring JBOSS through puppet. I tried to help him through one of VMware Workstation box on my Dell Inspiron.
I tried to google but couldn’t find the working example. I tried my hands of my own and YES…I did it finally.
I am sharing the overall idea how to deploy and configure JBOSS through Puppet.
Let’s say you have the following steps which you manually perform for installing JBOSS on your Linux machine:
1.$ su -c “yum install java-1.6.0-openjdk-devel”
2.$ java –version 3.wget http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final.zip 4.$ unzip jboss-as-7.1.1.Final.zip -d /usr/share 5.$ adduser jboss 6.$ chown -fR jboss.jboss /usr/share/jboss-as-7.1.1.Final/ 7.$ su jboss 8.$ cd /usr/share/jboss-as-7.1.1.Final/bin/ 9.$ ./add-user.sh You should see the following message on the console after executing the command: What type of user do you wish to add? a) Management User (mgmt-users.properties) b) Application User (application-users.properties) (a): a We select “a”, next you should see the following message: Enter the details of the new user to add. Realm (ManagementRealm) : Username : jboss Password : Re-enter Password : * hit enter for Realm to use default, then provide a username and password We select the default value for the Realm (ManagementRealm), by hitting enter, and select “jboss” as our username. By default, we supply “jb0ss” as our password, of course, you can provide any password you prefer here. Step 4: Start the JBoss AS 7 server: Once the appropriate JBoss users are created, we are now ready to start our new JBoss AS 7 server. With JBoss AS 7, a new standalone and domain model has been introduced. In this tutorial, we focus on starting up a standalone server. The domain server will be part of a future tutorial. Startup a JBoss 7, standalone instance: A standalone instance of JBoss 7 can be starting by executing: $ ./standalone.sh -Djboss.bind.address=0.0.0.0 -Djboss.bind.address.management=0.0.0. |
We can automate those steps for client through Puppet.Let’s start writing puppet init.pp from scratch. I will be delivering step by step of init.pp to achieve every components of init.pp.
Line 1 – 4
The Line 1 to 4 does nothing but downloading JBOSS to /usr/share directory. What we are going to do is put the downloaded jboss-as-7.1.1.Final on /var/lib/puppet/files directory on puppet master and push it to the puppet-client at /usr/share/jboss-as directory.
Here is the below init.pp
The above init.pp define a class jboss-custom, takes JBOSS-as-7.1.1-Final from the puppet-master /var/lib/puppet/files/ and push it to the puppet-client.
Que: How does it know which directory to pull the files from?
Answer: Under /etc/puppet/fileserver.conf, we define those path and permission as shown below:
Shall we start?
Ensure that you have put JBOSS-as-7.1.1-Final under /var/lib/puppet/files directory with permission:
#chown –R puppet:puppet /var/lib/puppet
The permission is very important and shouldn’t be skipped.
Now run the command from the puppet-client to check if it runs without any issue:
Wow !!! Our first program went well and the server has pushed the file to the puppet-client successfully.
Line:5 to 9
The easiest way of performing the overall step is writing a shell script which will run on the remote machine:
Go to /var/lib/puppet/files and create a script called jbossdeploy.sh
#!/bin/bash
groupadd jbossas useradd -g jbossas -p deQcvEr1PRPSM jbossas chown -fR jbossas:jbossas /usr/share/jboss-as-7.1.1.Final/ cd /usr/share/jboss-as/ #!/usr/bin/expect spawn ./add-user.sh expect “(a):” send “a” expect “Realm (ManagementRealm):” send “ManagementRealm” expect “Username:” send “jbossas” expect “Password:” send “jbossas” expect “Re-enter Password:” send “jbossas” cd /usr/share/jboss-as-7.1.1.Final/bin ./standalone.sh -Djboss.bind.address=0.0.0.0 -Djboss.bind.address.management=0.0.0.0& |
The above script will create jboss user and group, run add-user.sh command under /usr/share/jboss-as/jboss-as-7.1.1.Final/bin directory. I have used expect library (ensure it is already installed) in perl.
Lets modify the init.pp so as to accommodate this script execution as shown:
class jboss-custom {
file {‘/usr/share/jboss-as/jboss-7.1.1.Final’: owner => ‘root’, group => ‘root’, mode => ‘0440’, source => ‘puppet://puppet-server.test.com/files/jboss-as-7.1.1.Final’ } file { ‘/usr/share/jboss-as/jbossdeploy.sh’: source => ‘puppet://puppet-server.test.com/files/jbossdeploy.sh’ } exec { “/usr/share/jboss-as/jbossdeploy.sh”:} } |
If you run now the following it goes all fine and start the JBOSS application server.
Lets test it.
puppet agent –test –verbose –server puppet-server.test.com
info: Caching catalog for puppet-client.test.com info: Applying configuration version ‘1345944985’ notice: /File[/usr/share/jboss-as/jbossdeploy.sh]/content: — /usr/share/jboss-as/jbossdeploy.sh 2012-08-29 17:37:01.365003616 -0400 +++ /tmp/puppet-file20120829-18751-81r0p8-0 2012-08-29 17:44:40.993732919 -0 400 @@ -1,12 +1,10 @@ #!/bin/bash – groupadd jbossas useradd -g jbossas -p deQcvEr1PRPSM jbossas chown -fR jbossas:jbossas /usr/share/jboss-as-7.1.1.Final/ -cd /usr/share/jboss-as/jboss-as-7.1.1.Final/bin +cd /usr/share/jboss-as/ #!/usr/bin/expect -/usr/bin/expect << EOD -spawn sh add-user.sh +spawn ./add-user.sh expect “(a):” send “a” expect “Realm (ManagementRealm):” @@ -17,7 +15,6 @@ send “jbossas” expect “Re-enter Password:” send “jbossas” -EOD cd /usr/share/jboss-as-7.1.1.Final/bin ./standalone.sh -Djboss.bind.address=0.0.0.0 -Djboss.bind.address.management=0. 0.0.0& info: FileBucket adding {md5}afc9bd6b8229da628396b90f2759f41f info: /File[/usr/share/jboss-as/jbossdeploy.sh]: Filebucketed /usr/share/jboss-a s/jbossdeploy.sh to puppet with sum afc9bd6b8229da628396b90f2759f41f notice: /File[/usr/share/jboss-as/jbossdeploy.sh]/content: content changed ‘{md5 }afc9bd6b8229da628396b90f2759f41f’ to ‘{md5}140ab2a8605d1164793c2175aa972675’ notice: /Stage[main]/Jboss-custom/Exec[/usr/share/jboss-as/jbossdeploy.sh]/retur ns: executed successfully notice: /File[/usr/share/jboss-as/jboss-7.1.1.Final]/ensure: created notice: Finished catalog run in 0.79 seconds [root@puppet-client ~]# |
Comments are closed.