Skip to content

Commit

Permalink
Add remove action for plugin
Browse files Browse the repository at this point in the history
Per #264, add remove action. We still have no way of upgrading.
  • Loading branch information
martinb3 committed Oct 16, 2015
1 parent 51386a0 commit b854711
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,13 @@ end
Actions: `:install`, `:remove`

Installs or removes a plugin to a given elasticsearch instance and plugin
directory.
directory. Please note that there is currently no way to upgrade an existing
plugin using commandline tools, so we haven't exposed that feature here either.
Furthermore, there isn't a way to determine if a plugin is compatible with ES or
even what version it is. So once we install a plugin to a directory, we
generally assume that is the desired one and we don't touch it further.

See https://github.com/elastic/cookbook-elasticsearch/issues/264 for more info.

When running a single instance per machine (VM, etc), it's typically
sufficient to rely on the default value of `plugin_dir`:
Expand Down
22 changes: 22 additions & 0 deletions libraries/provider_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,27 @@ class Provider::ElasticsearchPlugin < Chef::Provider::LWRPBase
end
end
end # action

action :remove do
name = new_resource.plugin_name

fail 'Could not determine the plugin directory. Please set plugin_dir on this resource.' unless new_resource.plugin_dir
converge_by("install plugin #{name}") do
plugin_exists = begin
Dir.entries(new_resource.plugin_dir).any? do |plugin|
next if plugin =~ /^\./
name.include? plugin
end
rescue
false
end

if plugin_exists
# automatically raises on error, logs command output
shell_out!("#{new_resource.bindir}/plugin -remove #{name}".split(' '), user: new_resource.user, group: new_resource.group)
new_resource.updated_by_last_action(true)
end
end
end # action
end # provider
end # chef class

0 comments on commit b854711

Please sign in to comment.