Tomcat installation
Configure tomcat
(same across
platform).
Location is different
(the steps,which you
do are the same,but the place is different,
Variable to hold location (we have to change the xml format).
If node[‘platform’]
== “ubuntu”
Tomcat_location = “/var/lib/tomcat”
Elsif node[‘platform’] == “RedHat”
Tomcat_location =
“/usr/share/tomcat”
End
Here,we are writing some
resource like file.(whatever files,we write is same,but the location is
different).only for the location part,I am writing the ‘if’ loop.
File tomcat_
Manual steps of
tomcat on Ubuntu:
Sudo apt-get update
Sudo apt-get install
tomcat7
Sudo nano /etc/default/tomcat7
Manual steps of
tomcat on centos:
Sudo yum install
tomcat
Sudo vi
/usr/share/tomcat/conf/tomcat.conf
driver:
name: vagrant
customize:
memory: 1024
provisioner:
name: chef_zero
#roles_path: ../../roles
# data_bags_path: ../../data_bags
#environments_path: ../../environments
#cookbook_path: ../../cookbooks
always_update_cookbooks: true
platforms:
- name: Ubuntu-14.04
driver:
box:Ubuntu/trusty64
- name: centos
suites:
- name: default
run_list:
- recipe[configuretomcat::default]
verifier:
inspec_tests:
- test/smoke/default
attributes:
I want to have generically 1gb ram,so I have wriiten this.
We have to install:
$ berks install
(this is always the first step,before doing the kitchen
converge).
(kitchen has dependency with the log files,that generated).
(kitchen
expects this,berksfile.lock).
cookbook::
configuretomcat
Recipe:: default
(#generally in default,you wont
write code).
(The normal principle is in writing
the default is,you will be not writing code).
(you will write,what are the recipe
calling order).
(everyone calls this file,it
executes in the order you write it).
(generally,this file should not
contain the logic of tomcat installation).
(rather it contains a code,which contains
logic).
(unless is the best thing here).
(unless is nothing but the,ifnot).
unless node [‘platform_family’] == ‘debian’
|| node [‘platform_family’] == ‘redhat’
# raise
“this is not supported in your current platform”
#(we don’t want to install the tomcat in
other operating systems).
(since,I am not doing any interpolation,instead of using the double
quotes,I can use the single quotes)
raise ‘this is not
supported in your current platform’
end
include_recipe [configuretomcat::tomcat]
(I want to validate the
ruby,whatever I written is correct or not).
(if you want to check that,).
$ ruby -c recipes/default.rb
syntax OK
(this will,tell you about the
ruby syntax).
(this is nothing but the ruby
compile).
(generally,when
you have the issues with the if statements and while statements,we can excute
this).
#cookbook::
configuretomcat
#Recipe:: tomcat
If node[‘platform’] == “ubuntu”
Apt_update (this is a chef resource).
#i need to write a
code,which stores the package location
else
execute ‘yum update’ do
command ‘yum -y update’
action :run
end
end
[ #yum_update
(there is no chef_resource for yum_update).
#(you might not have the resource for everything
right,so basically,it is not possible for your #specific installations).
#But still,we have a source, for
us,which is called as execute.
#What this resource is used for?
#In execute resource,we can just
give,name to it,tell the command,what you want to do it.
(this command is a linux,which
you want to execute).
Since,I don’t have a resource
for yum_update,I would be using the execute.
If you don’t find a resource and
you find a linux statement.you can use this execute resource.
Note:
But,there is one
problem with this:
Whatever,you write
in execute is not idempotent
(for example,if I write
execute,write a linux script for removing
a file,so it will try to execute it everytime,whenever your using,this
kind of statements,which are not idempotent,)
(we are learning
something called if and not_if guards,to add that to the idempotence).
(yum_update is fine,if you run it again and again,for
somethings,you wont like to run the convergence again and again).
Note:
Whenever you write execute,you need to worry about the
idempotence.
(idempotence = same
result,when you execute one time or hundred times)]
#my package_name now is from the attribute.
#Node [whatever that is defined in the attribute].
Package_name = node[‘configuretomcat’] [‘package_name’]
package_name = ‘tomcat7’
else
package_name = ‘tomcat’
package package_name do
action
:install
end
# you need to also start the
service
service package_name do
action :start
end
(safely,I need to move this to
attribute files).
Chef generate attribute default
(#attribute are only for the
variables).
#Default [‘cookbookname’] [‘package_name’] = ‘tomcat7’
If node[‘platform’]
== ‘ubuntu’
default [‘configuretomcat’]
[‘package_name’] = ‘tomcat7’
(this is what
the variable names should be).
Else
default [‘configuretomcat’]
[‘package_name’] = ‘tomcat’
Note:
In attribute,we can write any conditional
statemens and but not any execution statements
For example:
Conditional statements
If
Else
For
Execution statements
(should not write in attribute files)/
Apt_update etc.
Note:
What is the
difference between kitchen and vagrant?
Kitchen has different
places,where it can create the test environment
Vagrant is also
similar.
Kitchen supports to create VM’s in various environment.
When you do the
Chef generate recipe tomcat_test
It generates files in three
places:
1)tomcat.rb
2)spec >
unit > recipes > tomat_spec.rb
3)test > smoke >
default > tomcat_test.rb
(you also,want to write the
code,which tests your recipes).
***this
cookbook should not work on windows,it
should work on centos and Ubuntu.
Interesting applications:
Mifos x Ubuntu
install
Note:
What is meant by omnibus?
We have a component called
omni,it has all the installer components.
(especially the server
components).
Note
1kb =1000 bytes.
1kib(kib bytes) =
1024 bytes
No comments:
Post a Comment