• R/O
  • HTTP
  • SSH
  • HTTPS

grid-chef-repo: Commit

Grid環境構築用のChefリポジトリです。


Commit MetaInfo

Revisiond801009ef3b9d1b4a9230dc4a8e1ce45d95208b2 (tree)
Time2018-09-23 13:57:35
Authorwhitestar <whitestar@user...>
Commiterwhitestar

Log Message

adds the APT Cacher NG autopilot feature.

Change Summary

Incremental Difference

--- a/cookbooks/apt_utils/CHANGELOG.md
+++ b/cookbooks/apt_utils/CHANGELOG.md
@@ -1,6 +1,11 @@
11 apt_utils CHANGELOG
22 ===================
33
4+0.3.0
5+-----
6+- adds the APT Cacher NG autopilot feature.
7+- refactoring.
8+
49 0.2.6
510 -----
611 - improves server key pair deployment for a aptly service.
--- /dev/null
+++ b/cookbooks/apt_utils/Gemfile.lock
@@ -0,0 +1,22 @@
1+GEM
2+ remote: https://rubygems.org/
3+ specs:
4+ chef-api (0.8.0)
5+ logify (~> 0.1)
6+ mime-types
7+ logify (0.2.0)
8+ mime-types (3.2.2)
9+ mime-types-data (~> 3.2015)
10+ mime-types-data (3.2018.0812)
11+ stove (6.0.0)
12+ chef-api (~> 0.5)
13+ logify (~> 0.2)
14+
15+PLATFORMS
16+ ruby
17+
18+DEPENDENCIES
19+ stove
20+
21+BUNDLED WITH
22+ 1.16.0
--- a/cookbooks/apt_utils/README.md
+++ b/cookbooks/apt_utils/README.md
@@ -51,6 +51,10 @@ This cookbook includes apt utility (apt-cacher-ng, apt mirroring site setup and
5151 |`['apt_utils']['aptly']['docker-compose']['etc_dir']`|String||`"#{node['apt_utils']['aptly']['docker-compose']['app_dir']}/etc"`|
5252 |`['apt_utils']['aptly']['docker-compose']['data_dir']`|String|Persistent volume path or nil (unset).|`"#{node['apt_utils']['aptly']['docker-compose']['app_dir']}/data"`|
5353 |`['apt_utils']['aptly']['docker-compose']['config']`|Hash|`docker-compose.yml` configurations.|See `attributes/default.rb`|
54+|`['apt_utils']['apt-cacher-ng']['autopilot']['enabled']`|Boolean|APT Cacher NG autopilot feature flag.|`false`|
55+|`['apt_utils']['apt-cacher-ng']['autopilot']['log_dir']`|String|log file's directory path.|`'/var/log'`|
56+|`['apt_utils']['apt-cacher-ng']['autopilot']['wait_time']`|String|wait time after booted.|`'120s'`|
57+|`['apt_utils']['apt-cacher-ng']['autopilot']['check_period']`|String|service check period. `'#'` means inactive.|`'*/5 * * * *'`|
5458 |`['apt_utils']['apt-cacher-ng']['CacheDir']`|String|path to cache directory|`'/var/cache/apt-cacher-ng'`|
5559 |`['apt_utils']['apt-cacher-ng']['LogDir']`|String|path to log directory.|`'/var/log/apt-cacher-ng'`|
5660 |`['apt_utils']['apt-cacher-ng']['Port']`|String|service port number.|`'3142'`|
@@ -100,6 +104,7 @@ name 'aptly-docker-compose'
100104 description 'aptly by docker-compose'
101105
102106 run_list(
107+ # see https://osdn.net/projects/metasearch/scm/git/grid-chef-repo/blobs/master/roles/docker-new-repo.rb
103108 'role[docker]',
104109 'recipe[apt_utils::aptly-docker-compose]',
105110 )
--- a/cookbooks/apt_utils/Rakefile
+++ b/cookbooks/apt_utils/Rakefile
@@ -3,12 +3,56 @@ require 'rubocop/rake_task'
33 require 'foodcritic'
44 require 'stove/rake_task'
55
6+tpl_cookbook = '00cookbook'
7+cookbook_name = File.basename(Dir.pwd)
8+
9+desc 'Initialize project'
10+task :init do
11+ next if cookbook_name == tpl_cookbook
12+
13+ [
14+ '.foodcritic',
15+ '.rubocop.yml',
16+ 'Berksfile',
17+ 'concourse.yml',
18+ 'fly-vars.yml',
19+ 'fly-vars.local.yml',
20+ 'Gemfile',
21+ 'Gemfile.lock',
22+ 'version',
23+ ].each {|conf|
24+ sh "cp ../#{tpl_cookbook}/#{conf} ./" unless File.exist?(conf)
25+ }
26+
27+ ruby [
28+ %(-pne '$_.gsub!(/^cookbook-name: .*$/, "cookbook-name: #{cookbook_name}")'),
29+ '-i fly-vars.local.yml',
30+ ].join(' ')
31+end
32+
33+desc 'Update project'
34+task :update do
35+ next if cookbook_name == tpl_cookbook
36+
37+ [
38+ 'Rakefile',
39+ 'concourse.yml',
40+ 'fly-vars.yml',
41+ 'Gemfile',
42+ 'Gemfile.lock',
43+ ].each {|conf|
44+ sh "cp ../#{tpl_cookbook}/#{conf} ./"
45+ }
46+end
47+
48+desc 'fly set-pipeline'
649 task :'set-pipeline' do
750 sh [
8- "fly -t $CC_TARGET sp -p #{File.basename(Dir.pwd)}-cookbook -c concourse.yml",
9- '-l fly-vars.yml -l ~/sec/credentials-prod.yml',
51+ "fly -t $CC_TARGET sp -p #{cookbook_name}-cookbook -c concourse.yml",
52+ '-l fly-vars.yml -l fly-vars.local.yml -l ~/sec/credentials-prod.yml',
1053 ].join(' ')
1154 end
55+desc 'rake set-pipeline alias'
1256 task sp: 'set-pipeline'
1357
1458 namespace :style do
--- a/cookbooks/apt_utils/attributes/default.rb
+++ b/cookbooks/apt_utils/attributes/default.rb
@@ -2,7 +2,7 @@
22 # Cookbook Name:: apt_utils
33 # Attributes:: default
44 #
5-# Copyright 2013-2017, whitestar
5+# Copyright 2013-2018, whitestar
66 #
77 # Licensed under the Apache License, Version 2.0 (the "License");
88 # you may not use this file except in compliance with the License.
@@ -122,6 +122,12 @@ version_2_config = {
122122 }
123123 default['apt_utils']['aptly']['docker-compose']['config'] = version_2_config
124124
125+default['apt_utils']['apt-cacher-ng']['autopilot'] = {
126+ 'enabled' => false,
127+ 'log_dir' => '/var/log',
128+ 'wait_time' => '120s',
129+ 'check_period' => '*/5 * * * *', # '#': inactive
130+}
125131 default['apt_utils']['apt-cacher-ng']['CacheDir'] = '/var/cache/apt-cacher-ng'
126132 default['apt_utils']['apt-cacher-ng']['LogDir'] = '/var/log/apt-cacher-ng'
127133 default['apt_utils']['apt-cacher-ng']['SupportDir'] = '/usr/lib/apt-cacher-ng'
--- a/cookbooks/apt_utils/concourse.yml
+++ b/cookbooks/apt_utils/concourse.yml
@@ -1,5 +1,4 @@
11 ---
2-# $ fly -t $CC_TARGET sp -p apt_utils-cookbook -c concourse.yml -l fly-vars.yml -l ~/sec/credentials-prod.yml
32 resources:
43 - name: src-git
54 type: git
@@ -8,8 +7,8 @@ resources:
87 branch: master
98 paths:
109 - cookbooks/((cookbook-name))
11- git_user: ((git-user-osdn))
1210 private_key: ((git-private-key))
11+ git_user: ((git-user-osdn))
1312 #check_every: 1h # default: 1m
1413 - name: chefdk-cache
1514 type: docker-image
--- /dev/null
+++ b/cookbooks/apt_utils/fly-vars.local.yml
@@ -0,0 +1,2 @@
1+---
2+cookbook-name: apt_utils
--- a/cookbooks/apt_utils/fly-vars.yml
+++ b/cookbooks/apt_utils/fly-vars.yml
@@ -1,3 +1,2 @@
11 ---
2-cookbook-name: apt_utils
32 chefdk-version: 1.6.11
--- a/cookbooks/apt_utils/metadata.rb
+++ b/cookbooks/apt_utils/metadata.rb
@@ -15,6 +15,6 @@ chef_version '>= 12'
1515 end
1616
1717 depends 'apt'
18-depends 'docker-grid', '>= 0.2.7'
18+depends 'docker-grid', '>= 0.5.8'
1919 depends 'platform_utils', '>= 0.4.3'
20-depends 'ssl_cert', '>= 0.4.1'
20+depends 'ssl_cert', '>= 0.4.2'
--- a/cookbooks/apt_utils/recipes/apt-cacher-ng.rb
+++ b/cookbooks/apt_utils/recipes/apt-cacher-ng.rb
@@ -2,7 +2,7 @@
22 # Cookbook Name:: apt_utils
33 # Recipe:: apt-cacher-ng
44 #
5-# Copyright 2013-2017, whitestar
5+# Copyright 2013-2018, whitestar
66 #
77 # Licensed under the Apache License, Version 2.0 (the "License");
88 # you may not use this file except in compliance with the License.
@@ -19,6 +19,8 @@
1919
2020 ::Chef::Recipe.send(:include, PlatformUtils::PackageUtils)
2121
22+conf = node['apt_utils']['apt-cacher-ng']
23+
2224 if node['platform_family'] == 'debian'
2325 pkg = 'apt-cacher-ng'
2426 user_name = pkg
@@ -32,14 +34,14 @@ if node['platform_family'] == 'debian'
3234 supports status: true, restart: true, reload: false
3335 end
3436
35- directory node['apt_utils']['apt-cacher-ng']['CacheDir'] do
37+ directory conf['CacheDir'] do
3638 owner user_name
3739 group user_name
3840 mode '2755'
3941 recursive true
4042 end
4143
42- directory node['apt_utils']['apt-cacher-ng']['LogDir'] do
44+ directory conf['LogDir'] do
4345 owner user_name
4446 group user_name
4547 mode '2755'
@@ -54,3 +56,21 @@ if node['platform_family'] == 'debian'
5456 notifies :restart, "service[#{service_name}]"
5557 end
5658 end
59+
60+# autopilot
61+srv = 'apt-cacher-ng'
62+template "/etc/cron.d/#{srv}-local" do
63+ source "etc/cron.d/#{srv}-local"
64+ owner 'root'
65+ group 'root'
66+ mode '0644'
67+ action :delete unless conf['autopilot']['enabled']
68+end
69+
70+template '/usr/local/bin/restart_acng-local' do
71+ source 'usr/local/bin/restart_acng-local'
72+ owner 'root'
73+ group 'root'
74+ mode '0755'
75+ action :delete unless conf['autopilot']['enabled']
76+end
--- a/cookbooks/apt_utils/recipes/aptly-docker-compose.rb
+++ b/cookbooks/apt_utils/recipes/aptly-docker-compose.rb
@@ -110,12 +110,14 @@ template config_file do
110110 mode '0644'
111111 end
112112
113-log <<-"EOM"
113+log 'aptly-docker-compose post install message' do
114+ message <<-"EOM"
114115 Note: You must execute the following command manually.
115- See #{doc_url}
116- * Start:
117- $ cd #{app_dir}
118- $ docker-compose up -d
119- * Stop
120- $ docker-compose down
116+ See #{doc_url}
117+ * Start:
118+ $ cd #{app_dir}
119+ $ docker-compose up -d
120+ * Stop
121+ $ docker-compose down
121122 EOM
123+end
--- a/cookbooks/apt_utils/spec/recipes/apt-cacher-ng_spec.rb
+++ b/cookbooks/apt_utils/spec/recipes/apt-cacher-ng_spec.rb
@@ -2,7 +2,7 @@
22 # Cookbook Name:: apt_utils
33 # Recipe Spec:: apt-cacher-ng_spec
44 #
5-# Copyright 2015-2017, whitestar
5+# Copyright 2015-2018, whitestar
66 #
77 # Licensed under the Apache License, Version 2.0 (the "License");
88 # you may not use this file except in compliance with the License.
@@ -22,8 +22,8 @@ require_relative '../spec_helper'
2222 describe 'apt_utils::apt-cacher-ng' do
2323 let(:chef_run_on_non_debian) {
2424 ChefSpec::SoloRunner.new(platform: 'centos', version: '7.0') {|node|
25- node.set['apt_utils']['apt-cacher-ng']['CacheDir'] = '/path/to/cache'
26- node.set['apt_utils']['apt-cacher-ng']['LogDir'] = '/path/to/log'
25+ node.normal['apt_utils']['apt-cacher-ng']['CacheDir'] = '/path/to/cache'
26+ node.normal['apt_utils']['apt-cacher-ng']['LogDir'] = '/path/to/log'
2727 }.converge(described_recipe)
2828 }
2929
@@ -39,8 +39,8 @@ describe 'apt_utils::apt-cacher-ng' do
3939
4040 let(:chef_run_on_debian) {
4141 ChefSpec::SoloRunner.new(platform: 'debian', version: '8.1') {|node|
42- node.set['apt_utils']['apt-cacher-ng']['CacheDir'] = '/path/to/cache'
43- node.set['apt_utils']['apt-cacher-ng']['LogDir'] = '/path/to/log'
42+ node.normal['apt_utils']['apt-cacher-ng']['CacheDir'] = '/path/to/cache'
43+ node.normal['apt_utils']['apt-cacher-ng']['LogDir'] = '/path/to/log'
4444 }.converge(described_recipe)
4545 }
4646
--- a/cookbooks/apt_utils/spec/recipes/source_spec.rb
+++ b/cookbooks/apt_utils/spec/recipes/source_spec.rb
@@ -2,7 +2,7 @@
22 # Cookbook Name:: apt_utils
33 # Recipe Spec:: source_spec
44 #
5-# Copyright 2015, whitestar
5+# Copyright 2015-2018, whitestar
66 #
77 # Licensed under the Apache License, Version 2.0 (the "License");
88 # you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@ describe 'apt_utils::source' do
3232
3333 let(:chef_run_on_debian) {
3434 ChefSpec::SoloRunner.new(platform: 'debian', version: '8.1') {|node|
35- node.set['apt_utils']['source']['apt_lines'] = [
35+ node.normal['apt_utils']['source']['apt_lines'] = [
3636 'deb http://cdn.debian.net/debian jessie main contrib non-free',
3737 'deb http://cdn.debian.net/debian jessie-updates main contrib',
3838 ]
--- /dev/null
+++ b/cookbooks/apt_utils/templates/default/etc/cron.d/apt-cacher-ng-local
@@ -0,0 +1,25 @@
1+<%
2+name = 'apt-cacher-ng'
3+
4+conf = node['apt_utils']['apt-cacher-ng']['autopilot']
5+log = "#{conf['log_dir']}/#{name}-local.log"
6+wait_time = conf['wait_time']
7+check_period = conf['check_period']
8+
9+cmd = nil
10+st_cmd = nil
11+if File.exist?('/etc/init.d/apt-cacher-ng')
12+ cmd = '/etc/init.d/apt-cacher-ng restart'
13+ st_cmd = '/etc/init.d/apt-cacher-ng status'
14+else
15+ cmd = 'systemctl restart apt-cacher-ng'
16+ st_cmd = 'systemctl status apt-cacher-ng'
17+end
18+-%>
19+SHELL=/bin/sh
20+PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
21+DATE_F='+%Y-%m-%d %H:%M:%S %z'
22+LOG=<%= log %>
23+
24+@reboot root sleep <%= wait_time %> && date "$DATE_F" > $LOG && <%= cmd %> >> $LOG 2>&1 && <%= st_cmd %> >> $LOG 2>&1
25+<%= check_period %> root /usr/local/bin/restart_acng-local
--- /dev/null
+++ b/cookbooks/apt_utils/templates/default/usr/local/bin/restart_acng-local
@@ -0,0 +1,23 @@
1+#!/bin/sh
2+<%
3+name = 'apt-cacher-ng'
4+
5+conf = node['apt_utils']['apt-cacher-ng']['autopilot']
6+log = "#{conf['log_dir']}/#{name}-local.log"
7+
8+cmd = nil
9+st_cmd = nil
10+if File.exist?('/etc/init.d/apt-cacher-ng')
11+ cmd = '/etc/init.d/apt-cacher-ng restart'
12+ st_cmd = '/etc/init.d/apt-cacher-ng status'
13+else
14+ cmd = 'systemctl restart apt-cacher-ng'
15+ st_cmd = 'systemctl status apt-cacher-ng'
16+end
17+-%>
18+
19+DATE_F='+%Y-%m-%d %H:%M:%S %z'
20+LOG=<%= log %>
21+
22+date "$DATE_F" > $LOG
23+<%= st_cmd %> | grep "Failed to start|Couldn't bind socket" && <%= cmd %> >> $LOG
--- a/cookbooks/apt_utils/version
+++ b/cookbooks/apt_utils/version
@@ -1 +1 @@
1-0.2.6
1+0.3.0
Show on old repository browser