Skip to content

Apache Lucene open-source search software

SOLR-7826: Refuse "bin/solr create" if run as root, unless -force is specified

Jan Høydahl7561461f738a
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index bf81f39a77a..0119917c778 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -152,6 +152,8 @@ Other Changes
* SOLR-9508: Install script install_solr_service.sh now checks existence of tools.
New option -n to avoid starting service after installation (janhoy)
+* SOLR-7826: Refuse "bin/solr create" if run as root, unless -force is specified (janhoy, Binoy Dalal)
+
================== 6.2.1 ==================
Bug Fixes
diff --git a/solr/bin/solr b/solr/bin/solr
index 46903e7c3a1..e2a665d92cb 100755
--- a/solr/bin/solr
+++ b/solr/bin/solr
@@ -696,6 +696,7 @@ if [[ "$SCRIPT_CMD" == "create" || "$SCRIPT_CMD" == "create_core" || "$SCRIPT_CM
CREATE_NUM_SHARDS=1
CREATE_REPFACT=1
+ FORCE=false
if [ $# -gt 0 ]; then
while true; do
@@ -748,6 +749,10 @@ if [[ "$SCRIPT_CMD" == "create" || "$SCRIPT_CMD" == "create_core" || "$SCRIPT_CM
CREATE_PORT="$2"
shift 2
;;
+ -force)
+ FORCE=true
+ shift
+ ;;
-help|-usage)
print_usage "$SCRIPT_CMD"
exit 0
@@ -805,6 +810,11 @@ if [[ "$SCRIPT_CMD" == "create" || "$SCRIPT_CMD" == "create_core" || "$SCRIPT_CM
exit 1
fi
+ if [[ "$(whoami)" == "root" ]] && [[ "$FORCE" == "false" ]] ; then
+ echo "WARNING: Creating cores as the root user can cause Solr to fail and is not advisable. Exiting."
+ echo " If you started Solr as root (not advisable either), force core creation by adding argument -force"
+ exit 1
+ fi
if [ "$SCRIPT_CMD" == "create_core" ]; then
run_tool create_core -name "$CREATE_NAME" -solrUrl "$SOLR_URL_SCHEME://$SOLR_TOOL_HOST:$CREATE_PORT/solr" \
-confdir "$CREATE_CONFDIR" -configsetsDir "$SOLR_TIP/server/solr/configsets"