Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-6962: bin/solr stop/start/restart should complain about missing value for options that expect a value. (#2671)

Eric Pugh34f77886104a
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 26bc501b463..bac9c16ec23 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -155,6 +155,8 @@ Bug Fixes
* SOLR-16254: Clarify when a bin/solr create needs to be run on the same server as Solr. (Eric Pugh)
+* SOLR-6962: bin/solr stop/start/restart should complain about missing value for options that expect a value. (Eric Pugh, Rahul Goswami)
+
Dependency Upgrades
---------------------
(No changes)
diff --git a/solr/bin/solr b/solr/bin/solr
index 036775a766b..d02d2c6545f 100755
--- a/solr/bin/solr
+++ b/solr/bin/solr
@@ -648,7 +648,7 @@ if [[ "$SCRIPT_CMD" == "auth" ]]; then
echo -e "\nSolr server directory $SOLR_SERVER_DIR not found!\n"
exit 1
fi
-
+
if [ -z "${SOLR_HOME:-}" ]; then
SOLR_HOME="$SOLR_SERVER_DIR/solr"
elif [[ $SOLR_HOME != /* ]]; then
@@ -659,7 +659,7 @@ if [[ "$SCRIPT_CMD" == "auth" ]]; then
SOLR_PID_DIR="$SOLR_HOME"
fi
fi
-
+
if [ -z "${AUTH_PORT:-}" ]; then
for ID in $(ps auxww | grep java | grep start\.jar | awk '{print $2}' | sort -r)
do
@@ -669,22 +669,18 @@ if [[ "$SCRIPT_CMD" == "auth" ]]; then
break
fi
done
- fi
-
+ fi
+
run_tool auth $@ --solr-url "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:${AUTH_PORT:-8983}" --auth-conf-dir "$SOLR_HOME" "--solr-include-file" "$SOLR_INCLUDE"
exit $?
fi
-# at this point all tools that have a custom run process, like "status" and "auth" have been run and exited.
+# at this point all tools that have a custom run process, like "status" and "auth" have been run and exited.
# Unless a command is one of the ones in the if clause below, we will just run it with the default run_tool function and then exit.
if [ "$SCRIPT_CMD" != "start" ] && [ "$SCRIPT_CMD" != "stop" ] && [ "$SCRIPT_CMD" != "restart" ]; then
# hand off the command to the SolrCLI and let it handle the option parsing and validation
run_tool "$SCRIPT_CMD" "$@"
- ret=$?
- if [ $ret -ne 0 ]; then
- exit $ret
- fi
- exit 0
+ exit $?
fi
# Everything below here is to support start, stop and restart.
@@ -695,7 +691,7 @@ fi
: "${SOLR_RECOMMENDED_OPEN_FILES:=65000}"
if [[ "${SOLR_ULIMIT_CHECKS:-}" != "false" ]]; then
- if [ "$SCRIPT_CMD" == "start" ] || [ "$SCRIPT_CMD" == "restart" ] || [ "$SCRIPT_CMD" == "status" ]; then
+ if [ "$SCRIPT_CMD" == "start" ] || [ "$SCRIPT_CMD" == "restart" ]; then
if hash ulimit 2>/dev/null; then
openFiles=$(ulimit -n)
maxProcs=$(ulimit -u)
@@ -832,16 +828,28 @@ if [ $# -gt 0 ]; then
shift 2
;;
-a|--jvm-opts|-addlopts)
+ if [[ -z "$2" ]]; then
+ print_usage "$SCRIPT_CMD" "JVM options are required when using the $1 option!"
+ exit 1
+ fi
ADDITIONAL_CMD_OPTS="$2"
PASS_TO_RUN_EXAMPLE+=("--jvm-opts" "$ADDITIONAL_CMD_OPTS")
shift 2
;;
-j|--jettyconfig|-jettyconfig)
+ if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
+ print_usage "$SCRIPT_CMD" "Jetty config is required when using the $1 option!"
+ exit 1
+ fi
ADDITIONAL_JETTY_CONFIG="$2"
PASS_TO_RUN_EXAMPLE+=("-j" "$ADDITIONAL_JETTY_CONFIG")
shift 2
;;
-k|--key|-key)
+ if [[ -z "$2" || "${2:0:1}" == "-" ]]; then
+ print_usage "$SCRIPT_CMD" "Stop key is required when using the $1 option!"
+ exit 1
+ fi
STOP_KEY="$2"
shift 2
;;
@@ -1226,7 +1234,7 @@ else
SECURITY_MANAGER_OPTS=()
fi
-# Enable ADMIN UI by default, and give the option for users to disable it
+# Enable Admin UI by default, and give the option for users to disable it
if [ "${SOLR_ADMIN_UI_DISABLED:-false}" == "true" ]; then
SOLR_ADMIN_UI="-DdisableAdminUI=true"
echo -e "ADMIN UI Disabled"
diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd
index 49f08502dae..287daec0834 100755
--- a/solr/bin/solr.cmd
+++ b/solr/bin/solr.cmd
@@ -425,8 +425,8 @@ IF "%1"=="--zkHost" goto set_zookeeper
IF "%1"=="-s" goto set_solr_url
IF "%1"=="--solr-url" goto set_solr_url
IF "%1"=="-solrUrl" goto set_solr_url
-IF "%1"=="-a" goto set_addl_opts
-IF "%1"=="--jvm-opts" goto set_addl_opts
+IF "%1"=="-a" goto set_jvm_opts
+IF "%1"=="--jvm-opts" goto set_jvm_opts
IF "%1"=="-j" goto set_addl_jetty_config
IF "%1"=="--jettyconfig" goto set_addl_jetty_config
IF "%1"=="--noprompt" goto set_noprompt
@@ -661,9 +661,12 @@ SHIFT
SHIFT
goto parse_args
-:set_addl_opts
+:set_jvm_opts
set "arg=%~2"
set "SOLR_ADDL_ARGS=%~2"
+IF "%SOLR_ADDL_ARGS%"=="" (
+ set "EMPTY_ADDL_JVM_ARGS=true"
+)
SHIFT
SHIFT
goto parse_args
@@ -875,6 +878,11 @@ IF "%SCRIPT_CMD%"=="start" (
)
)
)
+
+ IF "%EMPTY_ADDL_JVM_ARGS%"=="true" (
+ set "SCRIPT_ERROR=JVM options are required when using the -a or --jvm-opts option!"
+ goto err
+ )
)
@REM determine if -server flag is supported by current JVM
diff --git a/solr/packaging/test/test_start_solr.bats b/solr/packaging/test/test_start_solr.bats
index 170aeccc02d..c185128b219 100644
--- a/solr/packaging/test/test_start_solr.bats
+++ b/solr/packaging/test/test_start_solr.bats
@@ -49,3 +49,17 @@ teardown() {
solr assert --started http://localhost:${SOLR_PORT} --timeout 5000
}
+
+@test "check stop command doesn't hang" {
+ # for start/stop/restart we parse the args separate from picking the command
+ # which means you don't get an error message for passing a start arg, like --jvm-opts to a stop commmand.
+
+ # Set a timeout duration (in seconds)
+ TIMEOUT_DURATION=2
+
+ # make sure that passing a non flag option (i.e --jvm-opts "blah") doesn't hang the stop command.
+ run timeout $TIMEOUT_DURATION solr stop --jvm-opts
+
+ assert_output --partial "ERROR: JVM options are required when using the --jvm-opts option!"
+
+}