Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation enhancement #222

Closed
jbdamiano opened this issue Jun 25, 2014 · 10 comments
Closed

Installation enhancement #222

jbdamiano opened this issue Jun 25, 2014 · 10 comments

Comments

@jbdamiano
Copy link

Hello,

I have forked your cookbook. I'm trying to switch to your repository to avoid to maintain our cookbook and to have to check your change to report on your fork if needed.

I'm looking to write a wrapper, but I have an issue with our internal organization.
I have to install ES from debian packet located in our internal debian repository.

Do you think that is possible to have an attribute in you cookbook, to avoid to create the ES users, group and the ark installation from the default recipe ?
The wrapper part will be responsible of the installation phase.

If you agree with this I can perform a modification in your cookbook to do this.

Regards,

@karmi
Copy link
Contributor

karmi commented Jun 25, 2014

There's a special recipe for installing from a .deb file. I would like to keep any larger refactorings / reorganization of the cookbook to a new, fresh version, not this one.

@davidski
Copy link

@karmi, is a rewrite of this cookbook underway? While I'm currently using the published version without complaint (and many thanks!), if there's help the community can provide in testing and providing PRs for a next gen version, I'd like to contribute. We can't have the Elasticsearch Puppet folks get all the love! 😉

@karmi
Copy link
Contributor

karmi commented Jun 25, 2014

@davidski Hah, thanks! :) It wasn't started yet, still in a planning stage... I'd like to lay the foundation first, and then it would be awesome to jump on it... I'll try to announce it loudly when something will be available for review and evaluation.

@jbdamiano
Copy link
Author

As the installation could have some company requirement, I think that the installation part could be done in wrapper mode, and keep the configuration from the cookbook. It's for this, I suggest to skip the installation_part from your cookbook

I will plan to add a node[:elasticsearch][:skip_intallation] with a default value to false

The suggested patch is:

From 18352b0bcb5245d22a3714798c60bfb3a5cb0a8a Mon Sep 17 00:00:00 2001
From: Jean-Bernard Damiano <jbdamiano@gmail.com>
Date: Wed, 25 Jun 2014 14:58:54 +0200
Subject: [PATCH] add skip installation

---
 attributes/default.rb |   1 +
 recipes/default.rb    | 116 +++++++++++++++++++++++++++-----------------------
 2 files changed, 64 insertions(+), 53 deletions(-)

diff --git a/attributes/default.rb b/attributes/default.rb
index fc995d6..c7e906e 100644
--- a/attributes/default.rb
+++ b/attributes/default.rb
@@ -21,6 +21,7 @@ default.elasticsearch[:host]          = "http://download.elasticsearch.org"
 default.elasticsearch[:repository]    = "elasticsearch/elasticsearch"
 default.elasticsearch[:filename]      = "elasticsearch-#{node.elasticsearch[:version]}.tar.gz"
 default.elasticsearch[:download_url]  = [node.elasticsearch[:host], node.elasticsearch[:repository], node.elasticsearch[:filename]].join('/')
+default.elasticsearch[:skip_installation] = false

 # === NAMING
 #
diff --git a/recipes/default.rb b/recipes/default.rb
index 30892ce..b8f96a0 100644
--- a/recipes/default.rb
+++ b/recipes/default.rb
@@ -4,34 +4,37 @@ Erubis::Context.send(:include, Extensions::Templates)

 elasticsearch = "elasticsearch-#{node.elasticsearch[:version]}"

-include_recipe "elasticsearch::curl"
-include_recipe "ark"

-# Create user and group
-#
-group node.elasticsearch[:user] do
-  gid node.elasticsearch[:gid]
-  action :create
-  system true
-end
+unless node[:elasticsearch][:skip_installation]
+  include_recipe "elasticsearch::curl"
+  include_recipe "ark"

-user node.elasticsearch[:user] do
-  comment "ElasticSearch User"
-  home    "#{node.elasticsearch[:dir]}/elasticsearch"
-  shell   "/bin/bash"
-  uid     node.elasticsearch[:uid]
-  gid     node.elasticsearch[:user]
-  supports :manage_home => false
-  action  :create
-  system true
-end
+  # Create user and group
+  #
+  group node.elasticsearch[:user] do
+    gid node.elasticsearch[:gid]
+    action :create
+    system true
+  end
+
+  user node.elasticsearch[:user] do
+    comment "ElasticSearch User"
+    home    "#{node.elasticsearch[:dir]}/elasticsearch"
+    shell   "/bin/bash"
+    uid     node.elasticsearch[:uid]
+    gid     node.elasticsearch[:user]
+    supports :manage_home => false
+    action  :create
+    system true
+  end

-# FIX: Work around the fact that Chef creates the directory even for `manage_home: false`
-bash "remove the elasticsearch user home" do
-  user    'root'
-  code    "rm -rf  #{node.elasticsearch[:dir]}/elasticsearch"
-  not_if  { ::File.symlink?("#{node.elasticsearch[:dir]}/elasticsearch") }
-  only_if { ::File.directory?("#{node.elasticsearch[:dir]}/elasticsearch") }
+  # FIX: Work around the fact that Chef creates the directory even for `manage_home: false`
+  bash "remove the elasticsearch user home" do
+    user    'root'
+    code    "rm -rf  #{node.elasticsearch[:dir]}/elasticsearch"
+    not_if  { ::File.symlink?("#{node.elasticsearch[:dir]}/elasticsearch") }
+    only_if { ::File.directory?("#{node.elasticsearch[:dir]}/elasticsearch") }
+  end
 end


@@ -69,35 +72,42 @@ template "/etc/init.d/elasticsearch" do
   owner 'root' and mode 0755
 end

-service "elasticsearch" do
-  supports :status => true, :restart => true
-  action [ :enable ]
-end
-
-# Download, extract, symlink the elasticsearch libraries and binaries
-#
-ark_prefix_root = node.elasticsearch[:dir] || node.ark[:prefix_root]
-ark_prefix_home = node.elasticsearch[:dir] || node.ark[:prefix_home]
-
-ark "elasticsearch" do
-  url   node.elasticsearch[:download_url]
-  owner node.elasticsearch[:user]
-  group node.elasticsearch[:user]
-  version node.elasticsearch[:version]
-  has_binaries ['bin/elasticsearch', 'bin/plugin']
-  checksum node.elasticsearch[:checksum]
-  prefix_root   ark_prefix_root
-  prefix_home   ark_prefix_home
-
-  notifies :start,   'service[elasticsearch]' unless node.elasticsearch[:skip_start]
-  notifies :restart, 'service[elasticsearch]' unless node.elasticsearch[:skip_restart]
-
-  not_if do
-    link   = "#{node.elasticsearch[:dir]}/elasticsearch"
-    target = "#{node.elasticsearch[:dir]}/elasticsearch-#{node.elasticsearch[:version]}"
-    binary = "#{target}/bin/elasticsearch"
+if node[:elasticsearch][:skip_installation]
+  service "elasticsearch" do
+    supports :status => true, :restart => true
+    action [ :nothing ]
+  end
+else
+  service "elasticsearch" do
+    supports :status => true, :restart => true
+    action [ :enable ]
+  end

-    ::File.directory?(link) && ::File.symlink?(link) && ::File.readlink(link) == target && ::File.exists?(binary)
+  # Download, extract, symlink the elasticsearch libraries and binaries
+  #
+  ark_prefix_root = node.elasticsearch[:dir] || node.ark[:prefix_root]
+  ark_prefix_home = node.elasticsearch[:dir] || node.ark[:prefix_home]
+
+  ark "elasticsearch" do
+    url   node.elasticsearch[:download_url]
+    owner node.elasticsearch[:user]
+    group node.elasticsearch[:user]
+    version node.elasticsearch[:version]
+    has_binaries ['bin/elasticsearch', 'bin/plugin']
+    checksum node.elasticsearch[:checksum]
+    prefix_root   ark_prefix_root
+    prefix_home   ark_prefix_home
+
+    notifies :start,   'service[elasticsearch]' unless node.elasticsearch[:skip_start]
+    notifies :restart, 'service[elasticsearch]' unless node.elasticsearch[:skip_restart]
+
+    not_if do
+      link   = "#{node.elasticsearch[:dir]}/elasticsearch"
+      target = "#{node.elasticsearch[:dir]}/elasticsearch-#{node.elasticsearch[:version]}"
+      binary = "#{target}/bin/elasticsearch"
+
+      ::File.directory?(link) && ::File.symlink?(link) && ::File.readlink(link) == target && ::File.exists?(binary)
+    end
   end
 end

-- 
1.9.0

@karmi
Copy link
Contributor

karmi commented Jun 26, 2014

I can see how this is intriguing, but this makes everything about attributes totally crazy, doesn't it? :) The proper solution is to extract the recipes into smaller ones, and tie them together in the elasticsearch::default recipe, and that can be done even in the current state of the cookbook...

@jbdamiano
Copy link
Author

Im my fork I have do this to be able to install debian package
I have added an attribute called `node[:elasticsearch][:installation][:mode] set by default to tar
If I want to install deb package I set it to pkg

You can see a version in my fork in the reset_branch

@jbdamiano
Copy link
Author

Hi,

Did you have time to check the change in the reset_branch branch ?
Do you want to send you a pull request between my branch and your branch to be able to check it it's ok for you ?

With my change I can set node[:elasticsearch][:installation][:mode] to tar, pkg or anything else. In the last case, the wrapper must install elasticsearch. I have written a wrapper based on my branch and I have provisioned our two rec clusters with success.

with the tar mode (by default), nothing change. With pkg it includes your debian or rpm recipes do perform a debian and rpm installation.

Regards,

@brodock
Copy link

brodock commented Mar 10, 2015

I would like to see any solution for this merged.
Current install options are: "use debian package and configure nothing" or "use tar.gz and you can configure whatever you want"

@rryke
Copy link

rryke commented Apr 21, 2015

Checking on status for this. :)

@martinb3
Copy link
Contributor

martinb3 commented Jul 7, 2015

Hello! We've re-written the cookbook using libraries that expose resources and providers, so you shouldn't see this problem on the newer version; it should be much easier to install from packages. We also include package installs in the test suites now. Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants