Wednesday, January 29, 2014

Using role to install tomcat recipe with java

*Before starting this installation, we should download openssl recipe from http://community.opscode.com/cookbooks/openssl because of dependency.

Upload it with "knife cookbook upload openssl' in cookbook directory.
ex)
root@knife2:/home/young/chef-repo# ls cookbooks/openssl/
CHANGELOG.md  CONTRIBUTING  libraries  LICENSE  metadata.json  metadata.rb  README.md  recipes
root@knife2:/home/young/chef-repo# knife cookbook upload openssl
Uploading openssl        [1.0.2]
Uploaded 1 cookbook.


# First Download community cookbook tomcat recipe.

root@knife2:/home/young/chef-repo/cookbooks# wget http://community.opscode.com/cookbooks/tomcat/versions/0_15_2/downloads

2014-01-28 05:10:19 (66.0 KB/s) - `downloads' saved [12250/12250]

root@knife2:/home/young/chef-repo/cookbooks# mv downloads tomcat
root@knife2:/home/young/chef-repo/cookbooks# tar xvzf tomcat 




#Edit key tool path in attributes/default.rb to /usr/local/java/bin/keytool
#I'm using ubuntu server, so change like bellows. Just "keytool part" 
when "debian","ubuntu"
  default["tomcat"]["user"] = "tomcat#{node["tomcat"]["base_version"]}"
  default["tomcat"]["group"] = "tomcat#{node["tomcat"]["base_version"]}"
  default["tomcat"]["home"] = "/usr/share/tomcat#{node["tomcat"]["base_version"]}"
  default["tomcat"]["base"] = "/var/lib/tomcat#{node["tomcat"]["base_version"]}"
  default["tomcat"]["config_dir"] = "/etc/tomcat#{node["tomcat"]["base_version"]}"
  default["tomcat"]["log_dir"] = "/var/log/tomcat#{node["tomcat"]["base_version"]}"
  default["tomcat"]["tmp_dir"] = "/tmp/tomcat#{node["tomcat"]["base_version"]}-tmp"
  default["tomcat"]["work_dir"] = "/var/cache/tomcat#{node["tomcat"]["base_version"]}"
  default["tomcat"]["context_dir"] = "#{node["tomcat"]["config_dir"]}/Catalina/localhost"
  default["tomcat"]["webapp_dir"] = "/var/lib/tomcat#{node["tomcat"]["base_version"]}/webapps"
  default["tomcat"]["keytool"] = "/usr/local/java/bin/keytool"
  default["tomcat"]["lib_dir"] = "#{node["tomcat"]["home"]}/lib"
  default["tomcat"]["endorsed_dir"] = "#{node["tomcat"]["lib_dir"]}/endorsed"

# To use role, comment the line that is "include_recipe java

#
# Cookbook Name:: tomcat
# Recipe:: default
#
# Copyright 2010, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# required for the secure_password method from the openssl cookbook
::Chef::Recipe.send(:include, Opscode::OpenSSL::Password)

#Below line
#include_recipe "java"


#Change JAVA_HOME TO JAVA_HOME=<%= "/usr/local/java" %>
root@knife2:/home/young/chef-repo# vi cookbooks/tomcat/templates/default/default_tomcat6.erb 

# The home directory of the Java development kit (JDK). You need at least
# JDK version 1.5. If JAVA_HOME is not set, some common directories for
# OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried.
JAVA_HOME=<%= "/usr/local/java" %>

root@knife2:/home/young/chef-repo# vi cookbooks/tomcat/templates/default/
default_tomcat6.erb     manifest.xml.erb        sysconfig_tomcat6.erb   
logging.properties.erb  server.xml.erb          tomcat-users.xml.erb    
root@knife2:/home/young/chef-repo# vi cookbooks/tomcat/templates/default/default_tomcat6.erb 
root@knife2:/home/young/chef-repo# vi cookbooks/tomcat/attributes/default.rb 
root@knife2:/home/young/chef-repo# cd ..
root@knife2:/home/young# cd -
/home/young/chef-repo

# Let's upload tomcat recipe
root@knife2:/home/young/chef-repo# knife cookbook upload tomcat
Uploading tomcat         [0.15.2]
Uploaded 1 cookbook.
root@knife2:/home/young/chef-repo# 

# With drag and drop, make the role name java_tomcat
# Do not care phpapp part that is just I practice some recipe.









# To monitor the process of recipe role install, I modified the log_level from ":auto" to ":debug"
# There are three? levels, which is auto,info,debug.

root@chef-client2:~# cat /etc/chef/client.rb
log_level        :debug
log_location     STDOUT
chef_server_url  "https://chef-server:443"
validation_client_name "chef-validator"
# Using default node name (fqdn)

# Run role chef-client command.

root@chef-client2:/usr/local/java# chef-client -f -o 'role[java_tomcat]'

# You can check with "ps -ef | grep tomcat" command whether tomcat is installed correctly.

root@chef-client2:~# ps -ef | grep tomcat
tomcat6   6644     1 17 21:51 ?        00:00:03 /usr/local/java/bin/java -Djava.util.logging.config.file=/var/lib/tomcat6/conf/logging.properties -Xmx128M -Djava.awt.headless=true -XX:+UseConcMarkSweepGC -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/share/tomcat6/lib/endorsed -classpath /usr/share/tomcat6/bin/bootstrap.jar -Dcatalina.base=/var/libtomcat6 -Dcatalina.home=/usr/share/tomcat6 -Djava.io.tmpdir=/tmp/tomcat6-tmp org.apache.catalina.startup.Bootstrap start
root      6666  2436  0 21:51 pts/2    00:00:00 grep --color=auto tomcat
root@chef-client2:~#




No comments:

Post a Comment