diff --git a/attributes/default.rb b/attributes/default.rb index 30d5f7a9..f07fca05 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -17,7 +17,7 @@ default[:consul][:base_url] = 'https://dl.bintray.com/mitchellh/consul/' default[:consul][:version] = '0.4.1' -default[:consul][:install_dir] = '/usr/local/bin' +default[:consul][:install_dir] = (node[:platform] == 'coreos' ? '/opt/bin' : '/usr/local/bin') default[:consul][:checksums] = { '0.4.1_darwin_amd64' => '957fe9ba27bbaf99539cd534db8ac8ec4c9fa1c6b3b4675d0c0eb3a7fbfb646c', '0.4.1_linux_386' => 'a496d6fd8ff5b460aea50be5d20fbd95cb5d30e9018259a0540273a17fae1c25', diff --git a/metadata.rb b/metadata.rb index 9e23e9dd..0ad75556 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'Apache v2.0' description 'Installs/Configures consul' long_description 'Installs/Configures consul' -version '0.6.0' +version '0.6.1' recipe 'consul', 'Installs and starts consul service.' recipe 'consul::install_binary', 'Installs consul service from binary.' diff --git a/recipes/_service.rb b/recipes/_service.rb index 2b0c7abd..c8613a93 100644 --- a/recipes/_service.rb +++ b/recipes/_service.rb @@ -98,14 +98,28 @@ content JSON.pretty_generate(service_config, quirks_mode: true) end -template '/etc/init.d/consul' do - source 'consul-init.erb' - mode 0755 - variables( - consul_binary: "#{node[:consul][:install_dir]}/consul", - config_dir: node[:consul][:config_dir], - ) - notifies :restart, 'service[consul]', :immediately +if node[:platform] == "coreos" + template '/etc/systemd/system/consul.service' do + source 'consul-systemd.erb' + mode 0755 + variables( + user: consul_user, + group: consul_group, + consul_binary: "#{node[:consul][:install_dir]}/consul", + config_dir: node[:consul][:config_dir], + ) + notifies :restart, 'service[consul]', :immediately + end +else + template '/etc/init.d/consul' do + source 'consul-init.erb' + mode 0755 + variables( + consul_binary: "#{node[:consul][:install_dir]}/consul", + config_dir: node[:consul][:config_dir], + ) + notifies :restart, 'service[consul]', :immediately + end end service 'consul' do diff --git a/recipes/install.rb b/recipes/install.rb index 0fd36df3..889ff789 100644 --- a/recipes/install.rb +++ b/recipes/install.rb @@ -19,8 +19,11 @@ install_arch = node[:kernel][:machine] =~ /x86_64/ ? 'amd64' : '386' install_version = [node[:consul][:version], node[:os], install_arch].join('_') install_checksum = node[:consul][:checksums].fetch(install_version) +install_dir = node[:consul][:install_dir] -package "unzip" +package "unzip" do + not_if "which unzip" +end bash "Fetch consul for #{install_version}" do code < sha256sums sha256sum -c --status sha256sums unzip "#{install_version}.zip" -mv consul /usr/local/bin +mkdir -p #{install_dir} +mv consul #{install_dir} EOC end include_recipe 'consul::_service' diff --git a/recipes/ui.rb b/recipes/ui.rb index 252cc3ea..e3f41290 100644 --- a/recipes/ui.rb +++ b/recipes/ui.rb @@ -16,7 +16,9 @@ install_version = [node[:consul][:version], 'web_ui'].join('_') install_checksum = node[:consul][:checksums].fetch(install_version) -package "unzip" +package "unzip" do + not_if "which unzip" +end bash "Fetch consul UI for #{install_version}" do code < +Group=<%= @group %> +ExecStart=<%= @consul_binary %> agent -config-dir <%= @config_dir %> +ExecReload=/bin/kill -HUP $MAINPID +KillMode=process +Restart=on-failure +RestartSec=42s + +[Install] +WantedBy=multi-user.target