Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sbates
Created May 12, 2013 13:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbates/5563535 to your computer and use it in GitHub Desktop.
Save sbates/5563535 to your computer and use it in GitHub Desktop.
#
# Cookbook Name:: tomcat
# Definitions:: deploy_tomcat_app
#
# Author:: Sascha Bates
define :deploy_tomcat_app,
:artifact_type => "latest", #latest or static
:artifact => "",
:group_id => "",
:version => "",
:repo => "",
:filetype => "",
:properties_dir => "",
:svc_name => "",
:homedir => "/opt/tomcat",
:action => "deploy" do
svc_name = params[:svc_name] || node[:tomcat][:svc_name]
homedir = params[:homedir] || node[:tomcat][:home]
src = "#{Chef::Config[:file_cache_path]}/#{params[:artifact]}-#{params[:version]}.#{params[:filetype]}"
dst = "#{homedir}/webapps/#{params[:artifact]}.#{params[:filetype]}"
service svc_name do
action :nothing
end
execute "deploy_#{params[:artifact]}" do
Chef::Log.debug("deploying #{params[:artifact]} to #{homedir}/webapps")
command "cp #{src} #{dst}"
notifies :restart, "service[#{svc_name}]"
action :nothing
end
art_action = "download_#{params[:artifact_type]}"
artifact params[:artifact] do
action art_action
group_id params[:group_id]
repo params[:repo]
version params[:version]
filetype params[:filetype]
notifies :stop, ("service[#{svc_name}]"), :immediately
notifies :delete, ("directory[#{homedir}/webapps/#{params[:artifact]}]"), :immediately
notifies :run, ("execute[deploy_#{params[:artifact]}]")
end
# This block exists to allow a deployed app to be deleted prior to deploying the new one
directory "#{homedir}/webapps/#{params[:artifact]}" do
action :nothing
recursive true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment