<commit_before>#
# Cookbook Name:: haproxy-ng
# Recipe:: install
#
# Copyright 2015 <NAME>
#
# 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.

case node['haproxy']['install_method']
when 'package'
  package 'haproxy'
when 'ppa'
  apt_repository 'haproxy' do
    uri node['haproxy']['ppa']['uri']
    distribution node['lsb']['codename']
    components ['main']
    keyserver 'keyserver.ubuntu.<EMAIL>'
    key node['haproxy']['ppa']['key']
  end
  package 'haproxy'
when 'source'
  node.default['haproxy']['source']['archive_url'] = [
    node['haproxy']['source']['url'],
    node['haproxy']['source']['version'],
    'src',
    "haproxy-#{node['haproxy']['source']['release']}.tar.gz"
  ].join('/')

  src = node['haproxy']['source']

  src['dependencies'].each do |dep|
    package dep
  end

  download_path = Chef::Config['file_cache_path'] || '/tmp'
  pkg_path = "#{download_path}/haproxy-#{src['release']}.tar.gz"

  execute 'compile-haproxy' do
    cwd "#{download_path}/haproxy-#{src['release']}"
    command <<-EOC
      make #{src['make_args']} && \
      make install
    EOC
    action :nothing
  end

  execute 'extract-haproxy' do
    cwd download_path
    command <<-EOC
      tar xzf #{::File.basename(pkg_path)} -C #{download_path}
    EOC
    action :nothing
    notifies :run, 'execute[compile-haproxy]', :immediately
  end

  remote_file 'haproxy-src-archive' do
    path pkg_path
    source src['archive_url']
    notifies :run, 'execute[extract-haproxy]', :immediately
  end

  directory '/etc/haproxy'

  user 'haproxy' do
    home '/var/lib/haproxy'
    shell '/usr/sbin/nologin'
    system true
  end

  directory '/var/lib/haproxy' do
    owner 'haproxy'
    group 'haproxy'
  end

  svc_provider = Chef::Platform.find_provider_for_node(node, :service)

  cookbook_file '/etc/init/haproxy.conf' do
    source 'haproxy.conf'
    mode '0755'
    not_if do
      svc_provider == Chef::Provider::Service::Systemd
    end
  end

  cookbook_file '/etc/systemd/system/haproxy.service' do
    source 'haproxy.service'
    only_if do
      svc_provider == Chef::Provider::Service::Systemd
    end
  end
else
  Chef::Log.warn 'Unknown install_method for haproxy. Skipping install!'
end<commit_msg>internal provider mapper method changed, see https://github.com/chef/chef/issues/3257<commit_after>#
# Cookbook Name:: haproxy-ng
# Recipe:: install
#
# Copyright 2015 <NAME>
#
# 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.

case node['haproxy']['install_method']
when 'package'
  package 'haproxy'
when 'ppa'
  apt_repository 'haproxy' do
    uri node['haproxy']['ppa']['uri']
    distribution node['lsb']['codename']
    components ['main']
    keyserver 'keyserver.ubuntu.com'
    key node['haproxy']['ppa']['key']
  end

  package 'haproxy'
when 'source'
  node.default['haproxy']['source']['archive_url'] = [
    node['haproxy']['source']['url'],
    node['haproxy']['source']['version'],
    'src',
    "haproxy-#{node['haproxy']['source']['release']}.tar.gz"
  ].join('/')

  src = node['haproxy']['source']

  src['dependencies'].each do |dep|
    package dep
  end

  download_path = Chef::Config['file_cache_path'] || '/tmp'
  pkg_path = "#{download_path}/haproxy-#{src['release']}.tar.gz"

  execute 'compile-haproxy' do
    cwd "#{download_path}/haproxy-#{src['release']}"
    command <<-EOC
      make #{src['make_args']} && \
      make install
    EOC
    action :nothing
  end

  execute 'extract-haproxy' do
    cwd download_path
    command <<-EOC
      tar xzf #{::File.basename(pkg_path)} -C #{download_path}
    EOC
    action :nothing
    notifies :run, 'execute[compile-haproxy]', :immediately
  end

  remote_file 'haproxy-src-archive' do
    path pkg_path
    source src['archive_url']
    notifies :run, 'execute[extract-haproxy]', :immediately
  end

  directory '/etc/haproxy'

  user 'haproxy' do
    home '/var/lib/haproxy'
    shell '/usr/sbin/nologin'
    system true
  end

  directory '/var/lib/haproxy' do
    owner 'haproxy'
    group 'haproxy'
  end

  cookbook_file '/etc/init/haproxy.conf' do
    source 'haproxy.conf'
    mode '0755'
    only_if do
      ::File.directory?('/etc/init')
    end
  end

  cookbook_file '/etc/systemd/system/haproxy.service' do
    source 'haproxy.service'
    only_if do
      ::File.directory?('/etc/systemd/system')
    end
  end
else
  Chef::Log.warn 'Unknown install_method for haproxy. Skipping install!'
end
{'fraction_non_alphanumeric': 0.1424860853432282, 'fraction_numerical': 0.005194805194805195, 'mean_word_length': 3.7289473684210526, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1311286', 'n_tokens_mistral': 1899, 'n_tokens_neox': 1827, 'n_words': 470}