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

Add support for CoreOS #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down
30 changes: 22 additions & 8 deletions recipes/_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions recipes/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOC
Expand All @@ -31,7 +34,8 @@
echo '#{install_checksum} #{install_version}.zip' > 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'
4 changes: 3 additions & 1 deletion recipes/ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOC
Expand Down
16 changes: 16 additions & 0 deletions templates/default/consul-systemd.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Consul Agent
Wants=basic.target
After=basic.target network.target

[Service]
User=<%= @user %>
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