http://wnapdlf.blogspot.kr/2014/01/using-role-to-install-tomcat-recipe.html
We can install java and tomcat using attributes/default.rb also
1.First
root@knife2:/home/young/chef-repo# vi cookbooks/java/attributes/default.rb
default["java"]["java_home"] = "/usr/local/java"
2. Second
Comment out on line include_recipe "java"
root@knife2:/home/young/chef-repo# vi cookbooks/tomcat/recipes/default.rb
# required for the secure_password method from the openssl cookbook
::Chef::Recipe.send(:include, Opscode::OpenSSL::Password)
include_recipe "java"
3. Change JAVA_HOME
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=<%= node["java"]["java_home"] %>
4. Upload recipe
root@knife2:/home/young/chef-repo# knife cookbook upload java tomcat
Uploading java [0.1.0]
Uploading tomcat [0.15.2]
Uploaded 2 cookbooks.
root@knife2:/home/young/chef-repo#
5. Now let's test.
root@chef-client1:~# rm -rf /usr/local/java; apt-get -y purge tomcat6
root@chef-client1:~# chef-client -o tomcat
Omitting..blah blah blah
2014-01-30T03:22:16+09:00] INFO: service[tomcat] restarted
- restart service service[tomcat]
[2014-01-30T03:22:16+09:00] INFO: Chef Run complete in 32.761104063 seconds
[2014-01-30T03:22:16+09:00] INFO: Running report handlers
[2014-01-30T03:22:16+09:00] INFO: Report handlers complete
Chef Client finished, 6 resources updated
root@chef-client1:~# /usr/local/java/bin/java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
root@chef-client1:~#
root@chef-client1:~# ps -ef | grep tomcat
tomcat6 10865 1 1 03:44 ? 00:00:04 /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 10901 8275 0 03:49 pts/2 00:00:00 grep --color=auto tomcat
root@chef-client1:~#
6. Conclusion
I could install java and tomcat without new role.
First, edit attributes/default.rb of java recipe.
Second, just use the tomcat recipe from community site as it is.
Thanks for reading. Any comments or recommendation is welcome.
No comments:
Post a Comment