Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make it compatible with war install and gentoo #26

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
#

default[:jenkins][:mirror] = "http://mirrors.jenkins-ci.org"
default[:jenkins][:package_url] = "http://pkg.jenkins-ci.org"
default[:jenkins][:java_home] = ENV['JAVA_HOME']

default[:jenkins][:java_install] = false

default[:jenkins][:server][:home] = "/var/lib/jenkins"
default[:jenkins][:server][:user] = "jenkins"

Expand Down
24 changes: 24 additions & 0 deletions attributes/package.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Cookbook Name:: jenkins
# Based on hudson
# Attributes:: package
#
# Author:: Doug MacEachern <[email protected]>
# Author:: Fletcher Nichol <[email protected]>
#
# Copyright 2010, VMware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

default[:jenkins][:package_url] = "http://pkg.jenkins-ci.org"
25 changes: 25 additions & 0 deletions attributes/war.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Cookbook Name:: jenkins
# Based on hudson
# Attributes:: war
#
# Author:: Pierre Ozoux <[email protected]>
#
# Copyright 2010, VMware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

default[:jenkins][:war_url] = "http://mirrors.jenkins-ci.org/war/latest/jenkins.war"
default[:jenkins][:server][:log_dir] = "/var/log/jenkins"
default[:jenkins][:server][:java_war_dir] = "/usr/share/jenkins"
3 changes: 2 additions & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.6.3"

%w(runit java).each { |cb| depends cb }
%w(java).each { |cb| depends cb }
%w(iptables yum apt).each { |cb| recommends cb }
depends "nginx"
69 changes: 69 additions & 0 deletions recipes/commons.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#
# Cookbook Name:: jenkins
# Based on hudson
# Recipe:: default
#
# Author:: AJ Christensen <[email protected]>
# Author:: Doug MacEachern <[email protected]>
# Author:: Fletcher Nichol <[email protected]>
#
# Copyright 2010, VMware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

pkey = "#{node[:jenkins][:server][:home]}/.ssh/id_rsa"

user node[:jenkins][:server][:user] do
home node[:jenkins][:server][:home]
end

directory node[:jenkins][:server][:home] do
recursive true
owner node[:jenkins][:server][:user]
group node[:jenkins][:server][:group]
end

directory "#{node[:jenkins][:server][:home]}/.ssh" do
mode 0700
owner node[:jenkins][:server][:user]
group node[:jenkins][:server][:group]
end

execute "ssh-keygen -f #{pkey} -N ''" do
user node[:jenkins][:server][:user]
group node[:jenkins][:server][:group]
not_if { File.exists?(pkey) }
end

ruby_block "store jenkins ssh pubkey" do
block do
node.set[:jenkins][:server][:pubkey] = File.open("#{pkey}.pub") { |f| f.gets }
end
end

directory "#{node[:jenkins][:server][:home]}/plugins" do
owner node[:jenkins][:server][:user]
group node[:jenkins][:server][:group]
only_if { node[:jenkins][:server][:plugins].size > 0 }
end

node[:jenkins][:server][:plugins].each do |name|
remote_file "#{node[:jenkins][:server][:home]}/plugins/#{name}.hpi" do
source "#{node[:jenkins][:mirror]}/plugins/#{name}/latest/#{name}.hpi"
backup false
owner node[:jenkins][:server][:user]
group node[:jenkins][:server][:group]
action :create_if_missing
end
end
104 changes: 16 additions & 88 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,88 +22,19 @@
# limitations under the License.
#

pkey = "#{node[:jenkins][:server][:home]}/.ssh/id_rsa"
tmp = "/tmp"

user node[:jenkins][:server][:user] do
home node[:jenkins][:server][:home]
end

directory node[:jenkins][:server][:home] do
recursive true
owner node[:jenkins][:server][:user]
group node[:jenkins][:server][:group]
end

directory "#{node[:jenkins][:server][:home]}/.ssh" do
mode 0700
owner node[:jenkins][:server][:user]
group node[:jenkins][:server][:group]
end

execute "ssh-keygen -f #{pkey} -N ''" do
user node[:jenkins][:server][:user]
group node[:jenkins][:server][:group]
not_if { File.exists?(pkey) }
end

ruby_block "store jenkins ssh pubkey" do
block do
node.set[:jenkins][:server][:pubkey] = File.open("#{pkey}.pub") { |f| f.gets }
end
end
#"jenkins stop" may (likely) exit before the process is actually dead
#so we sleep until nothing is listening on jenkins.server.port (according to netstat)

directory "#{node[:jenkins][:server][:home]}/plugins" do
owner node[:jenkins][:server][:user]
group node[:jenkins][:server][:group]
only_if { node[:jenkins][:server][:plugins].size > 0 }
end
include_recipe 'jenkins::commons'

