Hello,
I believe I managed to reproduce the cause of your issue - the warnings initially seem to be a bit of a red herring (they're warnings, not errors, right?) which is how I found your post
I'm unable to install logstash on a brand new Ubuntu 18.04 VM myself, using AdoptOpenJDK 11.0.7+10. The initial apt error is a bit cryptic:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
logstash
0 upgraded, 1 newly installed, 0 to remove and 52 not upgraded.
Need to get 167 MB of archives.
After this operation, 295 MB of additional disk space will be used.
Get:1 https://artifacts.elastic.co/packages/7.x/apt stable/main amd64 logstash all 1:7.7.1-1 [167 MB]
Fetched 167 MB in 4s (44.4 MB/s)
Selecting previously unselected package logstash.
(Reading database ... 82148 files and directories currently installed.)
Preparing to unpack .../logstash_1%3a7.7.1-1_all.deb ...
Unpacking logstash (1:7.7.1-1) ...
Setting up logstash (1:7.7.1-1) ...
Using provided startup.options file: /etc/logstash/startup.options
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
2020-06-11T15:41:06.296Z [main] WARN FilenoUtil : Native subprocess control requires open access to sun.nio.ch
Pass '--add-opens java.base/sun.nio.ch=org.jruby.dist' or '=org.jruby.core' to enable.
Errno::EBADF: Bad file descriptor - systemctl
spawn at org/jruby/RubyProcess.java:1635
spawn at org/jruby/RubyKernel.java:1658
popen_run at /usr/share/logstash/vendor/jruby/lib/ruby/stdlib/open3.rb:202
popen3 at /usr/share/logstash/vendor/jruby/lib/ruby/stdlib/open3.rb:98
execute at /usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/pleaserun-0.0.31/lib/pleaserun/detector.rb:74
detect_systemd at /usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/pleaserun-0.0.31/lib/pleaserun/detector.rb:29
detect_platform at /usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/pleaserun-0.0.31/lib/pleaserun/detector.rb:24
detect at /usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/pleaserun-0.0.31/lib/pleaserun/detector.rb:18
setup_defaults at /usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/pleaserun-0.0.31/lib/pleaserun/cli.rb:153
execute at /usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/pleaserun-0.0.31/lib/pleaserun/cli.rb:119
run at /usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/command.rb:67
run at /usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/pleaserun-0.0.31/lib/pleaserun/cli.rb:114
run at /usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/clamp-0.6.5/lib/clamp/command.rb:132
<main> at /usr/share/logstash/lib/systeminstall/pleasewrap.rb:28
Unable to install system startup script for Logstash.
chmod: cannot access '/etc/default/logstash': No such file or directory
dpkg: error processing package logstash (--configure):
installed logstash package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
logstash
W: --force-yes is deprecated, use one of the options starting with --allow instead.
E: Sub-process /usr/bin/dpkg returned an error code (1)
The problem seems to actually be https://github.com/jruby/jruby/issues/5766 because using the test provided in that issue I got the following:
ubuntu@ip-10-62-220-120:~$ ruby -r open3 -e 'Open3.popen3("ls")'
ubuntu@ip-10-62-220-120:~$ /usr/share/logstash/vendor/jruby/bin/jruby -r open3 -e 'Open3.popen3("ls")'
2020-06-11T16:06:36.824Z [main] WARN FilenoUtil : Native subprocess control requires open access to sun.nio.ch
Pass '--add-opens java.base/sun.nio.ch=org.jruby.dist' or '=org.jruby.core' to enable.
Errno::EBADF: Bad file descriptor - ls
spawn at org/jruby/RubyProcess.java:1635
spawn at org/jruby/RubyKernel.java:1658
popen_run at /usr/share/logstash/vendor/jruby/lib/ruby/stdlib/open3.rb:202
popen3 at /usr/share/logstash/vendor/jruby/lib/ruby/stdlib/open3.rb:98
<main> at -e:1
So the issue failing the install is actually a jruby issue preventing open3.popen3
from working
Rather confusingly, following the warning (not error!) about reflections doesn't help all that much:
ubuntu@ip-10-62-220-120:~$ JAVA_OPTS='--add-opens java.base/sun.nio.ch=org.jruby.dist' /usr/share/logstash/vendor/jruby/bin/jruby -r open3 -e 'Open3.popen3("ls")'
Errno::EBADF: Bad file descriptor - ls
spawn at org/jruby/RubyProcess.java:1635
spawn at org/jruby/RubyKernel.java:1658
popen_run at /usr/share/logstash/vendor/jruby/lib/ruby/stdlib/open3.rb:202
popen3 at /usr/share/logstash/vendor/jruby/lib/ruby/stdlib/open3.rb:98
<main> at -e:1
but digging into the endless jruby issues on GitHub provides some magic that does fix this:
ubuntu@ip-10-62-220-120:~$ JAVA_OPTS='--add-opens java.base/sun.nio.ch=org.jruby.dist --add-opens java.base/java.io=org.jruby.dist' /usr/share/logstash/vendor/jruby/bin/jruby -r open3 -e 'Open3.popen3("ls")'
Whew! So far, so good, right? The only way I've managed to get this install to work is by taking the startup.options
file from the logstash package, adding a new line with JAVA_OPTS='--add-opens java.base/sun.nio.ch=org.jruby.dist --add-opens java.base/java.io=org.jruby.dist'
and then installing logstash ensuring that apt does not overwrite the startup.options file Logstash does not need this anymore but the pleaserun
installer seems to.
Even more confusingly, when you add the --add-opens
environment variable to that file, the shell script attempts to evaluate the arguments as variables (because they are in the form of foo=bar
) and throws a shell substitution error which send you down another rabbit hole entirely if you run apt-get manually in hopes of figuring this out I've been struggling with this for a good few hours now and still haven't managed to successfully install using ansible but when I drop into a shell everything seems to be a-ok:
ubuntu@ip-10-62-220-114:~$ sudo apt-get -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold install logstash=1:7.7.1-1
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
logstash
0 upgraded, 1 newly installed, 0 to remove and 54 not upgraded.
Need to get 167 MB of archives.
After this operation, 295 MB of additional disk space will be used.
Get:1 https://artifacts.elastic.co/packages/7.x/apt stable/main amd64 logstash all 1:7.7.1-1 [167 MB]
Fetched 167 MB in 3s (53.2 MB/s)
Selecting previously unselected package logstash.
(Reading database ... 82148 files and directories currently installed.)
Preparing to unpack .../logstash_1%3a7.7.1-1_all.deb ...
Unpacking logstash (1:7.7.1-1) ...
Setting up logstash (1:7.7.1-1) ...
Configuration file '/etc/logstash/startup.options'
==> File on system created by you or by a script.
==> File also in package provided by package maintainer.
==> Keeping old config file as default.
Using provided startup.options file: /etc/logstash/startup.options
/usr/share/logstash/bin/system-install: line 56: java.base/sun.nio.ch: bad substitution
/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/pleaserun-0.0.31/lib/pleaserun/platform/base.rb:112: warning: constant ::Fixnum is deprecated
Successfully created system startup script for Logstash
ubuntu@ip-10-62-220-114:~$ echo $?
0
Hope this helps...
@warkolm is this something that can be fixed in the debian package itself? Seems to me like the --add-opens
options are required for pleaserun
with the version of jruby provided with logstash...
Thanks,
Simon
edit: I've still not managed to figure out why the installation fails when orchestrated by ansible but I had to resort to pre-populating /etc/logstash/defaults before installing the package and calling /usr/share/logstash/bin/system-install /etc/logstash/startup.options
after the package is installed - it's rather odd (and I don't have the time to dig into this further at the moment) but it does work.
edit 2: after a lot of further debugging I think I've got this figured out now. The /usr/share/logstash/bin/system-install: line 56: java.base/sun.nio.ch: bad substitution
error is actually fatal when installing from Ansible - not sure why that is the case but this is what was causing my Ansible woes. My final working solution is to add the following to /etc/logstash/startup.options
before installing logstash:
JAVA_OPTS="@/etc/logstash/java_opts"
and create a /etc/logstash/java_opts
file (also prior to the installation) with the following content:
--add-opens java.base/sun.nio.ch=org.jruby.dist
--add-opens java.base/java.io=org.jruby.dist