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

Feature/windows support #154

Closed
wants to merge 11 commits into from
52 changes: 42 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Installs and configures [Consul][1] client, server and UI.
- RHEL 6.5, 7.0
- Ubuntu 12.04, 14.04
- Arch Linux
- Windows

## Attributes

Expand Down Expand Up @@ -44,14 +45,26 @@ Installs and configures [Consul][1] client, server and UI.
<tr>
<td><tt>['consul']['install_method']</tt></td>
<td>String</td>
<td>Method to install consul with when using default recipe: binary or source</td>
<td><tt>binary</tt></td>
<td>Method to install consul with when using default recipe: 'binary', 'source' or 'windows'</td>
<td>
\*nix: <tt> binary</tt></br>
Windows: <tt>binary</tt>
</td>
</tr>
<tr>
<td><tt>['consul']['choco_source']</tt></td>
<td>String</td>
<td>Source to use for fetching the chocolatey package. Defaults to the chocolatey public feed</td>
<td><tt>https://chocolatey.org/api/v2/</tt></td>
</tr>
<tr>
<td><tt>['consul']['install_dir']</tt></td>
<td>String</td>
<td>Directory to install binary to.</td>
<td><tt>/usr/local/bin</tt></td>
<td>
\*nix: <tt>/usr/local/bin</tt></br>
Windows: <tt>{chocolatey_install_dir}\lib\consul.{consul_version}</tt>
</td>
</tr>
<tr>
<td><tt>['consul']['service_mode']</tt></td>
Expand All @@ -69,13 +82,29 @@ Installs and configures [Consul][1] client, server and UI.
<td><tt>['consul']['data_dir']</tt></td>
<td>String</td>
<td>Location to store consul's data in</td>
<td><tt>/var/lib/consul</tt></td>
<td>
\*nix: <tt>/var/lib/consul</tt></br>
Windows: <tt>C:\ProgramData\consul\data</tt>
</td>
</tr>
<tr>
<td><tt>['consul']['config_dir']</tt></td>
<td>String</td>
<td>Location to read service definitions from (directoy will be created)</td>
<td><tt>/etc/consul.d</tt></td>
<td>
\*nix: <tt>/etc/consul.d</tt></br>
Windows: <tt>C:\ProgramData\consul\config</tt>
</td>
</tr>
<tr>
<td><tt>['consul']['etc_config_dir']</tt></td>
<td>String</td>
<td>Misc. configuration directory that might need to be execute during service start</td>
<td>
Debian: <tt>/etc/default/consul</tt></br>
Windows: <tt>{chocolatey_install_dir}\lib\consul.{consul_version}\tools</tt></br>
Other: <tt>/etc/sysconfig/consul</tt>
</td>
</tr>
<tr>
<td><tt>['consul']['servers']</tt></td>
Expand Down Expand Up @@ -117,8 +146,7 @@ Installs and configures [Consul][1] client, server and UI.
<td><tt>['consul']['log_level']</tt></td>
<td>String</td>
<td>
The level of logging to show after the Consul agent has started.
Available: "trace", "debug", "info", "warn", "err"
The level of logging to show after the Consul agent has started: 'trace', 'debug', 'info', 'warn', or 'err'
</td>
<td><tt>info</tt></td>
</tr>
Expand All @@ -137,8 +165,11 @@ Installs and configures [Consul][1] client, server and UI.
<tr>
<td><tt>['consul']['init_style']</tt></td>
<td>String</td>
<td>Service init mode for running consul as: init, runit or systemd</td>
<td><tt>init</tt></td>
<td>Service init mode for running consul as: 'init', 'runit', 'systemd', or 'windows'</td>
<td>
\*nix: <tt>init</tt></br>
Windows: <tt>windows</tt>
</td>
</tr>
<tr>
<td><tt>['consul']['service_user']</tt></td>
Expand Down Expand Up @@ -389,7 +420,8 @@ the application.

### consul::ui
Installing the separate Consul UI simply requires you to include
the `consul::ui` recipe in your node's `run_list`.
the `consul::ui` recipe in your node's `run_list`. Consul UI is not supported
on Windows platform.

