I am running Logstash 1.4.1, comparing to the latest, I can't find anywhere in my installation folders contains gem information (versus the latest code in github has those gembag.rb, Gemfile etc..)

My current issue is I need to use several gems that Logstash doesn't have out of box, simply require 'gemname' seems doesn't work. Could anyone direct me to the readings that explains how to add these 3rd party gems or show me some sample codes which can do this.

Thanks very much!

up vote 9 down vote accepted
cd /opt/logstash
env GEM_HOME=vendor/bundle/jruby/1.9 GEM_PATH="" java -jar vendor/jar/jruby-complete-1.7.11.jar -S gem install gemname

If you're installing a local gem file, put the path to the file in GEM_PATH.

  • That's a fantastic solution @Alain. I guess even with latest logstash this is still doable? – James Jiang Oct 24 '14 at 1:06
  • I just did this on my 1.4.0 logstash install. The latest is 1.4.2, which shouldn't have changed too much... – Alain Collins Oct 24 '14 at 1:08
  • just confirmed it is running on 1.4.2 as well – schadr Jan 6 '15 at 17:56

Logstash version agnostic script (can also be used for logstash 6.0.0):

env GEM_HOME=$$(echo /usr/share/logstash/vendor/bundle/jruby/*/) /opt/logstash/vendor/jruby/bin/jruby /opt/logstash/vendor/jruby/bin/gem install PACKAGE_NAME -v PACKAGE_VERSION

In fact, here is the full script to both install a gem and append package metadata to the gemfile:

env GEM_HOME=$$(echo /usr/share/logstash/vendor/bundle/jruby/*/) /opt/logstash/vendor/jruby/bin/jruby /opt/logstash/vendor/jruby/bin/gem install PACKAGE_NAME -v PACKAGE_VERSION
echo 'gem \"PACKAGE_NAME\", \"PACKAGE_VERSION\"' >> /usr/share/logstash/Gemfile

Logstash may change JRuby version in the future. For instance, JRuby 2.3.0 is used in logstash 6.0.0. The script above does not require you to change JRuby version in the path when upgrading logstash.

For example:

env GEM_HOME=vendor/bundle/jruby/1.9 vendor/jruby/bin/jruby vendor/jruby/bin/gem install zookeeper -v 1.4.11 -V

edit Gemfile:

gem "zookeeper", "1.4.11"

This is what worked for me in logstash 2.0.

env GEM_HOME=/opt/logstash/vendor/bundle/jruby/1.9 /opt/logstash/vendor/jruby/bin/jruby /opt/logstash/vendor/jruby/bin/gem install PACKAGE_NAME -v PACKAGE_VERSION

Then I had to edit /opt/logstash/Gemfile to include the line:

gem "PACKAGE_NAME", "PACKAGE_VERSION"

I know we also did a yum install ruby-devel at some point along the way, but I don't remember if that was needed for this to work.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.