OSDN Git Service

add yum_utils::mirror recipe.
authorwhitestar <whitestar@gaea.test>
Tue, 24 Sep 2013 12:49:48 +0000 (21:49 +0900)
committerwhitestar <whitestar@gaea.test>
Tue, 24 Sep 2013 12:49:48 +0000 (21:49 +0900)
13 files changed:
cookbooks/apt_utils/attributes/default.rb
cookbooks/apt_utils/templates/default/etc/apache2/conf.d/apt-mirror
cookbooks/apt_utils/templates/default/etc/apt/mirror.list
cookbooks/apt_utils/templates/default/etc/apt/sources.list
cookbooks/apt_utils/templates/default/etc/cron.d/apt-mirror
cookbooks/yum_utils/attributes/default.rb
cookbooks/yum_utils/recipes/mirror.rb
cookbooks/yum_utils/templates/default/etc/apache2/conf.d/yum-mirror [new file with mode: 0644]
cookbooks/yum_utils/templates/default/etc/cron.d/yum-mirror
cookbooks/yum_utils/templates/default/usr/local/bin/yum-mirror
roles/apt-mirror.rb
roles/grid-ftp.rb
roles/yum-mirror.rb

index 2407650..33e85fd 100644 (file)
@@ -26,6 +26,8 @@ default['apt_utils']['mirror']['base_path'] = '/var/spool/apt-mirror'
 default['apt_utils']['mirror']['nthreads'] = '20'
 default['apt_utils']['mirror']['_tilde'] = '0'
 default['apt_utils']['mirror']['country'] = 'us'  # or jp,...
