<commit_before>#
# Copyright 2014 <NAME> <<EMAIL>>
# Copyright 2014 Bloomberg Finance L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'json'

# Configure directories
consul_directories = []
consul_directories << node['consul']['data_dir']
consul_directories << node['consul']['config_dir']
consul_directories << '/var/lib/consul'

# Select service user & group
case node['consul']['init_style']
when 'runit'
  include_recipe 'runit::default'

  consul_user = node['consul']['service_user']
  consul_group = node['consul']['service_group']
  consul_directories << '/var/log/consul'
else
  consul_user = 'root'
  consul_group = 'root'
end

# 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'
end

# Create service group
group "consul service group: #{consul_group}" do
  not_if { consul_group == 'root' }
  group_name consul_group
  members consul_user
  append true
end

# Create service directories
consul_directories.each do |dirname|
  directory dirname do
    owner consul_user
    group consul_group
    mode 0755
  end
end

# Determine service params
service_config = {}
service_config['data_dir'] = node['consul']['data_dir']
num_cluster = node['consul']['bootstrap_expect'].to_i

case node['consul']['service_mode']
when 'bootstrap'
  service_config['server'] = true
  service_config['bootstrap'] = true
when 'cluster'
  service_config['server'] = true
  if num_cluster > 1
    service_config['bootstrap_expect'] = num_cluster
    service_config['start_join'] = node['consul']['servers']
  else
    service_config['bootstrap'] = true
  end
when 'server'
  service_config['server'] = true
  service_config['start_join'] = node['consul']['servers']
when 'client'
  service_config['start_join'] = node['consul']['servers']
else
  Chef::Application.fatal! %Q(node['consul']['service_mode'] must be "bootstrap", "server", or "client")<commit_msg>Updated unkown `service_mode` error message<commit_after>#
# Copyright 2014 <NAME> <<EMAIL>>
# Copyright 2014 Bloomberg Finance L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'json'

# Configure directories
consul_directories = []
consul_directories << node['consul']['data_dir']
consul_directories << node['consul']['config_dir']
consul_directories << '/var/lib/consul'

# Select service user & group
case node['consul']['init_style']
when 'runit'
  include_recipe 'runit::default'

  consul_user = node['consul']['service_user']
  consul_group = node['consul']['service_group']
  consul_directories << '/var/log/consul'
else
  consul_user = 'root'
  consul_group = 'root'
end

# 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'
end

# Create service group
group "consul service group: #{consul_group}" do
  not_if { consul_group == 'root' }
  group_name consul_group
  members consul_user
  append true
end

# Create service directories
consul_directories.each do |dirname|
  directory dirname do
    owner consul_user
    group consul_group
    mode 0755
  end
end

# Determine service params
service_config = {}
service_config['data_dir'] = node['consul']['data_dir']
num_cluster = node['consul']['bootstrap_expect'].to_i

case node['consul']['service_mode']
when 'bootstrap'
  service_config['server'] = true
  service_config['bootstrap'] = true
when 'cluster'
  service_config['server'] = true
  if num_cluster > 1
    service_config['bootstrap_expect'] = num_cluster
    service_config['start_join'] = node['consul']['servers']
  else
    service_config['bootstrap'] = true
  end
when 'server'
  service_config['server'] = true
  service_config['start_join'] = node['consul']['servers']
when 'client'
  service_config['start_join'] = node['consul']['servers']
else
  Chef::Application.fatal! %Q(node['consul']['service_mode'] must be "bootstrap", "cluster", "server", or "client")
{'fraction_non_alphanumeric': 0.12240458770021752, 'fraction_numerical': 0.006723353767055566, 'mean_word_length': 5.291044776119403, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1159747', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1543, 'n_words': 464}