Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use configfile instead of hardcoding values into init file #12

Merged
merged 1 commit into from
Jun 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions recipes/service.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# Determine servers to connect to
server_conn = node[:consul][:servers].map{|s| "-join=#{s}"}.join(' ')
require 'json'

# Determine service params
service_config = {}
service_config['data_dir'] = node[:consul][:data_dir]

case node[:consul][:service_mode]
when 'bootstrap'
service_params = '-server -bootstrap'
service_config['server'] = true
service_config['bootstrap'] = true
when 'server'
service_params = "-server #{server_conn}"
service_config['server'] = true
service_config['start_join'] = node[:consul][:servers]
when 'client'
service_params = server_conn
service_config['start_join'] = node[:consul][:servers]
else
raise 'node[:consul][:service_mode] must be "bootstrap", "server", or "client"'
end

if node[:consul][:serve_ui]
service_params = "#{service_params} -ui-dir #{node[:consul][:ui_dir]} -client #{node[:consul][:client_addr]}"
service_config[:ui_dir] = node[:consul][:ui_dir]
service_config[:client_addr] = node[:consul][:client_addr]
end

directory node[:consul][:config_dir]
Expand All @@ -24,12 +29,18 @@
mode 0755
variables(
consul_binary: "#{node[:consul][:install_dir]}/consul",
data_dir: node[:consul][:data_dir],
config_dir: node[:consul][:config_dir],
service_params: service_params
)
end

file node[:consul][:config_dir] + "/default.json" do
user "root"
group "root"
mode "0600"
action :create
content JSON.pretty_generate(service_config, quirks_mode: true)
end

service 'consul' do
supports status: true, restart: true, reload: true
action [:enable, :start]
Expand Down
2 changes: 1 addition & 1 deletion templates/default/consul-init.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# * Multi Datacenter
### END INIT INFO

CMD="<%= @consul_binary %> agent <%= @service_params %> -data-dir <%= @data_dir %> -config-dir <%= @config_dir %>"
CMD="<%= @consul_binary %> agent -config-dir <%= @config_dir %>"
NAME="consul"

PIDFILE="/var/run/$NAME.pid"
Expand Down