node[:jenkins][:server][:plugins].each do |name|
remote_file "#{node[:jenkins][:server][:home]}/plugins/#{name}.hpi" do
source "#{node[:jenkins][:mirror]}/plugins/#{name}/latest/#{name}.hpi"
backup false
owner node[:jenkins][:server][:user]
group node[:jenkins][:server][:group]
action :create_if_missing
end
if node.jenkins.java_install or node.platform == "gentoo"
include_recipe 'jenkins::war'
else
include_recipe 'jenkins::package'
end

case node.platform
when "ubuntu", "debian"
include_recipe "apt"
include_recipe "java"
pid_file = node[:jenkins][:server][:pid_file]

pid_file = "/var/run/jenkins/jenkins.pid"
install_starts_service = true

apt_repository "jenkins" do
uri "#{node.jenkins.package_url}/debian"
components %w[binary/]
key "http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key"
action :add
end
when "centos", "redhat"
include_recipe "yum"

pid_file = "/var/run/jenkins.pid"
install_starts_service = false

yum_key "jenkins" do
url "#{node.jenkins.package_url}/redhat/jenkins-ci.org.key"
action :add
end

yum_repository "jenkins" do
description "repository for jenkins"
url "#{node.jenkins.package_url}/redhat/"
key "jenkins"
action :add
end
end

#"jenkins stop" may (likely) exit before the process is actually dead
#so we sleep until nothing is listening on jenkins.server.port (according to netstat)
ruby_block "netstat" do
block do
10.times do
Expand Down Expand Up @@ -145,22 +76,19 @@
action :nothing
end

log "jenkins: install and start" do
notifies :install, "package[jenkins]", :immediately
notifies :start, "service[jenkins]", :immediately unless install_starts_service
log "jenkins: start" do
case node.platform
when "ubuntu", "debian"
#nothing to start
else
notifies :start, "service[jenkins]", :immediately
end
notifies :create, "ruby_block[block_until_operational]", :immediately
not_if do
File.exists? "/usr/share/jenkins/jenkins.war"
File.exists? "#{node.jenkins.server.java_war_dir}/jenkins.war"
end
end

template "/etc/default/jenkins"

package "jenkins" do
action :nothing
notifies :create, "template[/etc/default/jenkins]", :immediately
end

# restart if this run only added new plugins
log "plugins updated, restarting jenkins" do
#ugh :restart does not work, need to sleep after stop.
Expand Down
63 changes: 63 additions & 0 deletions recipes/package.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#
# Cookbook Name:: jenkins
# Based on hudson
# Recipe:: package
#
# Author:: AJ Christensen <[email protected]>
# Author:: Doug MacEachern <[email protected]>
# Author:: Fletcher Nichol <[email protected]>
#
# Copyright 2010, VMware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

case node.platform
when "ubuntu", "debian"
include_recipe "apt"
include_recipe "java"

node.set[:jenkins][:server][:pid_file] = "/var/run/jenkins/jenkins.pid"

apt_repository "jenkins" do
uri "#{node.jenkins.package_url}/debian"
components %w[binary/]
key "http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key"
action :add
end
when "centos", "redhat"
include_recipe "yum"

node.set[:jenkins][:server][:pid_file] = "/var/run/jenkins.pid"

yum_key "jenkins" do
url "#{node.jenkins.package_url}/redhat/jenkins-ci.org.key"
action :add
end

yum_repository "jenkins" do
description "repository for jenkins"
url "#{node.jenkins.package_url}/redhat/"
key "jenkins"
action :add
end
end

notifies :install, "package[jenkins]", :immediately

template "/etc/default/jenkins"

package "jenkins" do
action :nothing
notifies :create, "template[/etc/default/jenkins]", :immediately
end
63 changes: 63 additions & 0 deletions recipes/war.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#
# Cookbook Name:: jenkins
# Based on hudson
# Recipe:: war
#
# Author:: Pierre Ozoux <[email protected]>
#
# Copyright 2010, VMware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include_recipe "java"


node.set[:jenkins][:server][:pid_file] = "/var/run/jenkins.pid"

directory node[:jenkins][:server][:java_war_dir] do
mode 0755
end

directory node[:jenkins][:server][:log_dir] do
mode 0755
owner node[:jenkins][:server][:user]
group node[:jenkins][:server][:group]
end

remote_file "#{node.jenkins.server.java_war_dir}/jenkins.war" do
source node[:jenkins][:war_url]
mode 00644
not_if "test -f #{node.jenkins.server.java_war_dir}/jenkins.war"
end

#init method
#It works on Gentoo, didn't test on other platform, that's why there is the test.
if node.platform == "gentoo"

template "/etc/init.d/jenkins" do
source "init.d.erb"
mode 0755
owner "root"
group "root"
end

template "/etc/conf.d/jenkins" do
source "conf.d.erb"
mode 0644
owner "root"
group "root"
end
else
#your init method
end
Loading