Created
May 12, 2013 13:15
-
-
Save sbates/5563525 to your computer and use it in GitHub Desktop.
Install Tomcat via artifactory as the package manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Cookbook Name:: tomcat | |
| # Recipe:: install | |
| # | |
| # Copyright 2012 | |
| # Author:: Sascha Bates | |
| # Contact:: sascha@brattyredhead.com | |
| # This recipe is meant to be a common use pattern for Tomcat | |
| # As it matures, I'll probably factor it back into a definition | |
| # Actions: set variarbles | setup user | download tomcat | extract tomcat | set a symlink | deploy templates | define service | |
| tomcat_pkg = "#{node[:tomcat][:pkg_name]}-#{node[:tomcat][:version]}.#{node[:tomcat][:minor_version]}" | |
| tomcat_uri = "ext-release-local/#{node[:tomcat][:pkg_name]}/#{node[:tomcat][:pkg_name]}/#{node[:tomcat][:version]}.#{node[:tomcat][:minor_version]}/#{tomcat_pkg}.tar.gz" | |
| auth_url = "#{node[:tools][:artifactory][:user]}:#{node[:tools][:artifactory][:password]}@#{node[:tools][:artifactory][:url]}" | |
| #set up the tomcat user and group; creating a user will create an identically named group | |
| user node[:tomcat][:user] do | |
| uid 5001 | |
| shell "/bin/bash" | |
| comment "This is the tomcat user" | |
| end | |
| # Get the file but not if we already have an /opt/tomcat/bin dir | |
| remote_file "#{Chef::Config[:file_cache_path]}/#{tomcat_pkg}.tar.gz" do | |
| source "https://#{auth_url}/#{tomcat_uri}" | |
| retries 3 | |
| not_if { File.exists?("#{node[:tomcat][:home]}/bin") } | |
| end | |
| # Extract the file | |
| execute "extract_tomcat" do | |
| command "tar xf #{Chef::Config[:file_cache_path]}/#{tomcat_pkg}.tar.gz" | |
| cwd "opt" | |
| not_if { File.exists?("#{node[:tomcat][:home]}/bin") } | |
| only_if { File.exists?("#{Chef::Config[:file_cache_path]}/#{tomcat_pkg}.tar.gz") } | |
| end | |
| # # Symlink (/opt/tomcat -> /opt/tomcat-7.0.33) | |
| # link node[:tomcat][:home] do | |
| # to "/opt/#{tomcat_pkg}" | |
| # end | |
| ## Set up log symlink for easier finding of logs | |
| link "#{node[:logbase]}/#{node[:tomcat][:svc_name]}" do | |
| to "#{node[:tomcat][:home]}/logs" | |
| end | |
| # # Set up templates/configured files | |
| # template "#{node[:tomcat][:home]}/conf/server.xml" do | |
| # source "#{node[:tomcat][:version]}/server.xml.erb" | |
| # #owner node[:tomcat][:user] | |
| # notifies :restart, "service[#{node[:tomcat][:svc_name]}]" | |
| # end | |
| # Set up the service | |
| template "/etc/init.d/#{node[:tomcat][:svc_name]}" do | |
| source "tomcat.erb" | |
| mode "0755" | |
| notifies :restart, "service[#{node[:tomcat][:svc_name]}]" | |
| end | |
| service node[:tomcat][:svc_name] do | |
| supports :restart => true, :status => true | |
| action :enable | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment