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

Expose logs to systemd users #46900

Closed
DaveCTurner opened this issue Sep 20, 2019 · 7 comments · Fixed by #47208
Closed

Expose logs to systemd users #46900

DaveCTurner opened this issue Sep 20, 2019 · 7 comments · Fixed by #47208
Assignees
Labels
:Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts help wanted adoptme Team:Delivery Meta label for Delivery team

Comments

@DaveCTurner
Copy link
Contributor

We get more than a few posts on the forums like this one complaining about Elasticsearch stopping shortly after starting and quoting the output from systemd:

 elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2019-08-26 09:39:21 EST; 5min ago
     Docs: http://www.elastic.co
  Process: 881 ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet (code=exited, status=78)
 Main PID: 881 (code=exited, status=78)

Aug 26 09:39:09 p2e systemd[1]: Started Elasticsearch.
Aug 26 09:39:10 p2e elasticsearch[881]: OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be r
Aug 26 09:39:21 p2e systemd[1]: elasticsearch.service: Main process exited, code=exited, status=78/n/a
Aug 26 09:39:21 p2e systemd[1]: elasticsearch.service: Unit entered failed state.
Aug 26 09:39:21 p2e systemd[1]: elasticsearch.service: Failed with result 'exit-code'.

Often (as in the post linked above) this is after adjusting network.host and the reason Elasticsearch is shutting down is due to a bootstrap check that now fails. However there is no indication here that there is more information in some other logs, and volunteers on the forum must spend time helping users to find this extra information.

Can we improve this? For instance, can we expose the location of the Elasticsearch logs in this output? It looks like stderr is exposed above, because of the OpenJDK 64-Bit Server VM warning line. Could we emit a message on stderr that points the user to the log file? Or maybe we can expose stdout here too?

@DaveCTurner DaveCTurner added :Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts team-discuss labels Sep 20, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@jasontedor
Copy link
Member

Or maybe we can expose stdout here too?

Relates #17220

@rjernst rjernst added help wanted adoptme and removed team-discuss labels Sep 25, 2019
@pugnascotia
Copy link
Contributor

Interestingly, if I replicate the problem of setting network.host and thereby causing the bootstrap checks to fail, I get the following printed to STDERR (on master):

$ ./bin/elasticsearch > /dev/null
Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

Whereas in the snippet above we only see the JVM warning line. I should point out however, that I get this from running bin/elasticsearch directory from a tarball, so the situation may be different when running through systemd.

@jasontedor
Copy link
Member

@pugnascotia Note that in our systemd startup script we pass --quiet which closes the standard streams:

final boolean closeStandardStreams = (foreground == false) || quiet;
try {
if (closeStandardStreams) {
final Logger rootLogger = LogManager.getRootLogger();
final Appender maybeConsoleAppender = Loggers.findAppender(rootLogger, ConsoleAppender.class);
if (maybeConsoleAppender != null) {
Loggers.removeAppender(rootLogger, maybeConsoleAppender);
}
closeSystOut();
}
and
if (closeStandardStreams) {
closeSysError();
}

@jasontedor
Copy link
Member

I think closing system error in any situation is a mistake. 🤷‍♀

@pugnascotia
Copy link
Contributor

So we could just stop closing system error, and that should let any errors through to e.g. systemd. We could also print a message about the logs dir, for completeness.

@pugnascotia pugnascotia self-assigned this Sep 26, 2019
@jasontedor
Copy link
Member

Yes, I don't think we should passthrough stdout to the journal, only stderr.

pugnascotia added a commit to pugnascotia/elasticsearch that referenced this issue Sep 27, 2019
Closes elastic#46900. When running ES with --quiet, if ES then exits
abnormally, a user has to go hunting in the logs for the error. Instead,
never close System.err, and print more information to it if ES
encounters a fatal error e.g.  config validation, or some fatal runtime
exception.
pugnascotia added a commit that referenced this issue Nov 15, 2019
Closes #46900. When running ES with `--quiet`, if ES then exits abnormally, a
user has to go hunting in the logs for the error. Instead, never close
System.err, and print more information to it if ES encounters a fatal error
e.g. config validation, or some fatal runtime exception. This is useful when
running under e.g. systemd, since the error will go into the journal.

Note that stderr is still closed in daemon (`-d`) mode.
pugnascotia added a commit to pugnascotia/elasticsearch that referenced this issue Nov 21, 2019
Closes elastic#46900. When running ES with `--quiet`, if ES then exits abnormally, a
user has to go hunting in the logs for the error. Instead, never close
System.err, and print more information to it if ES encounters a fatal error
e.g. config validation, or some fatal runtime exception. This is useful when
running under e.g. systemd, since the error will go into the journal.

Note that stderr is still closed in daemon (`-d`) mode.
pugnascotia added a commit that referenced this issue Nov 22, 2019
Backport of #47208.

Closes #46900. When running ES with `--quiet`, if ES then exits abnormally, a
user has to go hunting in the logs for the error. Instead, never close
System.err, and print more information to it if ES encounters a fatal error
e.g. config validation, or some fatal runtime exception. This is useful when
running under e.g. systemd, since the error will go into the journal.

Note that stderr is still closed in daemon (`-d`) mode.
@mark-vieira mark-vieira added the Team:Delivery Meta label for Delivery team label Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts help wanted adoptme Team:Delivery Meta label for Delivery team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants