Skip to content
This repository has been archived by the owner on Aug 13, 2020. It is now read-only.

Commit

Permalink
Support to configure environment variables opts
Browse files Browse the repository at this point in the history
  • Loading branch information
spesnova committed May 24, 2016
1 parent 0c67313 commit b7a2b20
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -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
===========

Expand Down
5 changes: 5 additions & 0 deletions attributes/default.rb
Expand Up @@ -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
25 changes: 25 additions & 0 deletions recipes/default.rb
Expand Up @@ -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']
Expand Down
10 changes: 10 additions & 0 deletions spec/mackerel-agent_spec.rb
Expand Up @@ -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 }
Expand Down
6 changes: 6 additions & 0 deletions 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 %>

0 comments on commit b7a2b20

Please sign in to comment.