From b7a2b2023b3395df5c20ef16a8817bd6af50e3a6 Mon Sep 17 00:00:00 2001 From: Seigo Uchida Date: Tue, 24 May 2016 16:01:18 +0900 Subject: [PATCH] Support to configure environment variables opts --- README.md | 11 +++++++++++ attributes/default.rb | 5 +++++ recipes/default.rb | 25 +++++++++++++++++++++++++ spec/mackerel-agent_spec.rb | 10 ++++++++++ templates/env_file.erb | 6 ++++++ 5 files changed, 57 insertions(+) create mode 100644 templates/env_file.erb diff --git a/README.md b/README.md index fe4cc6e..1bb24cd 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,17 @@ default['mackerel-agent']['conf']['roles'] = nil default['mackerel-agent']['start_on_setup'] = false ``` +### Configure environment variable options +You can configure environment variable options via the following attributes. +(These all attributes are set to `nil` by default) + +``` +default['mackerel-agent']['env_opts']['other_opts'] = nil +default['mackerel-agent']['env_opts']['auto_retirement'] = nil +default['mackerel-agent']['env_opts']['http_proxy'] = nil +default['mackerel-agent']['env_opts']['mackerel_agent_plugin_meta'] = nil +``` + Development =========== diff --git a/attributes/default.rb b/attributes/default.rb index 42a3f5a..2d64f63 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -8,3 +8,8 @@ default['mackerel-agent']['start_on_setup'] = true default['mackerel-agent']['plugins']['package-action'] = :upgrade + +default['mackerel-agent']['env_opts']['other_opts'] = nil +default['mackerel-agent']['env_opts']['auto_retirement'] = nil +default['mackerel-agent']['env_opts']['http_proxy'] = nil +default['mackerel-agent']['env_opts']['mackerel_agent_plugin_meta'] = nil diff --git a/recipes/default.rb b/recipes/default.rb index e5c720b..3df1d09 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -71,6 +71,31 @@ end end +env_file_path = '' +if platform?('centos') or platform?('redhat') or platform?('amazon') + env_file_path = '/etc/sysconfig/mackerel-agent' +elsif platform?('debian') or platform?('ubuntu') + env_file_path = '/etc/default/mackerel-agent' +end + +template env_file_path do + source 'env_file.erb' + owner 'root' + group 'root' + mode 0644 + backup false + variables({ + other_opts: node['mackerel-agent']['env_opts']['other_opts'], + auto_retirement: node['mackerel-agent']['env_opts']['auto_retirement'], + http_proxy: node['mackerel-agent']['env_opts']['http_proxy'], + mackerel_agent_plugin_meta: node['mackerel-agent']['env_opts']['mackerel_agent_plugin_meta'], + }) + if node['mackerel-agent']['start_on_setup'] + notifies :restart, 'service[mackerel-agent]' + end + action :create +end + service 'mackerel-agent' do supports :status => true, :restart => true if node['mackerel-agent']['start_on_setup'] diff --git a/spec/mackerel-agent_spec.rb b/spec/mackerel-agent_spec.rb index e563b42..fcc83b6 100644 --- a/spec/mackerel-agent_spec.rb +++ b/spec/mackerel-agent_spec.rb @@ -12,6 +12,16 @@ it { should be_file } end +env_file_path = '' +if ['centos', 'redhat', 'amazon'].include?(os[:family]) + env_file_path = '/etc/sysconfig/mackerel-agent' +elsif ['debian', 'ubuntu'].include?(os[:family]) + env_file_path = '/etc/default/mackerel-agent' +end +describe file(env_file_path) do + it { should be_file } +end + #default package is not install mackerel-agent-plugins describe package('mackerel-agent-plugins') do it { should_not be_installed } diff --git a/templates/env_file.erb b/templates/env_file.erb new file mode 100644 index 0000000..86a34fb --- /dev/null +++ b/templates/env_file.erb @@ -0,0 +1,6 @@ +# This file is managed by chef +# DO NOT modify this file directly +<% if @other_opts %>OTHER_OPTS=<%= @other_opts %><% end %> +<% if @auto_retirement %>AUTO_RETIREMENT=<%= @auto_retirement %><% end %> +<% if @http_proxy %>HTTP_PROXY=<%= @http_proxy %><% end %> +<% if @mackerel_agent_plugin_meta %>MACKEREL_AGENT_PLUGIN_META=<%= @mackerel_agent_plugin_meta %><% end %>