apt_utils CHANGELOG
===================
+0.3.0
+-----
+- adds the APT Cacher NG autopilot feature.
+- refactoring.
+
0.2.6
-----
- improves server key pair deployment for a aptly service.
--- /dev/null
+GEM
+ remote: https://rubygems.org/
+ specs:
+ chef-api (0.8.0)
+ logify (~> 0.1)
+ mime-types
+ logify (0.2.0)
+ mime-types (3.2.2)
+ mime-types-data (~> 3.2015)
+ mime-types-data (3.2018.0812)
+ stove (6.0.0)
+ chef-api (~> 0.5)
+ logify (~> 0.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ stove
+
+BUNDLED WITH
+ 1.16.0
|`['apt_utils']['aptly']['docker-compose']['etc_dir']`|String||`"#{node['apt_utils']['aptly']['docker-compose']['app_dir']}/etc"`|
|`['apt_utils']['aptly']['docker-compose']['data_dir']`|String|Persistent volume path or nil (unset).|`"#{node['apt_utils']['aptly']['docker-compose']['app_dir']}/data"`|
|`['apt_utils']['aptly']['docker-compose']['config']`|Hash|`docker-compose.yml` configurations.|See `attributes/default.rb`|
+|`['apt_utils']['apt-cacher-ng']['autopilot']['enabled']`|Boolean|APT Cacher NG autopilot feature flag.|`false`|
+|`['apt_utils']['apt-cacher-ng']['autopilot']['log_dir']`|String|log file's directory path.|`'/var/log'`|
+|`['apt_utils']['apt-cacher-ng']['autopilot']['wait_time']`|String|wait time after booted.|`'120s'`|
+|`['apt_utils']['apt-cacher-ng']['autopilot']['check_period']`|String|service check period. `'#'` means inactive.|`'*/5 * * * *'`|
|`['apt_utils']['apt-cacher-ng']['CacheDir']`|String|path to cache directory|`'/var/cache/apt-cacher-ng'`|
|`['apt_utils']['apt-cacher-ng']['LogDir']`|String|path to log directory.|`'/var/log/apt-cacher-ng'`|
|`['apt_utils']['apt-cacher-ng']['Port']`|String|service port number.|`'3142'`|
description 'aptly by docker-compose'
run_list(
+ # see https://osdn.net/projects/metasearch/scm/git/grid-chef-repo/blobs/master/roles/docker-new-repo.rb
'role[docker]',
'recipe[apt_utils::aptly-docker-compose]',
)
require 'foodcritic'
require 'stove/rake_task'
+tpl_cookbook = '00cookbook'
+cookbook_name = File.basename(Dir.pwd)
+
+desc 'Initialize project'
+task :init do
+ next if cookbook_name == tpl_cookbook
+
+ [
+ '.foodcritic',
+ '.rubocop.yml',
+ 'Berksfile',
+ 'concourse.yml',
+ 'fly-vars.yml',
+ 'fly-vars.local.yml',
+ 'Gemfile',
+ 'Gemfile.lock',
+ 'version',
+ ].each {|conf|
+ sh "cp ../#{tpl_cookbook}/#{conf} ./" unless File.exist?(conf)
+ }
+
+ ruby [
+ %(-pne '$_.gsub!(/^cookbook-name: .*$/, "cookbook-name: #{cookbook_name}")'),
+ '-i fly-vars.local.yml',
+ ].join(' ')
+end
+
+desc 'Update project'
+task :update do
+ next if cookbook_name == tpl_cookbook
+
+ [
+ 'Rakefile',
+ 'concourse.yml',
+ 'fly-vars.yml',
+ 'Gemfile',
+ 'Gemfile.lock',
+ ].each {|conf|
+ sh "cp ../#{tpl_cookbook}/#{conf} ./"
+ }
+end
+
+desc 'fly set-pipeline'
task :'set-pipeline' do
sh [
- "fly -t $CC_TARGET sp -p #{File.basename(Dir.pwd)}-cookbook -c concourse.yml",
- '-l fly-vars.yml -l ~/sec/credentials-prod.yml',
+ "fly -t $CC_TARGET sp -p #{cookbook_name}-cookbook -c concourse.yml",
+ '-l fly-vars.yml -l fly-vars.local.yml -l ~/sec/credentials-prod.yml',
].join(' ')
end
+desc 'rake set-pipeline alias'
task sp: 'set-pipeline'
namespace :style do
# Cookbook Name:: apt_utils
# Attributes:: default
#
-# Copyright 2013-2017, whitestar
+# Copyright 2013-2018, whitestar
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
}
default['apt_utils']['aptly']['docker-compose']['config'] = version_2_config
+default['apt_utils']['apt-cacher-ng']['autopilot'] = {
+ 'enabled' => false,
+ 'log_dir' => '/var/log',
+ 'wait_time' => '120s',
+ 'check_period' => '*/5 * * * *', # '#': inactive
+}
default['apt_utils']['apt-cacher-ng']['CacheDir'] = '/var/cache/apt-cacher-ng'
default['apt_utils']['apt-cacher-ng']['LogDir'] = '/var/log/apt-cacher-ng'
default['apt_utils']['apt-cacher-ng']['SupportDir'] = '/usr/lib/apt-cacher-ng'
---
-# $ fly -t $CC_TARGET sp -p apt_utils-cookbook -c concourse.yml -l fly-vars.yml -l ~/sec/credentials-prod.yml
resources:
- name: src-git
type: git
branch: master
paths:
- cookbooks/((cookbook-name))
- git_user: ((git-user-osdn))
private_key: ((git-private-key))
+ git_user: ((git-user-osdn))
#check_every: 1h # default: 1m
- name: chefdk-cache
type: docker-image
--- /dev/null
+---
+cookbook-name: apt_utils
---
-cookbook-name: apt_utils
chefdk-version: 1.6.11
end
depends 'apt'
-depends 'docker-grid', '>= 0.2.7'
+depends 'docker-grid', '>= 0.5.8'
depends 'platform_utils', '>= 0.4.3'
-depends 'ssl_cert', '>= 0.4.1'
+depends 'ssl_cert', '>= 0.4.2'
# Cookbook Name:: apt_utils
# Recipe:: apt-cacher-ng
#
-# Copyright 2013-2017, whitestar
+# Copyright 2013-2018, whitestar
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
::Chef::Recipe.send(:include, PlatformUtils::PackageUtils)
+conf = node['apt_utils']['apt-cacher-ng']
+
if node['platform_family'] == 'debian'
pkg = 'apt-cacher-ng'
user_name = pkg
supports status: true, restart: true, reload: false
end
- directory node['apt_utils']['apt-cacher-ng']['CacheDir'] do
+ directory conf['CacheDir'] do
owner user_name
group user_name
mode '2755'
recursive true
end
- directory node['apt_utils']['apt-cacher-ng']['LogDir'] do
+ directory conf['LogDir'] do
owner user_name
group user_name
mode '2755'
notifies :restart, "service[#{service_name}]"
end
end
+
+# autopilot
+srv = 'apt-cacher-ng'
+template "/etc/cron.d/#{srv}-local" do
+ source "etc/cron.d/#{srv}-local"
+ owner 'root'
+ group 'root'
+ mode '0644'
+ action :delete unless conf['autopilot']['enabled']
+end
+
+template '/usr/local/bin/restart_acng-local' do
+ source 'usr/local/bin/restart_acng-local'
+ owner 'root'
+ group 'root'
+ mode '0755'
+ action :delete unless conf['autopilot']['enabled']
+end
mode '0644'
end
-log <<-"EOM"
+log 'aptly-docker-compose post install message' do
+ message <<-"EOM"
Note: You must execute the following command manually.
- See #{doc_url}
- * Start:
- $ cd #{app_dir}
- $ docker-compose up -d
- * Stop
- $ docker-compose down
+ See #{doc_url}
+ * Start:
+ $ cd #{app_dir}
+ $ docker-compose up -d
+ * Stop
+ $ docker-compose down
EOM
+end
# Cookbook Name:: apt_utils
# Recipe Spec:: apt-cacher-ng_spec
#
-# Copyright 2015-2017, whitestar
+# Copyright 2015-2018, whitestar
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
describe 'apt_utils::apt-cacher-ng' do
let(:chef_run_on_non_debian) {
ChefSpec::SoloRunner.new(platform: 'centos', version: '7.0') {|node|
- node.set['apt_utils']['apt-cacher-ng']['CacheDir'] = '/path/to/cache'
- node.set['apt_utils']['apt-cacher-ng']['LogDir'] = '/path/to/log'
+ node.normal['apt_utils']['apt-cacher-ng']['CacheDir'] = '/path/to/cache'
+ node.normal['apt_utils']['apt-cacher-ng']['LogDir'] = '/path/to/log'
}.converge(described_recipe)
}
let(:chef_run_on_debian) {
ChefSpec::SoloRunner.new(platform: 'debian', version: '8.1') {|node|
- node.set['apt_utils']['apt-cacher-ng']['CacheDir'] = '/path/to/cache'
- node.set['apt_utils']['apt-cacher-ng']['LogDir'] = '/path/to/log'
+ node.normal['apt_utils']['apt-cacher-ng']['CacheDir'] = '/path/to/cache'
+ node.normal['apt_utils']['apt-cacher-ng']['LogDir'] = '/path/to/log'
}.converge(described_recipe)
}
# Cookbook Name:: apt_utils
# Recipe Spec:: source_spec
#
-# Copyright 2015, whitestar
+# Copyright 2015-2018, whitestar
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
let(:chef_run_on_debian) {
ChefSpec::SoloRunner.new(platform: 'debian', version: '8.1') {|node|
- node.set['apt_utils']['source']['apt_lines'] = [
+ node.normal['apt_utils']['source']['apt_lines'] = [
'deb http://cdn.debian.net/debian jessie main contrib non-free',
'deb http://cdn.debian.net/debian jessie-updates main contrib',
]
--- /dev/null
+<%
+name = 'apt-cacher-ng'
+
+conf = node['apt_utils']['apt-cacher-ng']['autopilot']
+log = "#{conf['log_dir']}/#{name}-local.log"
+wait_time = conf['wait_time']
+check_period = conf['check_period']
+
+cmd = nil
+st_cmd = nil
+if File.exist?('/etc/init.d/apt-cacher-ng')
+ cmd = '/etc/init.d/apt-cacher-ng restart'
+ st_cmd = '/etc/init.d/apt-cacher-ng status'
+else
+ cmd = 'systemctl restart apt-cacher-ng'
+ st_cmd = 'systemctl status apt-cacher-ng'
+end
+-%>
+SHELL=/bin/sh
+PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+DATE_F='+%Y-%m-%d %H:%M:%S %z'
+LOG=<%= log %>
+
+@reboot root sleep <%= wait_time %> && date "$DATE_F" > $LOG && <%= cmd %> >> $LOG 2>&1 && <%= st_cmd %> >> $LOG 2>&1
+<%= check_period %> root /usr/local/bin/restart_acng-local
--- /dev/null
+#!/bin/sh
+<%
+name = 'apt-cacher-ng'
+
+conf = node['apt_utils']['apt-cacher-ng']['autopilot']
+log = "#{conf['log_dir']}/#{name}-local.log"
+
+cmd = nil
+st_cmd = nil
+if File.exist?('/etc/init.d/apt-cacher-ng')
+ cmd = '/etc/init.d/apt-cacher-ng restart'
+ st_cmd = '/etc/init.d/apt-cacher-ng status'
+else
+ cmd = 'systemctl restart apt-cacher-ng'
+ st_cmd = 'systemctl status apt-cacher-ng'
+end
+-%>
+
+DATE_F='+%Y-%m-%d %H:%M:%S %z'
+LOG=<%= log %>
+
+date "$DATE_F" > $LOG
+<%= st_cmd %> | grep "Failed to start|Couldn't bind socket" && <%= cmd %> >> $LOG