systemd.asciidoc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ==== Running Elasticsearch with `systemd`
  2. To configure Elasticsearch to start automatically when the system boots up,
  3. run the following commands:
  4. [source,sh]
  5. --------------------------------------------------
  6. sudo /bin/systemctl daemon-reload
  7. sudo /bin/systemctl enable elasticsearch.service
  8. --------------------------------------------------
  9. Elasticsearch can be started and stopped as follows:
  10. [source,sh]
  11. --------------------------------------------
  12. sudo systemctl start elasticsearch.service
  13. sudo systemctl stop elasticsearch.service
  14. --------------------------------------------
  15. These commands provide no feedback as to whether Elasticsearch was started
  16. successfully or not. Instead, this information will be written in the log
  17. files located in `/var/log/elasticsearch/`.
  18. If you have password-protected your {es} keystore, you will need to provide
  19. `systemd` with the keystore password using a local file and systemd environment
  20. variables. This local file should be protected while it exists and may be
  21. safely deleted once Elasticsearch is up and running.
  22. [source,sh]
  23. -----------------------------------------------------------------------------------
  24. echo "keystore_password" > /path/to/my_pwd_file.tmp
  25. chmod 600 /path/to/my_pwd_file.tmp
  26. sudo systemctl set-environment ES_KEYSTORE_PASSPHRASE_FILE=/path/to/my_pwd_file.tmp
  27. sudo systemctl start elasticsearch.service
  28. -----------------------------------------------------------------------------------
  29. By default the Elasticsearch service doesn't log information in the `systemd`
  30. journal. To enable `journalctl` logging, the `--quiet` option must be removed
  31. from the `ExecStart` command line in the `elasticsearch.service` file.
  32. When `systemd` logging is enabled, the logging information are available using
  33. the `journalctl` commands:
  34. To tail the journal:
  35. [source,sh]
  36. --------------------------------------------
  37. sudo journalctl -f
  38. --------------------------------------------
  39. To list journal entries for the elasticsearch service:
  40. [source,sh]
  41. --------------------------------------------
  42. sudo journalctl --unit elasticsearch
  43. --------------------------------------------
  44. To list journal entries for the elasticsearch service starting from a given time:
  45. [source,sh]
  46. --------------------------------------------
  47. sudo journalctl --unit elasticsearch --since "2016-10-30 18:17:16"
  48. --------------------------------------------
  49. Check `man journalctl` or https://www.freedesktop.org/software/systemd/man/journalctl.html for
  50. more command line options.
  51. [TIP]
  52. .Startup timeouts with older `systemd` versions
  53. ====
  54. By default {es} sets the `TimeoutStartSec` parameter to `systemd` to `900s`. If
  55. you are running at least version 238 of `systemd` then {es} can automatically
  56. extend the startup timeout, and will do so repeatedly until startup is complete
  57. even if it takes longer than 900s.
  58. Versions of `systemd` prior to 238 do not support the timeout extension
  59. mechanism and will terminate the {es} process if it has not fully started up
  60. within the configured timeout. If this happens, {es} will report in its logs
  61. that it was shut down normally a short time after it started:
  62. [source,text]
  63. -------------
  64. [2022-01-31T01:22:31,077][INFO ][o.e.n.Node ] [instance-0000000123] starting ...
  65. ...
  66. [2022-01-31T01:37:15,077][INFO ][o.e.n.Node ] [instance-0000000123] stopping ...
  67. -------------
  68. However the `systemd` logs will report that the startup timed out:
  69. [source,text]
  70. -------------
  71. Jan 31 01:22:30 debian systemd[1]: Starting Elasticsearch...
  72. Jan 31 01:37:15 debian systemd[1]: elasticsearch.service: Start operation timed out. Terminating.
  73. Jan 31 01:37:15 debian systemd[1]: elasticsearch.service: Main process exited, code=killed, status=15/TERM
  74. Jan 31 01:37:15 debian systemd[1]: elasticsearch.service: Failed with result 'timeout'.
  75. Jan 31 01:37:15 debian systemd[1]: Failed to start Elasticsearch.
  76. -------------
  77. To avoid this, upgrade your `systemd` to at least version 238. You can also
  78. temporarily work around the problem by extending the `TimeoutStartSec`
  79. parameter.
  80. ====