<commit_before>#
# Cookbook Name:: dynatrace
# Recipes:: server_uninstall
#
# Copyright 2015, Dynatrace
#

require 'json'
require 'net/https'

include_recipe 'dynatrace::upgrade_system'
include_recipe 'java'
include_recipe 'dynatrace::dynatrace_user'

name = 'Uninstall Dynatrace Server'

installer_bitsize = node['dynatrace']['server']['installer']['bitsize']

sizing = node['dynatrace']['server']['sizing']

collector_port = node['dynatrace']['server']['collector_port']

do_pwh_connection       = node['dynatrace']['server']['do_pwh_connection']
pwh_connection_hostname = node['dynatrace']['server']['pwh_connection']['hostname']
pwh_connection_port     = node['dynatrace']['server']['pwh_connection']['port']
pwh_connection_dbms     = node['dynatrace']['server']['pwh_connection']['dbms']
pwh_connection_database = node['dynatrace']['server']['pwh_connection']['database']
pwh_connection_username = node['dynatrace']['server']['pwh_connection']['username']
pwh_connection_password = node['dynatrace']['server']['pwh_connection']['password']

dynatrace_owner = node['dynatrace']['owner']
dynatrace_group = node['dynatrace']['group']

if platform_family?('debian', 'fedora', 'rhel')
  installer_prefix_dir = node['dynatrace']['server']['linux']['installer']['prefix_dir']
  installer_file_name  = node['dynatrace']['server']['linux']['installer']['file_name']
  installer_file_url   = node['dynatrace']['server']['linux']['installer']['file_url']

  installer_cache_dir = "#{Chef::Config['file_cache_path']}/dynatrace"
  installer_path      = "#{installer_cache_dir}/#{installer_file_name}"

  service      = 'dynaTraceServer'
  ini_files    = ['dtserver.ini', 'dtfrontendserver.ini']
  init_scripts = ['dynaTraceBackendServer', 'dynaTraceFrontendServer', service]
else
  # Unsupported
end

service "#{name}" do
  service_name service
  supports     :status => true
  action       [:stop, :disable]
end

ruby_block "Stop any running instance of dynatrace service: dtserver" do
  block do
    Dynatrace::Helpers.stop_processes('dtserver', node['platform_family'])
  end
end

ruby_block "Stop any running instance of dynatrace service: dtfrontendserver" do
  block do
    Dynatrace::Helpers.stop_processes('dtfrontendserver', node['platform_family'])
  end
end

directory "Delete the installer cache directory #{installer_cache_dir}" do
  path   installer_cache_dir
  recursive true
  action :delete
end

dir2del = installer_prefix_dir + '/dynatrace'

#remove directory using symlink
cmd2exec = "rm -rf \"$(readlink #{dir2del})\""
#puts 'remove directory content using symlink: ' + cmd2exec
#%x[ #{cmd2exec} ]
execute "Remove directory content using symlink: #{cmd2exec}" do
  command cmd2exec
end

#remove symlink
cmd2exec = "rm -rf #{dir2del}"
#puts 'remove symlink: ' + cmd2exec
#%x[ #{cmd2exec} ]
execute "Remove symlink: #{cmd2exec}" do
  command cmd2exec
end

directory "Delete the installation directory #{dir2del}" do
  path      dir2del
  recursive true<commit_msg>JLT-153139 Recipe to cleanup machines with installed Dynatrace components (server/collector/agents). Fixed method to determine processes to kill. Easy Travel uninstall reorganized.<commit_after>#
# Cookbook Name:: dynatrace
# Recipes:: server_uninstall
#
# Copyright 2015, Dynatrace
#

require 'json'
require 'net/https'

include_recipe 'dynatrace::upgrade_system'
include_recipe 'java'
include_recipe 'dynatrace::dynatrace_user'

name = 'Uninstall Dynatrace Server'

installer_bitsize = node['dynatrace']['server']['installer']['bitsize']

sizing = node['dynatrace']['server']['sizing']

collector_port = node['dynatrace']['server']['collector_port']

do_pwh_connection       = node['dynatrace']['server']['do_pwh_connection']
pwh_connection_hostname = node['dynatrace']['server']['pwh_connection']['hostname']
pwh_connection_port     = node['dynatrace']['server']['pwh_connection']['port']
pwh_connection_dbms     = node['dynatrace']['server']['pwh_connection']['dbms']
pwh_connection_database = node['dynatrace']['server']['pwh_connection']['database']
pwh_connection_username = node['dynatrace']['server']['pwh_connection']['username']
pwh_connection_password = node['dynatrace']['server']['pwh_connection']['password']

dynatrace_owner = node['dynatrace']['owner']
dynatrace_group = node['dynatrace']['group']

if platform_family?('debian', 'fedora', 'rhel')
  installer_prefix_dir = node['dynatrace']['server']['linux']['installer']['prefix_dir']
  installer_file_name  = node['dynatrace']['server']['linux']['installer']['file_name']
  installer_file_url   = node['dynatrace']['server']['linux']['installer']['file_url']

  installer_cache_dir = "#{Chef::Config['file_cache_path']}/dynatrace"
  installer_path      = "#{installer_cache_dir}/#{installer_file_name}"

  service      = 'dynaTraceServer'
  ini_files    = ['dtserver.ini', 'dtfrontendserver.ini']
  init_scripts = ['dynaTraceBackendServer', 'dynaTraceFrontendServer', service]
else
  # Unsupported
end

service "#{name}" do
  service_name service
  supports     :status => true
  action       [:stop, :disable]
end

ruby_block "Stop any running instance of dynatrace service: dtserver" do
  block do
    Dynatrace::Helpers.stop_processes('dtserver', node['platform_family'])
  end
end

ruby_block "Stop any running instance of dynatrace service: dtfrontendserver" do
  block do
    Dynatrace::Helpers.stop_processes('dtfrontendserver', node['platform_family'])
  end
end

directory "Delete the installer cache directory #{installer_cache_dir}" do
  path   installer_cache_dir
  recursive true
  action :delete
end

dir2del = installer_prefix_dir + '/dynatrace'

#remove directory using symlink
cmd2exec = "rm -rf \"$(readlink #{dir2del})\""
execute "Remove directory content using symlink: #{cmd2exec}" do
  command cmd2exec
end

#remove symlink
cmd2exec = "rm -rf #{dir2del}"
execute "Remove symlink: #{cmd2exec}" do
  command cmd2exec
end

directory "Delete the installation directory #{dir2del}" do
  path      dir2del
  recursive true
{'fraction_non_alphanumeric': 0.14646380203979267, 'fraction_numerical': 0.006687844841999665, 'mean_word_length': 7.1498637602179835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4909676', 'n_tokens_mistral': 1911, 'n_tokens_neox': 1900, 'n_words': 394}