<commit_before>#  Copyright (c) 2012-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# 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 "omnibus-ctl/version"
require 'json'
require 'fileutils'

# For license checks
require 'io/console'
require 'io/wait'

module Omnibus
  class Ctl

    File::umask(022)

    SV_COMMAND_NAMES = %w[status up down once pause cont hup alarm interrupt quit
                      term kill start stop restart shutdown force-stop
                      force-reload force-restart force-shutdown check usr1 usr2]

    attr_accessor :name, :display_name, :log_exclude, :base_path, :sv_path,
    :service_path, :etc_path, :data_path, :log_path, :command_map, :category_command_map,
    :fh_output, :kill_users, :verbose, :log_path_exclude

    attr_reader :backup_dir, :exe_name


    def initialize(name, merge_service_commands=true, disp_name = nil)
      @name = name
      @service_commands = merge_service_commands
      @display_name = disp_name || name
      @base_path = "/opt/#{name}"
      @sv_path = File.join(@base_path, "sv")
      @service_path = File.join(@base_path, "service")
      @log_path = "/var/log/#{name}"
      @data_path = "/var/opt/#{name}"
      @etc_path = "/etc/#{name}"
      @log_exclude = '(config|lock|@|gzip|tgz|gz)'
      @log_path_exclude = ['*/sasl/*']
      @fh_output = STDOUT
      @kill_users = []
      @verbose = false
      @quiet = false
      @exe_name = File.basename($0)
      @force_exit = false
      @global_pre_hooks = {}

      # Remove SVDIR if it is set
      ENV.delete('SVDIR')

      # backwards compat command map that does not have categories
      @command_map = { }

      # categoired commands that we want by default
      @category_command_map = {
        "general" => {
          "show-config" => {
            :desc => "Show the configuration that would be generated by reconfigure.",
            :arity => 1
          },
          "reconfigure" => {<commit_msg>Explicitly set SVDIR to the service_dir<commit_after>#  Copyright (c) 2012-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# 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 "omnibus-ctl/version"
require 'json'
require 'fileutils'

# For license checks
require 'io/console'
require 'io/wait'

module Omnibus
  class Ctl

    File::umask(022)

    SV_COMMAND_NAMES = %w[status up down once pause cont hup alarm interrupt quit
                      term kill start stop restart shutdown force-stop
                      force-reload force-restart force-shutdown check usr1 usr2]

    attr_accessor :name, :display_name, :log_exclude, :base_path, :sv_path,
    :service_path, :etc_path, :data_path, :log_path, :command_map, :category_command_map,
    :fh_output, :kill_users, :verbose, :log_path_exclude

    attr_reader :backup_dir, :exe_name


    def initialize(name, merge_service_commands=true, disp_name = nil)
      @name = name
      @service_commands = merge_service_commands
      @display_name = disp_name || name
      @base_path = "/opt/#{name}"
      @sv_path = File.join(@base_path, "sv")
      @service_path = File.join(@base_path, "service")
      @log_path = "/var/log/#{name}"
      @data_path = "/var/opt/#{name}"
      @etc_path = "/etc/#{name}"
      @log_exclude = '(config|lock|@|gzip|tgz|gz)'
      @log_path_exclude = ['*/sasl/*']
      @fh_output = STDOUT
      @kill_users = []
      @verbose = false
      @quiet = false
      @exe_name = File.basename($0)
      @force_exit = false
      @global_pre_hooks = {}

      # TODO(ssd) 2017-03-28: Set SVDIR explicitly. Once we fix a bug
      # in our debian support, where we rely on system-installed
      # runit, we can likely change this back to ENV.delete("SVDIR")
      ENV['SVDIR'] = service_path

      # backwards compat command map that does not have categories
      @command_map = { }

      # categoired commands that we want by default
      @category_command_map = {
        "general" => {
          "show-config" => {
            :desc => "Show the configuration that would be generated by reconfigure.",
            :arity => 1
          },
          "reconfigure" => {
{'fraction_non_alphanumeric': 0.1065891472868217, 'fraction_numerical': 0.009689922480620155, 'mean_word_length': 2.9761171032357474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '306072', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1546, 'n_words': 494}