```json
{
Expand Down
37 changes: 25 additions & 12 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
default['consul']['version'] = '0.5.2'
default['consul']['install_method'] = 'binary'
default['consul']['install_dir'] = '/usr/local/bin'
default['consul']['checksums'] = {
default['consul']['choco_source'] = "https://chocolatey.org/api/v2/"

default['consul']['checksums'] = {
'0.3.0_darwin_amd64' => '9dfbc70c01ebbc3e7dba0e4b31baeddbdcbd36ef99f5ac87ca6bbcc7405df405',
'0.3.0_linux_386' => '2513496374f8f15bda0da4da33122e93f82ce39f661ee3e668c67a5b7e98fd5f',
'0.3.0_linux_amd64' => 'da1337ab3b236bad19b791a54a8df03a8c2a340500a392000c21608696957b15',
Expand Down Expand Up @@ -66,15 +68,23 @@
default['consul']['use_packagecloud_repo'] = true

# Service attributes
default['consul']['service_mode'] = 'bootstrap'
default['consul']['service_mode'] = 'bootstrap'
default['consul']['retry_on_join'] = false

# In the cluster mode, set the default cluster size to 3
default['consul']['bootstrap_expect'] = 3
default['consul']['data_dir'] = '/var/lib/consul'
default['consul']['config_dir'] = '/etc/consul.d'
default['consul']['logfile'] = '/var/log/consul.log'

case node['platform_family']
when 'windows'
default['consul']['install_method'] = 'windows'
default['consul']['init_style'] = 'windows'
default['consul']['config_dir'] = "#{ENV['SystemDrive']}\\ProgramData\\consul\\config"
default['consul']['data_dir'] = "#{ENV['SystemDrive']}\\ProgramData\\consul\\data"
default['consul']['install_dir'] = "#{ChocolateyHelpers.chocolatey_install}\\lib\\consul.#{node['consul']['version']}"
default['consul']['etc_config_dir'] = "#{ChocolateyHelpers.chocolatey_install}\\lib\\consul.#{node['consul']['version']}\\tools"
when 'debian'
default['consul']['etc_config_dir'] = '/etc/default/consul'
when 'rhel'
Expand All @@ -84,14 +94,17 @@
end

default['consul']['servers'] = []
default['consul']['init_style'] = 'init' # 'init', 'runit', 'systemd'
default['consul']['init_style'] = 'init' # 'init', 'runit', 'systemd', 'windows'

case node['consul']['init_style']
when 'runit' || 'systemd'
default['consul']['service_user'] = 'consul'
default['consul']['service_user'] = 'consul'
default['consul']['service_group'] = 'consul'
when 'windows'
default['consul']['service_user'] = 'Administrator'
default['consul']['service_group'] = 'Administrators'
else
default['consul']['service_user'] = 'root'
default['consul']['service_user'] = 'root'
default['consul']['service_group'] = 'root'
end

Expand All @@ -105,28 +118,28 @@
}

# Consul DataBag
default['consul']['data_bag'] = 'consul'
default['consul']['data_bag'] = 'consul'
default['consul']['data_bag_encrypt_item'] = 'encrypt'

# Gossip encryption
default['consul']['encrypt_enabled'] = false
default['consul']['encrypt'] = nil
default['consul']['encrypt'] = nil
# TLS support
default['consul']['verify_incoming'] = false
default['consul']['verify_outgoing'] = false
# Cert in pem format
default['consul']['ca_cert'] = nil
default['consul']['ca_path'] = "%{config_dir}/ca.pem"
default['consul']['ca_cert'] = nil
default['consul']['ca_path'] = "%{config_dir}/ca.pem"
default['consul']['cert_file'] = nil
default['consul']['cert_path'] = "%{config_dir}/cert.pem"
# Cert in pem format. It can be unique for each host
default['consul']['key_file'] = nil
default['consul']['key_file'] = nil
default['consul']['key_file_path'] = "%{config_dir}/key.pem"

# Optionally bind to a specific interface
default['consul']['bind_interface'] = nil
default['consul']['bind_interface'] = nil
default['consul']['advertise_interface'] = nil
default['consul']['client_interface'] = nil
default['consul']['client_interface'] = nil

# UI attributes
default['consul']['client_addr'] = '0.0.0.0'
Expand Down
5 changes: 5 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
supports 'ubuntu', '= 12.04'
supports 'ubuntu', '= 14.04'
supports 'arch'
supports 'windows'

recommends 'chef-provisioning'

Expand All @@ -27,3 +28,7 @@
depends 'runit'
depends 'yum-repoforge'
depends 'packagecloud'

# for windows
depends 'windows'
depends "chocolatey"
8 changes: 6 additions & 2 deletions providers/check_def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
end

file new_resource.path do
user node['consul']['service_user']
group node['consul']['service_group']
if node['platform'] == 'windows'
rights :full_control, node['consul']['service_user'], :applies_to_children => true
else
user node['consul']['service_user']
group node['consul']['service_group']
end
mode 0600
content new_resource.to_json

Expand Down
8 changes: 6 additions & 2 deletions providers/event_watch_def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@

action :create do
file new_resource.path do
user node['consul']['service_user']
group node['consul']['service_group']
if node['platform'] == 'windows'
rights :full_control, node['consul']['service_user'], :applies_to_children => true
else
user node['consul']['service_user']
group node['consul']['service_group']
end
mode 0600
content new_resource.to_json

Expand Down
8 changes: 6 additions & 2 deletions providers/key_watch_def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@

action :create do
file new_resource.path do
user node['consul']['service_user']
group node['consul']['service_group']
if node['platform'] == 'windows'
rights :full_control, node['consul']['service_user'], :applies_to_children => true
else
user node['consul']['service_user']
group node['consul']['service_group']
end
mode 0600
content new_resource.to_json

Expand Down
8 changes: 6 additions & 2 deletions providers/service_def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ def set_updated
action :create do
set_updated do
file new_resource.path do
user node['consul']['service_user']
group node['consul']['service_group']
if node['platform'] == 'windows'
rights :full_control, node['consul']['service_user'], :applies_to_children => true
else
user node['consul']['service_user']
group node['consul']['service_group']
end
mode 0600
content new_resource.to_json
action :create
Expand Down
8 changes: 6 additions & 2 deletions providers/service_watch_def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@

action :create do
file new_resource.path do
user node['consul']['service_user']
group node['consul']['service_group']
if node['platform'] == 'windows'
rights :full_control, node['consul']['service_user'], :applies_to_children => true
else
user node['consul']['service_user']
group node['consul']['service_group']
end
mode 0600
content new_resource.to_json

Expand Down
51 changes: 39 additions & 12 deletions recipes/_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,60 @@
consul_directories = []
consul_directories << node['consul']['data_dir']
consul_directories << node['consul']['config_dir']
consul_directories << '/var/lib/consul'

# Select service user & group
if node['consul']['init_style'] == 'runit'
case node['consul']['init_style']
when 'runit'
include_recipe 'runit::default'
consul_directories << '/var/log/consul'
when 'windows'
# already added, move along
else
consul_directories << '/var/lib/consul'
end


# Select service user & group
consul_user = node['consul']['service_user']
consul_group = node['consul']['service_group']

# Create service user
user "consul service user: #{consul_user}" do
not_if { consul_user == 'root' }
username consul_user
home '/dev/null'
shell '/bin/false'
comment 'consul service user'
case node['consul']['init_style']
when 'windows'
user "consul service user: #{consul_user}" do
not_if { consul_user == 'Administrator' }
username consul_user
comment 'consul service user'
end
else
user "consul service user: #{consul_user}" do
not_if { consul_user == 'root' }
username consul_user
home '/dev/null'
shell '/bin/false'
comment 'consul service user'
end
end

# Create service group
group "consul service group: #{consul_group}" do
not_if { consul_group == 'root' }
not_if { consul_group == 'root' && node['platform'] != 'windows'}
not_if { consul_group == 'Administrators' && node['platform'] == 'windows'}
group_name consul_group
members consul_user
append true
end


# Create service directories
consul_directories.uniq.each do |dirname|
directory dirname do
owner consul_user
group consul_group
if node['platform'] == 'windows'
rights :full_control, node['consul']['service_user'], :applies_to_children => true
recursive true
else
user consul_user
group consul_group
end
mode 0755
end

Expand Down Expand Up @@ -249,4 +270,10 @@
subscribes :restart, "file[#{consul_config_filename}]"
subscribes :restart, "link[#{Chef::Consul.active_binary(node)}]"
end
when 'windows'
# Windows service for consul has been create by Chocolatey and
# config is managed by the chocolatey package
service 'consul' do
subscribes :restart, "file[#{consul_config_filename}]"
end
end
2 changes: 2 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
include_recipe 'consul::install_binary'
when 'source'
include_recipe 'consul::install_source'
when 'windows'
include_recipe 'consul::install_windows'
when 'packages'
include_recipe 'consul::install_packages'
else
Expand Down
Loading