diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2019-07-15 20:57:01 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2019-07-15 20:57:01 -0700 |
commit | 940f27de6acaca411ed349b77f45254f887224f3 (patch) | |
tree | 95bbce5a03979c9b48d03dde7d332ae9fa3b1853 /lib/chef/application/client.rb | |
parent | f046ceca7f21ee61d7386e21779a6f60e7bdc49f (diff) | |
download | chef-940f27de6acaca411ed349b77f45254f887224f3.tar.gz |
create application base class for de-duplication
all of the changes in this commit should be mechanical and identical
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/application/client.rb')
-rw-r--r-- | lib/chef/application/client.rb | 175 |
1 files changed, 2 insertions, 173 deletions
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb index 1e1b76de15..e8a5242aac 100644 --- a/lib/chef/application/client.rb +++ b/lib/chef/application/client.rb @@ -17,25 +17,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -require_relative "../application" -require_relative "../client" -require_relative "../config" -require_relative "../daemon" -require_relative "../log" -require_relative "../config_fetcher" +require_relative "base" require_relative "../handler/error_report" require_relative "../workstation_config_loader" -require_relative "../mixin/shell_out" -require "chef-config/mixin/dot_d" -require "mixlib/archive" unless defined?(Mixlib::Archive) require "uri" unless defined?(URI) -require_relative "../dist" -require "license_acceptance/cli_flags/mixlib_cli" -class Chef::Application::Client < Chef::Application - include Chef::Mixin::ShellOut - include ChefConfig::Mixin::DotD - include LicenseAcceptance::CLIFlags::MixlibCLI +class Chef::Application::Client < Chef::Application::Base # Mimic self_pipe sleep from Unicorn to capture signals safely SELF_PIPE = [] # rubocop:disable Style/MutableConstant @@ -45,77 +32,6 @@ class Chef::Application::Client < Chef::Application long: "--config CONFIG", description: "The configuration file to use." - option :config_option, - long: "--config-option OPTION=VALUE", - description: "Override a single configuration option.", - proc: lambda { |option, existing| - (existing ||= []) << option - existing - } - - option :formatter, - short: "-F FORMATTER", - long: "--format FORMATTER", - description: "The output format to use.", - proc: lambda { |format| Chef::Config.add_formatter(format) } - - option :force_logger, - long: "--force-logger", - description: "Use logger output instead of formatter output.", - boolean: true, - default: false - - option :force_formatter, - long: "--force-formatter", - description: "Use formatter output instead of logger output.", - boolean: true, - default: false - - option :profile_ruby, - long: "--[no-]profile-ruby", - description: "Dump complete Ruby call graph stack of entire #{Chef::Dist::PRODUCT} run (expert only).", - boolean: true, - default: false - - option :color, - long: "--[no-]color", - boolean: true, - default: true, - description: "Use colored output, defaults to enabled." - - option :log_level, - short: "-l LEVEL", - long: "--log_level LEVEL", - description: "Set the log level (auto, trace, debug, info, warn, error, fatal).", - proc: lambda { |l| l.to_sym } - - option :log_location, - short: "-L LOGLOCATION", - long: "--logfile LOGLOCATION", - description: "Set the log file location, defaults to STDOUT - recommended for daemonizing.", - proc: nil - - option :help, - short: "-h", - long: "--help", - description: "Show this help message.", - on: :tail, - boolean: true, - show_options: true, - exit: 0 - - option :user, - short: "-u USER", - long: "--user USER", - description: "User to set privilege to.", - proc: nil - - option :group, - short: "-g GROUP", - long: "--group GROUP", - description: "Group to set privilege to.", - proc: nil - unless Chef::Platform.windows? option :daemonize, short: "-d [WAIT]", @@ -131,40 +47,11 @@ class Chef::Application::Client < Chef::Application description: "Set the PID file location, for the #{Chef::Dist::CLIENT} daemon process. Defaults to /tmp/chef-client.pid.", proc: nil - option :lockfile, - long: "--lockfile LOCKFILE", - description: "Set the lockfile location. Prevents multiple client processes from converging at the same time.", - proc: nil - - option :interval, - short: "-i SECONDS", - long: "--interval SECONDS", - description: "Run #{Chef::Dist::CLIENT} periodically, in seconds.", - proc: lambda { |s| s.to_i } - option :once, long: "--once", description: "Cancel any interval or splay options, run #{Chef::Dist::CLIENT} once and exit.", boolean: true - option :json_attribs, - short: "-j JSON_ATTRIBS", - long: "--json-attributes JSON_ATTRIBS", - description: "Load attributes from a JSON file or URL.", - proc: nil - - option :node_name, - short: "-N NODE_NAME", - long: "--node-name NODE_NAME", - description: "The node name for this client.", - proc: nil - - option :splay, - short: "-s SECONDS", - long: "--splay SECONDS", - description: "The splay time for running at intervals, in seconds.", - proc: lambda { |s| s.to_i } - option :chef_server_url, short: "-S CHEFSERVERURL", long: "--server CHEFSERVERURL", @@ -188,30 +75,6 @@ class Chef::Application::Client < Chef::Application long: "--named-run-list NAMED_RUN_LIST", description: "Use a policyfile's named run list instead of the default run list." - option :environment, - short: "-E ENVIRONMENT", - long: "--environment ENVIRONMENT", - description: "Set the #{Chef::Dist::PRODUCT} environment on the node." - - option :version, - short: "-v", - long: "--version", - description: "Show #{Chef::Dist::PRODUCT} version.", - boolean: true, - proc: lambda { |v| puts "#{Chef::Dist::PRODUCT}: #{::Chef::VERSION}" }, - exit: 0 - - option :override_runlist, - short: "-o RunlistItem,RunlistItem...", - long: "--override-runlist RunlistItem,RunlistItem...", - description: "Replace current run list with specified items for a single run.", - proc: lambda { |items| - items = items.split(",") - items.compact.map do |item| - Chef::RunList::RunListItem.new(item) - end - } - option :runlist, short: "-r RunlistItem,RunlistItem...", long: "--runlist RunlistItem,RunlistItem...", @@ -223,17 +86,6 @@ class Chef::Application::Client < Chef::Application end } - option :why_run, - short: "-W", - long: "--why-run", - description: "Enable whyrun mode.", - boolean: true - - option :client_fork, - short: "-f", - long: "--[no-]fork", - description: "Fork #{Chef::Dist::CLIENT} process." - option :recipe_url, long: "--recipe-url=RECIPE_URL", description: "Pull down a remote archive of recipes and unpack it to the cookbook cache. Only used in local mode." @@ -263,11 +115,6 @@ class Chef::Application::Client < Chef::Application description: "Refuse to load a config file and use defaults. This is for development and not a stable API.", boolean: true - option :run_lock_timeout, - long: "--run-lock-timeout SECONDS", - description: "Set maximum duration to wait for another client run to finish, default is indefinitely.", - proc: lambda { |s| s.to_i } - if Chef::Platform.windows? option :fatal_windows_admin_check, short: "-A", @@ -276,11 +123,6 @@ class Chef::Application::Client < Chef::Application boolean: true end - option :minimal_ohai, - long: "--minimal-ohai", - description: "Only run the bare minimum Ohai plugins #{Chef::Dist::PRODUCT} needs to function.", - boolean: true - option :listen, long: "--[no-]listen", description: "Whether a local mode (-z) server binds to a port.", @@ -313,8 +155,6 @@ class Chef::Application::Client < Chef::Application IMMEDIATE_RUN_SIGNAL = "1".freeze RECONFIGURE_SIGNAL = "H".freeze - attr_reader :chef_client_json - # Reconfigure the chef client # Re-open the JSON attributes and load them into the node def reconfigure @@ -412,10 +252,6 @@ class Chef::Application::Client < Chef::Application Ohai::Log.use_log_devices( Chef::Log ) end - def setup_application - Chef::Daemon.change_privilege - end - def setup_signal_handlers super @@ -521,13 +357,6 @@ class Chef::Application::Client < Chef::Application end end - def unforked_interval_error_message - "Unforked #{Chef::Dist::CLIENT} interval runs are disabled by default." + - "\nConfiguration settings:" + - ("\n interval = #{Chef::Config[:interval]} seconds" if Chef::Config[:interval]).to_s + - "\nEnable #{Chef::Dist::CLIENT} interval runs by setting `:client_fork = true` in your config file or adding `--fork` to your command line options." - end - def fetch_recipe_tarball(url, path) Chef::Log.trace("Download recipes tarball from #{url} to #{path}") if File.exist?(url) |