How to run logstash from exploded jar with JRuby - ruby

I'm not very comfortable with jruby and rvm environments, so I have trouble trying to run logstash with it (it is said to be the fastest way to do so).
What I've tryed :
I installed rvm environement (as a side note, the standard install scripts create a new .bash_profile, which disable the standard .bashrc script when you're on Ubuntu. This can confuse new users like me... I was wondering for several hours why my 'll' alias won't work !)
I uncompressed logstash (jar xvf /logstash-1.1.4-monolithic.jar) in a new directory
I've followed the instructions in https://rvm.io/rvm/install/ as rvm install 1.9.2 (albeit I've also made some try/error/redo manipulations, so I can't remember the exact listing of commands)
Then I tried several commands, but none of them worked :
$ ruby logstash.rb
/home/orabig/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- logstash/agent (LoadError)
from /home/orabig/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from logstash.rb:1:in `<main>'
whereas the following line is returning after some seconds :
jruby-1.7.0 logstash.rb agent -f ../etc/inout.config -v
(the inout.config file is working when invoked with the java commandline as in :)
java -jar (...)/logstash-1.1.4-monolithic.jar agent -f ../etc/inout.config -v
So I'm basically stuck now, because the more I will try random things, the more I'm afraid to mess up my configuration...
Update : On the logstash page (https://github.com/logstash/logstash), it looks like it's working with 1.6.8 ruby version (however it's not clear, and I'm not sure if it makes any difference...)
So I also tried :
$ rvm install 1.6.8
(...)
$ rvm use 1.6.8
$ export JRUBY_OPTS=--1.9
$ ruby logstash.rb agent -f ../etc/inout.config -v
$ jruby-1.6.8 logstash.rb agent -f ../etc/inout.config -v
but nothing happens when I run either of the last two lines...

As the rvm tool will let you know: You have to be in a login shell to use rvm like that.
So, either run bash -login or use rvm to select and run your version of ruby like done in the following:
rvm install 1.7.0 # note that 1.7.0 will also work
export JRUBY_OPTS=--1.9
rvm 1.7.0 do bundle install
rvm 1.7.0 do ruby lib/logstash/runner.rb agent -f ../etc/inout.config -v
This will tell rvm to use jruby-1.7.0 to run your logstash agent.

Related

turn off ruby version warning

Ubuntu 18.04, ruby 2.6.6
Cron jobs submitted for redmine generate warnings that are then mailed to admin, creating a steady stream of emails every 15 minutes:
Subject: Cron <root#mysys> su -l rubyuser -c " cd /opt/redmine/redmine ; bundle exec rake --trace redmine:email:receive_imap RAILS_ENV="production" host=imap.gmail.com port=993 ssl=1 username=issueadmin#someplace.com password=pw folder=Inbox move_on_success=Processed project=Issues status=open tracker=Bug priority=Normal >> /opt/redmine/redmine/log/issues.log 2>&1"
The mail contains the usual ruby warning message:
Unknown ruby interpreter version (do not know how to handle): >=2.3.0,<2.7.0ifBundler::VERSION>=1.12.0.
I have tried turning off the warning using
rvm rvmrc warning ignore allGemfiles
su -l rubyuser -c " cd /opt/redmine/redmine ; rvm rvmrc warning ignore allGemfiles"
but it has no effect.
Can someone tell me how to fix this / turn this off?
This is a system-wide ruby, installed at /usr/local/rvm. It appears to be caused by the Gemfile installed at /opt/redmine/redmine, which contains the line
ruby '>= 2.3.0', '< 2.7.0' if Bundler::VERSION >= '1.12.0'
I've tried tweaking that line a bit but I still get the error.
Matthew Boeh gave me the following answer which solves the immediate issue:
It looks like this is an issue with RVM, which tries to read the
Gemfile to determine which version of Ruby to switch to. It's limited
in what it can parse. I believe if you put a .ruby-version or .rvmrc
in that directory it will ignore the Gemfile.
I added "2.6.6" to a .ruby-version for the project.
The reason may be slightly more nuanced, as rvm doesn't consider 2.6.6 an "official" release for some reason, which may be the reason it complains. It does consider 2.7.0 one. At least that's my recollection; don't have access to the machine right now and I would need to install a 2.7 to find out.

How to fix "Unknown ruby interpreter version (do not know how to handle): RUBY_VERSION."

Today i just want to setup a jekyll Blog on my Mac, and have already install ruby 2.3.0, but when make '$ jekyll serve', it's error. and show this in terminal:
Error information:
Unknown ruby interpreter version (do not know how to handle): RUBY_VERSION.
So it looks like
bundle exec jekyll new
will create the a Gemfile with the line
ruby RUBY_VERSION
I believe you'll want to edit that file to be e.g.
ruby '2.1.1'
Coincidentally today I am also trying to setup Jekyll and am seeing the same problem. I am using RVM and it otherwise works fine (running multiple Rails dev sites locally). When I run env | grep 'RUBY' I get:
$ env | grep 'RUBY'
MY_RUBY_HOME=/Users/myusername/.rvm/rubies/ruby-2.0.0-p247
RUBY_VERSION=ruby-2.0.0-p247
However, I just continued and ran bundle install, then bundle exec jekyll serve and the site booted up without issue.
Seems like there is no variable RUBY_VERSION in your env.
Try in your shell: env | grep 'RUBY'
Output should be like this:
RUBY_VERSION=ruby-2.3.0
If you don't see anything, you need to reinstall ruby.
Use RVM or other ruby version manager. Here is a good manual
I used to have ruby '~> 2.6.3' in Gemfile and got same warning.
I changed it to ruby '2.6.3' and it fixed it.

Trying to uninstall and fresh install Ruby on Ubuntu: do I still have Ruby installed?

I'm coming from Windows to Linux (Ubuntu) so I'm new to the CLI. I had issues trying to install Rails so I figured a fresh install would help. I'm following "Installing Ruby the Correct Way."
I thought I had uninstalled Ruby, but after installing 2.1.4 it still shows some Ruby folders. Have I completely uninstalled Ruby?
Downloading ruby-2.1.4.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/bf9952cdeb3a0c6a5a27745c9b4c0e5e264e92b669b2b08efb363f5156549204
Installing ruby-2.1.4...
Installed ruby-2.1.4 to /home/richard/.rbenv/versions/2.1.4
richard#richard-ThinkPad-T400:~$ rbenv global 2.1.4
richard#richard-ThinkPad-T400:~$ ruby -v
The program 'ruby' can be found in the following packages:
* ruby
* ruby1.8
Try: sudo apt-get install <selected package>
richard#richard-ThinkPad-T400:~$ sudo rbenv global 2.1.4
richard#richard-ThinkPad-T400:~$ ruby -v
The program 'ruby' can be found in the following packages:
* ruby
* ruby1.8
Try: sudo apt-get install <selected package>
Are the "the following packages" on my local system? or are they online?
EDIT
I've been getting this error when I try to install RVM (and some other applications):
GPG signature verification failed for '/home/richard/.rvm/archives/rvm-1.26.0.tgz' - 'https://github.com/wayneeseguin/rvm/releases/download/1.26.0/1.26.0.tar.gz.asc'!
try downloading the signatures:
gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
they can be compared with:
https://rvm.io/mpapis.asc
https://keybase.io/mpapis
Does this have anything to do with it? I wouldn't really think so but I'm a noob.
Don't sudo rbenv anything or you will summon Cthulhu. Use rbenv by itself.
Also, don't randomly follow guides on the internet until you're more familiar with your OS; They go stale, or start out wrong, or don't accurately apply to what you're doing. Instead, go to the source and follow the directions there.
To find out what is installed on your machine, use locate to quickly find Ruby instances. Something like:
locate /bin/ruby | grep -v .rbenv
should narrow down whether multiple Rubies are installed outside the ~/.rbenv directory.
Traditionally, you'll find a normally installed system-wide Ruby in /usr/bin/ruby. A user installed one from source will probably be in /usr/local/bin/ruby unless you specifically said otherwise, probably with a PREFIX= directive.
rbenv will default to installing Ruby in the ~/.rbenv hierarchy since it acts like a sandbox manager and will put all Rubies it installs underneath that directory. RVM, a similar application, will use ~/.rvm, and in both cases, the purpose is to keep them where the user's permissions are sufficient to install and update gems without requiring the use of sudo. For general use, avoid sudo unless you understand what you're about to do, as it can turn a computer into an under-desk heater in seconds.
The shell uses the PATH variable to figure out where to look for executable commands. It sounds like your PATH isn't set correctly. If you followed the directions on the rbenv site, they say how to enable rbenv by modifying your ~/.bash_profile script. Doing that, then closing and reopening your shell should bring rbenv to life.
Following that blog post, you are installing Ruby using a tool called rbenv, and if you only uninstalled one Ruby, that doesn't mean that all Rubies are uninstalled.
The message that you posted shows that it is a local install: Installed ruby-2.1.4 to /home/richard/.rbenv/versions/2.1.4 which is a copy of the 4th line of your message.
You can find out from whence your Ruby executable is being invoked by issuing at the command line:
which ruby
You will then know if the program is available and which it is. Using ruby -v if it is there will tell you the version.
You have done some of these steps and are finding out that your system does not know how to get to the Ruby, if it is indeed installed.
Right now, it is effectively uninstalled, as it is unavailable to your environment.

How do I run a Ruby Gem?

This might seem stupid, but I recently tried to install SASS and followed their instructions:
$ gem install sass
$ sass --watch [...]
So I followed along:
root#server:~# gem install sass
Successfully installed sass-3.1.15
1 gem installed
Installing ri documentation for sass-3.1.15...
Installing RDoc documentation for sass-3.1.15...
root#server:~# sass
bash: sass: command not found
Despite looking around like an idiot trying to find some simple way to run something like gem run sass or some other workaround to make it function, I am more or less at a loss.
It seems that Debian/Ubuntu drops ruby gems into /var/lib/gems/1.8/bin.
So the solution (at least for Ubuntu/Debian) is:
$ sudo -s
# echo 'PATH=/var/lib/gems/1.8/bin:$PATH' > /etc/profile.d/gemspath.sh
# chmod 0755 /etc/profile.d/gemspath.sh
...and then open a new shell session.
(This is fixed in Ubuntu 11.10.)
If you happen to have installed Ruby through rbenv, you'll need to execute the following command
rbenv rehash
On macOS I had to add the gem executable directory to the path.
Add these lines to your ~/.bashrc file, and reopen the terminal to refresh the env vars.
# gem
gembin=`(gem env | sed -n "s/.*EXECUTABLE DIRECTORY: \(.*\)/\1/p")`
export PATH=$gembin:$PATH
If you use macOS and you:
I don't know/care about Ruby.
I just want to run this program.
Why is this so complicated?
Then run:
~/.gem/ruby/*/bin/jekyll
where jekyll is the thing you just installed with gem install.
If you're trying to run a simple WEBrick server for your gem you can do the following after installation:
sass start

Build and run ruby without installing it to system directories

I've cloned the ruby 1.8.7 source tree. I can build ruby. But I can't figure out how to run it without installing it in system directories. How can I do it?
Background: I want to use "git bisect" to figure out which build of Ruby introduced a new behavior in my code. I need to build and run ruby against a test program, multiple times, but I don't want to clobber the ruby that the Debian package installed.
Here's what I get if I try to run the ruby I built from source:
$ ./ruby -e 'puts RUBY_VERSION'
ÀÇ ÀÇ : ÀÇ ÀÇ : cannot open shared object file: No such file or directory - ÀÇ ÀÇ (LoadError)
I've also tried installing it, but not to the system directories, and got a stack trace:
$ ./configure --prefix=/home/wayne/tmp/ruby/installed --exec-prefix=/home/wayne/tmp/ruby/installed
$ make
$ make install
$ /home/wayne/tmp/ruby/installed/bin/ruby -e 'puts RUBY_VERSION'
/home/wayne/tmp/ruby/installed/lib/ruby/1.8/openssl/ssl.rb:26: uninitialized constant OpenSSL::SSL::VERIFY_PEER (NameError)
from /home/wayne/tmp/ruby/installed/lib/ruby/1.8/openssl.rb:23:in `require'
from /home/wayne/tmp/ruby/installed/lib/ruby/1.8/openssl.rb:23
I've got the feeling that I'm close, but a miss is as good as a mile.
rvm is a great tool. and should be able to take care of the heavy lifting for switching between different ruby version (or even sets of gems).
Installation is very easy:
$ gem install rvm && rvm-install
$ echo "if [[ ! -z $HOME/.rvm ]] ; then source $HOME/.rvm ; fi" >> ~/.bash_profile
Then to install a specific version & patch level:
rvm install ruby-1.8.7-p160
Then to switch between versions:
$ rvm 1.8.7-p160
$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 160) [i686-darwin10.0.0]
$ rvm 1.8.7-p174
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.0.0]
When I need to do something like that, I use the chroot command. Create a temporary directory, install ruby into a sbin subdirectory, and chroot into the temp folder. Depending on what you are testing, you may also have to copy some system libraries into the temporary directory tree (before you chroot in).
It's probably easier to use rvm to test your app against different rubies.

Resources