Class: Chef::Provider::Launchd
- Inherits:
-
Chef::Provider
- Object
- Chef::Provider
- Chef::Provider::Launchd
- Extended by:
- Forwardable
- Defined in:
- lib/chef/provider/launchd.rb
Instance Attribute Summary
Attributes inherited from Chef::Provider
#action, #after_resource, #current_resource, #logger, #new_resource, #run_context
Instance Method Summary collapse
- #define_resource_requirements ⇒ Object
- #file_content ⇒ Object
- #file_content? ⇒ Boolean
- #gen_hash ⇒ Object
- #gen_path_from_type ⇒ Object
- #load_current_resource ⇒ Object
- #manage_agent?(action) ⇒ Boolean
- #manage_plist(action, &block) ⇒ Object
- #manage_service(action) ⇒ Object
- #path ⇒ Object private
Methods inherited from Chef::Provider
action, action_description, action_descriptions, #action_nothing, #check_resource_semantics!, #cleanup_after_converge, #compile_and_converge_action, #converge_by, #converge_if_changed, #cookbook_name, #description, #events, include_resource_dsl?, include_resource_dsl_module, #initialize, #introduced, #load_after_resource, #node, #process_resource_requirements, provides, provides?, #recipe_name, #requirements, #resource_collection, #resource_updated?, #run_action, #set_updated_status, supports?, use, use_inline_resources, #validate_required_properties!, #whyrun_mode?, #whyrun_supported?
Methods included from Mixin::Provides
#provided_as, #provides, #provides?
Methods included from Mixin::DescendantsTracker
#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited
Methods included from Mixin::LazyModuleInclude
#descendants, #include, #included
Methods included from Mixin::PowershellOut
#powershell_out, #powershell_out!
Methods included from Mixin::WindowsArchitectureHelper
#assert_valid_windows_architecture!, #disable_wow64_file_redirection, #forced_32bit_override_required?, #is_i386_process_on_x86_64_windows?, #node_supports_windows_architecture?, #node_windows_architecture, #restore_wow64_file_redirection, #valid_windows_architecture?, #with_os_architecture, #wow64_architecture_override_required?, #wow64_directory
Methods included from DSL::Secret
#default_secret_config, #default_secret_service, #secret, #with_secret_config, #with_secret_service
Methods included from DSL::RenderHelpers
#render_json, #render_toml, #render_yaml
Methods included from DSL::ReaderHelpers
#parse_file, #parse_json, #parse_toml, #parse_yaml
Methods included from DSL::Powershell
Methods included from DSL::RegistryHelper
#registry_data_exists?, #registry_get_subkeys, #registry_get_values, #registry_has_subkeys?, #registry_key_exists?, #registry_value_exists?
Methods included from DSL::ChefVault
#chef_vault, #chef_vault_item, #chef_vault_item_for_environment
Methods included from DSL::DataQuery
#data_bag, #data_bag_item, #search, #tagged?
Methods included from EncryptedDataBagItem::CheckEncrypted
Methods included from DSL::PlatformIntrospection
#older_than_win_2012_or_8?, #platform?, #platform_family?, #value_for_platform, #value_for_platform_family
Methods included from DSL::Recipe
#exec, #have_resource_class_for?, #resource_class_for
Methods included from DSL::Definitions
add_definition, #evaluate_resource_definition, #has_resource_definition?
Methods included from DSL::Resources
add_resource_dsl, remove_resource_dsl
Methods included from DSL::Cheffish
Methods included from DSL::RebootPending
Methods included from DSL::IncludeRecipe
Methods included from Mixin::NotifyingBlock
#notifying_block, #subcontext_block
Methods included from DSL::DeclareResource
#build_resource, #declare_resource, #delete_resource, #delete_resource!, #edit_resource, #edit_resource!, #find_resource, #find_resource!, #resources, #with_run_context
Methods included from DSL::Compliance
#include_input, #include_profile, #include_waiver
Constructor Details
This class inherits a constructor from Chef::Provider
Instance Method Details
#define_resource_requirements ⇒ Object
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/chef/provider/launchd.rb', line 128 def define_resource_requirements requirements.assert( :create, :create_if_missing, :delete, :enable, :disable ) do |a| type = new_resource.type a.assertion { %w{daemon agent}.include?(type.to_s) } error_msg = "type must be daemon or agent." a. Chef::Exceptions::ValidationFailed, error_msg end end |
#file_content ⇒ Object
143 144 145 146 |
# File 'lib/chef/provider/launchd.rb', line 143 def file_content plist_hash = new_resource.plist_hash || gen_hash ::Plist::Emit.dump(plist_hash) unless plist_hash.nil? end |
#file_content? ⇒ Boolean
139 140 141 |
# File 'lib/chef/provider/launchd.rb', line 139 def file_content? !!file_content end |
#gen_hash ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/chef/provider/launchd.rb', line 148 def gen_hash return nil unless new_resource.program || new_resource.program_arguments { "label" => "Label", "program" => "Program", "program_arguments" => "ProgramArguments", "abandon_process_group" => "AbandonProcessGroup", "associated_bundle_identifiers" => "AssociatedBundleIdentifiers", "debug" => "Debug", "disabled" => "Disabled", "enable_globbing" => "EnableGlobbing", "enable_transactions" => "EnableTransactions", "environment_variables" => "EnvironmentVariables", "exit_timeout" => "ExitTimeout", "ld_group" => "GroupName", "hard_resource_limits" => "HardResourceLimits", "inetd_compatibility" => "inetdCompatibility", "init_groups" => "InitGroups", "keep_alive" => "KeepAlive", "launch_events" => "LaunchEvents", "launch_only_once" => "LaunchOnlyOnce", "limit_load_from_hosts" => "LimitLoadFromHosts", "limit_load_to_hosts" => "LimitLoadToHosts", "limit_load_to_session_type" => "LimitLoadToSessionType", "low_priority_io" => "LowPriorityIO", "mach_services" => "MachServices", "nice" => "Nice", "on_demand" => "OnDemand", "process_type" => "ProcessType", "queue_directories" => "QueueDirectories", "root_directory" => "RootDirectory", "run_at_load" => "RunAtLoad", "sockets" => "Sockets", "soft_resource_limits" => "SoftResourceLimits", "standard_error_path" => "StandardErrorPath", "standard_in_path" => "StandardInPath", "standard_out_path" => "StandardOutPath", "start_calendar_interval" => "StartCalendarInterval", "start_interval" => "StartInterval", "start_on_mount" => "StartOnMount", "throttle_interval" => "ThrottleInterval", "time_out" => "TimeOut", "umask" => "Umask", "username" => "UserName", "wait_for_debugger" => "WaitForDebugger", "watch_paths" => "WatchPaths", "working_directory" => "WorkingDirectory", }.each_with_object({}) do |(key, val), memo| memo[val] = new_resource.send(key) if new_resource.send(key) end end |
#gen_path_from_type ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/chef/provider/launchd.rb', line 38 def gen_path_from_type types = { "daemon" => "/Library/LaunchDaemons/#{label}.plist", "agent" => "/Library/LaunchAgents/#{label}.plist", } types[type] end |
#load_current_resource ⇒ Object
34 35 36 |
# File 'lib/chef/provider/launchd.rb', line 34 def load_current_resource current_resource = Chef::Resource::Launchd.new(new_resource.name) end |
#manage_agent?(action) ⇒ Boolean
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/chef/provider/launchd.rb', line 110 def manage_agent?(action) # Gets UID of console_user and converts to string. console_user = Etc.getpwuid(::File.stat("/dev/console").uid).name root = console_user == "root" agent = type == "agent" invalid_action = %i{delete disable enable restart}.include?(action) lltstype = "" if new_resource.limit_load_to_session_type lltstype = new_resource.limit_load_to_session_type end invalid_type = lltstype != "LoginWindow" if root && agent && invalid_action && invalid_type logger.trace("#{label}: Aqua LaunchAgents shouldn't be loaded as root") return false end true end |
#manage_plist(action, &block) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/chef/provider/launchd.rb', line 79 def manage_plist(action, &block) if source cookbook_file path do cookbook_name = new_resource.cookbook if new_resource.cookbook copy_properties_from(new_resource, :backup, :group, :mode, :owner, :source) action(action) only_if { manage_agent?(action) } instance_eval(&block) if block_given? end else file path do copy_properties_from(new_resource, :backup, :group, :mode, :owner) content(file_content) if file_content? action(action) only_if { manage_agent?(action) } instance_eval(&block) if block_given? end end end |
#manage_service(action) ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/chef/provider/launchd.rb', line 99 def manage_service(action) plist_path = path macosx_service label do service_name(new_resource.label) if new_resource.label plist(plist_path) if plist_path copy_properties_from(new_resource, :session_type) action(action) only_if { manage_agent?(action) } end end |
#path ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
202 203 204 |
# File 'lib/chef/provider/launchd.rb', line 202 def path @path ||= new_resource.path || gen_path_from_type end |