-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Replace most shell script logic with Java #85758
Merged
Merged
Changes from 187 commits
Commits
Show all changes
193 commits
Select commit
Hold shift + click to select a range
917ee1e
stash
rjernst 3a0a7e2
Merge branch 'master' into launcher
rjernst 5ea8dbc
cleanup
rjernst 2bf16e1
plugin cli sort of works, invoked through cli tool manually
rjernst 3500ef7
plugin cli done (on nix)
rjernst 42f1bde
certutil converted
rjernst 483577f
use exec
rjernst b49edb4
use exec in certutil, remove <java17 checks
rjernst abefb36
move java version checking, use source instead of exec
rjernst e11e6a3
Fix version checker
rjernst 2ba7d99
convert geoip cli
rjernst b3dc890
convert keystore cli
rjernst eeff485
introspect toolname
rjernst 160bbcf
convert node and shard clis
rjernst eab9724
convert most security tools
rjernst 271096f
convert croneval
rjernst e0fb885
use es-env script again, so sql-cli can still use it
rjernst fdc695f
fix reconfigure tool
rjernst 64c65c6
convert postinst
rjernst 9129265
Update windows scripts to use launcher tool
williamrandolph 92e0247
Convert croneval.bat
williamrandolph 9292c78
Set config directory in elasticsearch-cli.bat
williamrandolph 3571c35
create server cli provider, move launcher stuff to it
rjernst fa15e1e
Use elasticsearch-env.bat in elasticsearch-cli.bat and in sql cli
williamrandolph 4c6f9e8
Don't hardcode tool names for windows batch
williamrandolph c76c8b7
Just get the filename
williamrandolph ab73844
Merge branch 'launcher' into launcher-wrb
williamrandolph 8ba04d0
more server cleanup, simplified logging init for clis
rjernst 4af0543
remove old main methods
rjernst e0b0b57
remove beforeMain hook
rjernst 8081db1
Call launcher in elasticsearch.bat
williamrandolph eea56b7
Merge branch 'launcher-wrb' into launcher
williamrandolph 43ab03f
Stub for windows service cli tool
williamrandolph 7401099
server sort of works, it starts!
rjernst 38b518d
remove old files
rjernst ccd695b
Merge branch 'launcher' into launcher-windows-service
williamrandolph d49e11b
daemonization works
rjernst d026aa7
some cleanup
rjernst aae9eb4
pass -E through to autoconfigurenode
rjernst 25de46e
Merge branch 'launcher-windows-service' into launcher
williamrandolph 444f6d4
add comment
rjernst 82cf495
windows service cli
rjernst dc9764a
windows service fixes
rjernst dbe21c4
more windows service fixes
rjernst 4b0d62b
and the toolprovider filename too
rjernst 76c32d5
remove old
rjernst f092e88
Merge branch 'master' into launcher
rjernst 9b3d6c9
Merge branch 'master' into launcher
rjernst e28acc6
spotless
rjernst 914d08a
remove old launcher
rjernst 0fdb858
fix windows service
rjernst 603c2f0
cleanup
rjernst 6060da4
move tests
rjernst b8e5422
Merge branch 'master' into launcher
rjernst 8f71d35
fix scripts to use correct env var
rjernst b8084b1
Merge branch 'master' into launcher
rjernst fcde65f
cleanups
rjernst 468569f
use quiet flag
rjernst 5551b3d
cleanup project config
rjernst 4ca5bbd
remove direct dep on cli since it is still part of server
rjernst 81fa06d
simplify checked exceptions
rjernst ee8d205
imports
rjernst 620b492
Merge branch 'master' into launcher
rjernst 55a0865
abstract start
rjernst 0503dea
Merge branch 'master' into launcher
rjernst 1a5e7b5
Merge branch 'master' into launcher
rjernst 9ac647e
trying to improve tests...
rjernst f836b17
Make env aware CLI command publicly runnable
rjernst 2113ecf
spotless
rjernst 1bd19e8
Merge branch 'cli/env_aware_access' into launcher
rjernst 8027ce4
get some tests working
rjernst 44eea73
remove zip source import, doesn't work for integ-test-zip
rjernst edf9d82
pass keystore password through
rjernst 76d6a4a
fix javadoc
rjernst b6a1382
fix forbidden
rjernst 7a3f0dc
spotless
rjernst 71f37e3
attempt windows fix for classpath
rjernst aac4d1a
add assertion, somehow cursor is empty
rjernst d025984
Merge branch 'master' into launcher
rjernst b894afb
fix docker process lookup
rjernst bc64782
defensive cursor
rjernst 9624c26
copy old comment
rjernst b9e4d9f
add check on enrollment token repeats
rjernst 228d167
move empty enrollemnt token test
rjernst 3e36905
spotless
rjernst cb9b7f9
cleanup
rjernst 7d92af7
remove old exit method
rjernst 22bf949
change back to private parser option
rjernst 7b97d7e
undo whitespace change
rjernst 437b34c
add debugging for keystore tests
rjernst 9777549
add back exit, for now
rjernst 569c1f3
allow child process in systemd to send notify
rjernst ea5696c
add comment
rjernst 5e2da7e
try different notify access
rjernst 1bbd4ea
add error debug
rjernst 686905c
add auto config tests
rjernst 023a5ad
fix keystore password reading
rjernst 386841e
simplify password passing to auto config
rjernst 94d2cee
use separate thread for pump
rjernst 7dcfcc3
improve tests
rjernst 737b9f5
spotless
rjernst a81b960
spotless again
rjernst 5d5c669
improve debug
rjernst c5f4576
more debug
rjernst fe2502e
implement close for server cli to propagate shutdown signal
rjernst fdbdbb1
wait for subprocess to die
rjernst 23272b8
attempt to send main pid back to systemd
rjernst d5f315b
fix server cli to not kill subprocess when daemonized
rjernst 33699c6
Merge branch 'master' into launcher
rjernst 9da910b
implement fake pid
rjernst 889e8bb
add debugging for auto config errors
rjernst 1bbcf34
more debug for windows
rjernst 189d632
improve stderr flush
rjernst 4087595
fix unit tests
rjernst 60e6840
improve windows cli
rjernst 0d375ca
fix env vars to server script
rjernst 7b20225
fix passthrough of enrollment token to auto config
rjernst 38f716e
fix windows service provider
rjernst 04091e4
fix test name
rjernst bda6dca
Merge branch 'master' into launcher
rjernst 8e088ca
remove display name from assertions
rjernst 8b1258a
tweak windows service test failure expectation
rjernst 937b0a8
add packaging test debug
rjernst 38d4712
more debugging for package tests
rjernst 25b9a40
another windows test
rjernst 242e111
spotless
rjernst ce91516
more packaging test debug
rjernst 67cb0d9
pass verbosity through to keystore terminal
rjernst 89539b2
attempting better windows service logs
rjernst b31e532
pass tool info as sysprops, not env for windows service
rjernst 4953f1e
more debug for packaging tests
rjernst 20e2dc2
spotless
rjernst 77ca898
Merge branch 'master' into launcher
rjernst 74634be
cleanup debug logging
rjernst 584da86
try leaving server cli as main process with systemd
rjernst a56f5fe
add debug for windows service
rjernst 39d13e6
add stop mode for windows service
rjernst 5614994
log more when cleanup fails
rjernst 6451adf
put command in the static, doh!
rjernst 0a97715
rework rework service cli command passing
rjernst 7069fcc
spotless
rjernst 46306e6
more windows debugging
rjernst 3e776f8
add systemd comment
rjernst 0f83215
remove systemd changes
rjernst c60196e
Merge branch 'master' into launcher
rjernst 55552ab
pass hostname through to windows service
rjernst f888299
Merge branch 'master' into launcher
rjernst fbeea85
fix compile
rjernst 77745ae
daemonize in the windows service
rjernst 7fdbeb3
don't pass quiet to windows service since we are now daemonizing
rjernst ae5457f
dump service logs on move failure
rjernst d6ad750
don't clear process handle for windows
rjernst 142a94e
move logic into ServerProcess, very broken right now
rjernst dc87ec7
use sysprop to avoid waiting when starting windows service
rjernst f481470
Merge branch 'launcher_refactor' into launcher
rjernst b334d5c
don't wait for stderr to close, jvm bug?
rjernst ae31299
spotless
rjernst a1018a5
Merge branch 'master' into launcher
rjernst 8b89c2e
fix bugs and add debugging
rjernst ed2cd51
exit pump early
rjernst 4bc1697
fix compile
rjernst 6a9c1af
copy bundled jdk instead of moving it
rjernst 2ca3bee
remove manager test, won't work with new clis
rjernst 27ba962
more debugging
rjernst 5f84788
more windows debugging
rjernst 98914a5
Merge branch 'master' into launcher
rjernst 5b7da1b
better large file error matching
rjernst 3870922
are these all nulls??
rjernst 18ebfeb
cleaner debug string
rjernst 4c4172d
Merge branch 'master' into launcher
rjernst a3dc55b
simpler read file again
rjernst db1f04f
let stderr pump fully drain
rjernst e4d7d4e
rework and document
rjernst 0953a70
Merge branch 'master' into launcher
rjernst 8289fc9
more javadocs
rjernst c6c0da5
more javadocs
rjernst 4aa2953
spotless
rjernst efabb33
forbidden
rjernst 5f617c3
Merge branch 'master' into launcher
rjernst cf0fe87
windows service tests
rjernst 0eb87f2
tests done
rjernst 3695181
revert large file handling
rjernst eb269c9
Merge branch 'master' into launcher
rjernst fa29cd9
fix command tests
rjernst 1c1c7c9
fix naming of windows service daemon
rjernst 48363b5
fix detach state
rjernst 358447a
spotless
rjernst 48b55a7
add enrollment token test
rjernst 3234bd4
guard against exceptional read errors
rjernst ce2a433
protect from unexpected exception in error pump
rjernst 83083e2
improve javadocs
rjernst 79ba71e
Merge branch 'master' into launcher
rjernst a7f9442
tweak for running test on windows
rjernst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,139 +1,5 @@ | ||
#!/bin/bash | ||
|
||
# CONTROLLING STARTUP: | ||
# | ||
# This script relies on a few environment variables to determine startup | ||
# behavior, those variables are: | ||
# | ||
# ES_PATH_CONF -- Path to config directory | ||
# ES_JAVA_OPTS -- External Java Opts on top of the defaults set | ||
# | ||
# Optionally, exact memory values can be set using the `ES_JAVA_OPTS`. Example | ||
# values are "512m", and "10g". | ||
# | ||
# ES_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/elasticsearch | ||
|
||
source "`dirname "$0"`"/elasticsearch-env | ||
|
||
CHECK_KEYSTORE=true | ||
ATTEMPT_SECURITY_AUTO_CONFIG=true | ||
DAEMONIZE=false | ||
ENROLL_TO_CLUSTER=false | ||
# Store original arg array as we will be shifting through it below | ||
ARG_LIST=("$@") | ||
|
||
while [ $# -gt 0 ]; do | ||
if [[ $1 == "--enrollment-token" ]]; then | ||
if [ $ENROLL_TO_CLUSTER = true ]; then | ||
echo "Multiple --enrollment-token parameters are not allowed" 1>&2 | ||
exit 1 | ||
fi | ||
ENROLL_TO_CLUSTER=true | ||
ATTEMPT_SECURITY_AUTO_CONFIG=false | ||
ENROLLMENT_TOKEN="$2" | ||
shift | ||
elif [[ $1 == "-h" || $1 == "--help" || $1 == "-V" || $1 == "--version" ]]; then | ||
CHECK_KEYSTORE=false | ||
ATTEMPT_SECURITY_AUTO_CONFIG=false | ||
elif [[ $1 == "-d" || $1 == "--daemonize" ]]; then | ||
DAEMONIZE=true | ||
fi | ||
if [[ $# -gt 0 ]]; then | ||
shift | ||
fi | ||
done | ||
|
||
if [ -z "$ES_TMPDIR" ]; then | ||
ES_TMPDIR=`"$JAVA" -cp "$SERVER_CLI_CLASSPATH" org.elasticsearch.server.cli.TempDirectory` | ||
fi | ||
|
||
if [ -z "$LIBFFI_TMPDIR" ]; then | ||
LIBFFI_TMPDIR="$ES_TMPDIR" | ||
export LIBFFI_TMPDIR | ||
fi | ||
|
||
# get keystore password before setting java options to avoid | ||
# conflicting GC configurations for the keystore tools | ||
unset KEYSTORE_PASSWORD | ||
KEYSTORE_PASSWORD= | ||
if [[ $CHECK_KEYSTORE = true ]] \ | ||
&& bin/elasticsearch-keystore has-passwd --silent | ||
then | ||
if ! read -s -r -p "Elasticsearch keystore password: " KEYSTORE_PASSWORD ; then | ||
echo "Failed to read keystore password on console" 1>&2 | ||
exit 1 | ||
fi | ||
fi | ||
|
||
if [[ $ENROLL_TO_CLUSTER = true ]]; then | ||
CLI_NAME="auto-configure-node" \ | ||
CLI_LIBS="modules/x-pack-core,modules/x-pack-security,lib/tools/security-cli" \ | ||
bin/elasticsearch-cli "${ARG_LIST[@]}" <<<"$KEYSTORE_PASSWORD" | ||
elif [[ $ATTEMPT_SECURITY_AUTO_CONFIG = true ]]; then | ||
# It is possible that an auto-conf failure prevents the node from starting, but this is only the exceptional case (exit code 1). | ||
# Most likely an auto-conf failure will leave the configuration untouched (exit codes 73, 78 and 80), optionally printing a message | ||
# if the error is uncommon or unexpected, but it should otherwise let the node to start as usual. | ||
# It is passed in all the command line options in order to read the node settings ones (-E), while the other parameters are ignored | ||
# (a small caveat is that it also inspects the -v option in order to provide more information on how auto config went) | ||
if CLI_NAME="auto-configure-node" \ | ||
CLI_LIBS="modules/x-pack-core,modules/x-pack-security,lib/tools/security-cli" \ | ||
bin/elasticsearch-cli "${ARG_LIST[@]}" <<<"$KEYSTORE_PASSWORD"; then | ||
: | ||
else | ||
retval=$? | ||
# these exit codes cover the cases where auto-conf cannot run but the node should NOT be prevented from starting as usual | ||
# eg the node is restarted, is already configured in an incompatible way, or the file system permissions do not allow it | ||
if [[ $retval -ne 80 ]] && [[ $retval -ne 73 ]] && [[ $retval -ne 78 ]]; then | ||
exit $retval | ||
fi | ||
fi | ||
fi | ||
|
||
# The JVM options parser produces the final JVM options to start Elasticsearch. | ||
# It does this by incorporating JVM options in the following way: | ||
# - first, system JVM options are applied (these are hardcoded options in the | ||
# parser) | ||
# - second, JVM options are read from jvm.options and jvm.options.d/*.options | ||
# - third, JVM options from ES_JAVA_OPTS are applied | ||
# - fourth, ergonomic JVM options are applied | ||
ES_JAVA_OPTS=`export ES_TMPDIR; "$JAVA" -cp "$SERVER_CLI_CLASSPATH" -Des.distribution.type="$ES_DISTRIBUTION_TYPE" org.elasticsearch.server.cli.JvmOptionsParser "$ES_PATH_CONF" "$ES_HOME/plugins"` | ||
|
||
# Remove enrollment related parameters before passing the arg list to Elasticsearch | ||
for i in "${!ARG_LIST[@]}"; do | ||
if [[ ${ARG_LIST[i]} = "--enrollment-token" || ${ARG_LIST[i]} = "$ENROLLMENT_TOKEN" ]]; then | ||
unset 'ARG_LIST[i]' | ||
fi | ||
done | ||
|
||
# manual parsing to find out, if process should be detached | ||
if [[ $DAEMONIZE = false ]]; then | ||
exec \ | ||
"$JAVA" \ | ||
$ES_JAVA_OPTS \ | ||
-Des.path.home="$ES_HOME" \ | ||
-Des.path.conf="$ES_PATH_CONF" \ | ||
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \ | ||
-cp "$ES_CLASSPATH" \ | ||
org.elasticsearch.bootstrap.Elasticsearch \ | ||
"${ARG_LIST[@]}" <<<"$KEYSTORE_PASSWORD" | ||
else | ||
exec \ | ||
"$JAVA" \ | ||
$ES_JAVA_OPTS \ | ||
-Des.path.home="$ES_HOME" \ | ||
-Des.path.conf="$ES_PATH_CONF" \ | ||
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \ | ||
-cp "$ES_CLASSPATH" \ | ||
org.elasticsearch.bootstrap.Elasticsearch \ | ||
"${ARG_LIST[@]}" \ | ||
<<<"$KEYSTORE_PASSWORD" & | ||
retval=$? | ||
pid=$! | ||
[ $retval -eq 0 ] || exit $retval | ||
if ! ps -p $pid > /dev/null ; then | ||
exit 1 | ||
fi | ||
exit 0 | ||
fi | ||
|
||
exit $? | ||
CLI_NAME=server | ||
CLI_LIBS=lib/tools/server-cli | ||
source "`dirname "$0"`"/elasticsearch-cli | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anticipating that the java process launch will be heavier on resources than the bash script, can we add an additional JVM command line option here to stop the JDK from using the optimizing compiler, i.e. -XX:TieredStopAtLevel=1. This will reduce both startup time, CPU and memory usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be for all CLIs or just server?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we were still launching Java processes before (JVM options parser, ergonomics, etc) so I don't think we've added any overhead here in terms of JVM startup, we've just consolidated some of that logic. I'd be surprised if there was any measurable change here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was thinking about it. If most of our cli tools are generally short running we should use it by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I'll take it upon myself to get some data on CPU/memory while running without the optimizing compiler and maybe if it's beneficial to a great extent, I'll follow up with a PR.