Created
May 17, 2013 18:34
-
-
Save sbates/5601045 to your computer and use it in GitHub Desktop.
A first pass at trying to install Tomcat from wherever the hell you please to keep your pkg.
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 | |
| # Provider:: install | |
| # | |
| # Author:: Sascha Bates | |
| def load_current_resource | |
| @inst = new_resource.pkg_src | |
| @uid = new_resource.uid || "5001" | |
| @gid = new_resource.gid || "5001" | |
| @user = new_resource.user || "tomcat" | |
| @group = new_resource.group || "tomcat" | |
| end | |
| action :install do | |
| user @user do | |
| uid @uid | |
| group @group | |
| shell "/bin/bash" | |
| comment "This is the tomcat user" | |
| end | |
| get_package | |
| install | |
| end | |
| def get_package | |
| case @inst | |
| when "package" | |
| Chef::Log.debug("I don't need to fetch the tomcat install package because we are using yum") | |
| #install from package; note that tomcat6 rpm requires 93 package deps to install (wtf?) | |
| when "artifactory" | |
| # Let's go get an rpm which will install tomcat into /opt/tomcat/apache-tomcat-version | |
| artifact new_resource.run_context.node[:tomcat][:pkg_name] do | |
| action :download_static | |
| repo new_resource.run_context.node[:tomcat][:repo] | |
| version full_version | |
| filetype "rpm" | |
| group_id new_resource.run_context.node[:tomcat][:pkg_name] | |
| end | |
| # When making instances, we'll be deleting the local log dir | |
| # and symlinking it to /var/log/tomcat/inst | |
| # to avoid filling up application partions | |
| directory "/var/log/tomcat" do | |
| action :create | |
| end | |
| when "s3" | |
| # We might write a provider for this or wherever ops gets their packages from | |
| Chef::Log.debug("Planning to fetch the tomcat package from S3") | |
| end | |
| end | |
| def full_version | |
| [new_resource.run_context.node[:tomcat][:version], new_resource.run_context.node[:tomcat][:minor_version]].join(".") | |
| end | |
| def create_default | |
| case install_type | |
| when "artifactory" | |
| when "package" | |
| #someone should write some code for this | |
| when "s3" | |
| #someone should also write code for this | |
| end | |
| end | |
| def install | |
| provider = Chef::Provider::Package::Rpm if @inst == "artifactory" | |
| tomcat_file = [node[:tomcat][:pkg_name], full_version].join("-") | |
| pkg = [tomcat_file, "rpm"].join(".") | |
| src = ::File.join(Chef::Config[:file_cache_path], pkg) | |
| package pkg do | |
| action :install | |
| provider provider | |
| source src | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment