概要
jenkins-tomcat update(ver1.509.4) Cookbookの作成
詳細
jenkins-tomcat update(ver1.509.4) Cookbookを作成します。
仕様
jenkins-tomcatの環境構築については下記に基づいて行っておく。
その上で後述の内容でjenkins_tomcat_update cookbookをsite-cookbookに追加します。
jenkins-tomcat Cookbookの作成
http://d.hatena.ne.jp/tbpg/20131106/1383750635
vagrant
Vagrantfile
# -*- mode: ruby -*- # vi: set ft=ruby : # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = "ubuntu-12.04-x64" config.omnibus.chef_version = "11.6.0" config.vm.network :private_network, ip: "192.168.33.21" config.vm.provision :chef_solo do |chef| chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"] chef.data_bags_path = "data_bags" chef.add_recipe "apt_get_update" chef.add_recipe "jenkins_tomcat" chef.add_recipe "jenkins_tomcat_update" end end
cookbook(jenkins_tomcat_update)
site-cookbooks/apt_get_update/recipe/default.rb
log "start update apt-get" execute "update package index" do command "apt-get update" end.run_action(:run) log "end update apt-get"
cookbook(jenkins-tomcat)
site-cookbooks/jenkins_tomcat_update/library/helper.rb
class Chef class Recipe def execute_with_log(name, &block) log "start #{name}" block.call log "end #{name}" end end end
site-cookbooks/jenkins_tomcat_update/recipe/default.rb
if File.exists? "/usr/share/jenkins/jenkins.war" execute_with_log("backup old jenkins.war") do file "/usr/share/jenkins/backup" do content IO.read("/usr/share/jenkins/jenkins.war") end end execute_with_log("delete old jenkins.war") do file "/usr/share/jenkins/jenkins.war" do action :delete end end end execute_with_log("copy jenkins.war(ver.1.509.4)") do cookbook_file "/usr/share/jenkins/jenkins.war" do source "jenkins.war" owner "root" group "root" mode "0755" end end