+# http://www.debian.org/mirror/official
+# https://launchpad.net/ubuntu/+archivemirrors
 default['apt_utils']['mirror']['distributions']['debian'] = {
   'code_names' => [
     'wheezy',
index c5255f9..b895cf4 100644 (file)
@@ -1,3 +1,19 @@
+#
+# Copyright 2013, whitestar
+#
+# 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.
+#
+
 <%
 country = node['apt_utils']['mirror']['country']
 
index 8a63823..82eecc1 100644 (file)
@@ -1,3 +1,19 @@
+#
+# Copyright 2013, whitestar
+#
+# 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.
+#
+
 ############# config ##################
 #
 set base_path    <%= node['apt_utils']['mirror']['base_path'] %>
index 66ff100..4e89c55 100644 (file)
@@ -1,3 +1,19 @@
+#
+# Copyright 2013, whitestar
+#
+# 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.
+#
+
 <% node['apt_utils']['source']['apt_lines'].each do |apt_line| -%>
 <%= apt_line %>
 <% end -%>
index ecd74c1..b1fa6e4 100644 (file)
@@ -1,6 +1,21 @@
 #
 # Regular cron jobs for the apt-mirror package
 #
+# Copyright 2013, whitestar
+#
+# 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.
+#
+
 <%
 user = nil
 command = nil
index 9eb99f4..0532f4a 100644 (file)
 # limitations under the License.
 #
 
-default['yum_utils']['mirror']['cron_period'] = '#0 4  * * *'  # default: negative
+default['yum_utils']['mirror']['cron_period'] = '#0 2  * * *'  # default: inactive
 default['yum_utils']['mirror']['base_path'] = '/var/spool/yum-mirror'
-default['yum_utils']['mirror']['country'] = 'us'  # or jp,...
+default['yum_utils']['mirror']['rsync_sources'] = [
+=begin
+# examples
+  # CentOS
+  # http://www.centos.org/modules/tinycontent/index.php?id=30
+  {
+    'url' => 'rsync://ftp.riken.jp/centos/',
+    'rsync_opts' => '-avSH --stats --partial --delete --exclude /[1-5]*/ --exclude /6.[0-3]/ --exclude local* --exclude isos --exclude ppc*',
+    'http_alias' => '/centos'
+  },
+  # EPEL
+  # http://mirrors.fedoraproject.org/publiclist/EPEL/
+  {
+    'url' => 'rsync://ftp.riken.jp/fedora/epel/',
+    'rsync_opts' => '-avSH --stats --partial --delete --exclude /[1-5]*/ --exclude local* --exclude isos --exclude ppc*',
+    'http_alias' => '/fedora/epel'
+  },
+=end
+]
 
index f49f2d0..888761f 100644 (file)
 # limitations under the License.
 #
 
+case node[:platform_family]
+when 'debian'
+  cron_package = 'cron'
+  httpd_service = 'apache2'
+  httpd_conf_path = "/etc/#{httpd_service}/conf.d/yum-mirror"
+when 'rhel'
+  cron_package = 'crontabs'
+  httpd_service = 'httpd'
+  httpd_conf_path = "/etc/#{httpd_service}/conf.d/yum-mirror.conf"
+end
+
 pkg = 'rsync'
 resources(:package => pkg) rescue package pkg do
   action :install
 end
 
+pkg = cron_package
+resources(:package => pkg) rescue package pkg do
+  action :install
+end
+
+base_path = node['yum_utils']['mirror']['base_path']
+%w{
+  mirror
+  var
+}.each {|subdir|
+  directory "#{base_path}/#{subdir}" do
+    owner 'root'
+    group 'root'
+    mode '0755'
+    recursive true
+  end
+}
+
+rsync_sources = []
+node['yum_utils']['mirror']['rsync_sources'].each {|source|
+  local_path = "#{base_path}/mirror/#{source['url'].gsub(/^rsync:\/\//, '')}"
+  if local_path.end_with?('/') then
+    local_path.chop!
+  end
+  directory local_path do
+    owner 'root'
+    group 'root'
+    mode '0755'
+    recursive true
+  end
+
+  rsync_sources.push(
+    {
+      'http_alias' => source['http_alias'],
+      'local_path' => local_path,
+      'rsync_command' => "rsync #{source['rsync_opts']} #{source['url']} #{local_path}/",
+    }
+  )
+}
+
 template '/usr/local/bin/yum-mirror' do
   source 'usr/local/bin/yum-mirror'
   owner 'root'
   group 'root'
   mode '0755'
+  variables({
+    :rsync_sources => rsync_sources
+  })
 end
 
 template '/etc/cron.d/yum-mirror' do
@@ -36,23 +90,24 @@ template '/etc/cron.d/yum-mirror' do
   mode '0644'
 end
 
-apache_pkg = nil
-apache_service = nil
-case node[:platform_family]
-when 'debian'
-  apache_pkg = 'apache2'
-  apache_service = 'apache2'
-when 'rhel'
-  apache_pkg = 'httpd'
-  apache_service = 'httpd'
-end
-
-resources(:package => apache_pkg) rescue package apache_pkg do
+pkg = httpd_service
+resources(:package => pkg) rescue package pkg do
   action :install
 end
 
-resources(:service => apache_service) rescue service apache_service do
+resources(:service => httpd_service) rescue service httpd_service do
   action [:enable, :start]
   supports :status => true, :restart => true, :reload => true
 end
 
+template httpd_conf_path do
+  source 'etc/apache2/conf.d/yum-mirror'
+  owner 'root'
+  group 'root'
+  mode '0644'
+  variables({
+    :rsync_sources => rsync_sources
+  })
+  notifies :restart, "service[#{httpd_service}]"
+end
+
diff --git a/cookbooks/yum_utils/templates/default/etc/apache2/conf.d/yum-mirror b/cookbooks/yum_utils/templates/default/etc/apache2/conf.d/yum-mirror
new file mode 100644 (file)
index 0000000..b6a854d
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# Copyright 2013, whitestar
+#
+# 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.
+#
+
+<%
+@rsync_sources.each do |source|
+-%>
+Alias <%= source['http_alias'] %> <%= source['local_path'] %> 
+<Directory <%= source['local_path'] %>>
+  Options Indexes SymLinksIfOwnerMatch FollowSymLinks
+  IndexOptions NameWidth=* +SuppressDescription
+  AllowOverride FileInfo Indexes
+  Order Deny,Allow
+  Allow from all
+  ErrorDocument 404 default
+</Directory>
+
+<%
+end
+-%>
+
index daf5246..bb35ec9 100644 (file)
@@ -1,4 +1,19 @@
 #
 # Regular cron jobs for the yum-mirror
 #
+# Copyright 2013, whitestar
+#
+# 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.
+#
+
 <%= node['yum_utils']['mirror']['cron_period'] %>      root    /usr/local/bin/yum-mirror > <%= node['yum_utils']['mirror']['base_path'] %>/var/cron.log
index e69de29..ef31fe4 100644 (file)
@@ -0,0 +1,27 @@
+#!/bin/sh
+#
+# Copyright 2013, whitestar
+#
+# 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.
+#
+
+<%
+@rsync_sources.each do |source|
+-%>
+date
+<%= source['rsync_command'] %>
+
+<%
+end
+-%>
+
index 16df5c5..0581ca9 100644 (file)
@@ -1,3 +1,19 @@
+#
+# Copyright 2013, whitestar
+#
+# 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.
+#
+
 name 'apt-mirror'
 description 'APT mirror server.'
 
index bd90c75..8d8e874 100644 (file)
@@ -1,3 +1,19 @@
+#
+# Copyright 2013, whitestar
+#
+# 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.
+#
+
 $LOAD_PATH.push("#{File.dirname(__FILE__)}/../_lib")
 #${chef-repo}/_lib/grid.rb
 require 'grid'
@@ -9,6 +25,7 @@ run_list(
   'role[node_commons]',
   'role[apt-mirror]',
   'role[apt-source]',
+  'role[yum-mirror]',
   #'role[ganglia-gmond]',
 )
 
@@ -69,8 +86,26 @@ override_attributes(
             'non-free'
           ]
         }
-      },
-    },
+      }
+    }
+  },
+  'yum_utils' => {
+    'mirror' => {
+      'cron_period' => '0 21   * * *',
+      #'cron_period' => '0 4   * * *',
+      'rsync_sources' => [
+        {
+          'url' => 'rsync://ftp.riken.jp/centos/',
+          'rsync_opts' => '-avSH --stats --partial --delete --exclude /[1-5]*/ --exclude /6.[0-3]/ --exclude local* --exclude isos --exclude ppc*',
+          'http_alias' => '/centos'
+        },
+        {
+          'url' => 'rsync://ftp.riken.jp/fedora/epel/',
+          'rsync_opts' => '-avSH --stats --partial --delete --exclude /[1-5]*/ --exclude local* --exclude isos --exclude ppc*',
+          'http_alias' => '/fedora/epel'
+        }
+      ]
+    }
   },
   'ganglia' => {
     # gmond
index 6c2d5ef..2acf069 100644 (file)
@@ -1,3 +1,19 @@
+#
+# Copyright 2013, whitestar
+#
+# 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.
+#
+
 name 'yum-mirror'
 description 'YUM mirror server.'