This is an automated email from the ASF dual-hosted git repository. dsmiley pushed a commit to branch branch_10x in repository https://gitbox.apache.org/repos/asf/solr.git
commit df074600e56352b82b0fa0bb224e5d8eb02e1100 Author: Jan Høydahl <[email protected]> AuthorDate: Thu Nov 5 23:23:39 2026 +0100 Add a picocli restart command so 'bin/solr restart --help' works (#5286) (cherry picked from commit e1799d8a71726bd8ec2ad69f1e3a4b5c4f3e019f) --- .../java/org/apache/solr/cli/RestartCommand.java | 49 ++++++++ .../core/src/java/org/apache/solr/cli/SolrCLI.java | 1 + .../org/apache/solr/cli/SolrCLIPicocliTest.java | 13 +++ .../modules/deployment-guide/deployment-nav.adoc | 1 + .../modules/deployment-guide/pages/cli/index.adoc | 1 + .../deployment-guide/pages/cli/solr-restart.adoc | 128 +++++++++++++++++++++ 6 files changed, 193 insertions(+) diff --git a/solr/core/src/java/org/apache/solr/cli/RestartCommand.java b/solr/core/src/java/org/apache/solr/cli/RestartCommand.java new file mode 100644 index 00000000000..d509e07b0f1 --- /dev/null +++ b/solr/core/src/java/org/apache/solr/cli/RestartCommand.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.cli; + +import picocli.CommandLine; + +/** + * This class is currently only used for printing CLI usage. The restart logic is currently handled + * in the start script, which parses the same options as {@code start} plus the stop key. + */ [email protected]( + name = "restart", + description = "Restarts Solr.", + footerHeading = "%nExamples:%n", + footer = { + " # Restart Solr running on the default port", + " bin/solr restart", + "", + " # Restart Solr running on a custom port with 2g heap", + " bin/solr restart -p 8984 -m 2g" + }) +public class RestartCommand extends StartCommand { + + @CommandLine.Option( + names = {"-k", "--key"}, + description = "Stop key; default is solrrocks", + defaultValue = "solrrocks") + String key; + + /** The bin/solr script performs the restart; this command only documents its options. */ + @Override + public Integer call() { + return 0; + } +} diff --git a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java index 555b30bf7c8..ca1b3e3b4b1 100755 --- a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java +++ b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java @@ -75,6 +75,7 @@ import org.slf4j.LoggerFactory; subcommands = { StartCommand.class, StopCommand.class, + RestartCommand.class, StatusTool.class, VersionTool.class, ZkTool.class, diff --git a/solr/core/src/test/org/apache/solr/cli/SolrCLIPicocliTest.java b/solr/core/src/test/org/apache/solr/cli/SolrCLIPicocliTest.java index 7929150b788..c73fa2df925 100644 --- a/solr/core/src/test/org/apache/solr/cli/SolrCLIPicocliTest.java +++ b/solr/core/src/test/org/apache/solr/cli/SolrCLIPicocliTest.java @@ -116,6 +116,19 @@ public class SolrCLIPicocliTest extends SolrTestCase { } } + /** + * The bin/solr script handles start, stop and restart itself, but still hands {@code --help} for + * them to this tool, so each one must be a registered command. + */ + @Test + public void testScriptHandledCommandsAreRegistered() { + for (String name : new String[] {"start", "stop", "restart"}) { + assertNotNull( + "'bin/solr " + name + " --help' is dispatched to the tool, so " + name + " must exist", + rootCommand().getSubcommands().get(name)); + } + } + /** {@code --version} is only meaningful on the top-level command. */ @Test public void testOnlyRootDeclaresVersionOption() { diff --git a/solr/solr-ref-guide/modules/deployment-guide/deployment-nav.adoc b/solr/solr-ref-guide/modules/deployment-guide/deployment-nav.adoc index e22a51c7be1..f267abf8bd6 100644 --- a/solr/solr-ref-guide/modules/deployment-guide/deployment-nav.adoc +++ b/solr/solr-ref-guide/modules/deployment-guide/deployment-nav.adoc @@ -41,6 +41,7 @@ **** xref:cli/solr-package-uninstall.adoc[uninstall] *** xref:cli/solr-post.adoc[post] *** xref:cli/solr-postlogs.adoc[postlogs] +*** xref:cli/solr-restart.adoc[restart] *** xref:cli/solr-snapshot.adoc[snapshot] **** xref:cli/solr-snapshot-create.adoc[create] **** xref:cli/solr-snapshot-delete.adoc[delete] diff --git a/solr/solr-ref-guide/modules/deployment-guide/pages/cli/index.adoc b/solr/solr-ref-guide/modules/deployment-guide/pages/cli/index.adoc index fb8ea48e30e..d1b55f01912 100644 --- a/solr/solr-ref-guide/modules/deployment-guide/pages/cli/index.adoc +++ b/solr/solr-ref-guide/modules/deployment-guide/pages/cli/index.adoc @@ -80,6 +80,7 @@ Any command not listed here is unavailable when the picocli implementation is en |xref:cli/solr-package.adoc[bin/solr package] |xref:cli/solr-post.adoc[bin/solr post] |xref:cli/solr-postlogs.adoc[bin/solr postlogs] +|xref:cli/solr-restart.adoc[bin/solr restart] |xref:cli/solr-snapshot-create.adoc[bin/solr snapshot create] |xref:cli/solr-snapshot-delete.adoc[bin/solr snapshot delete] |xref:cli/solr-snapshot-describe.adoc[bin/solr snapshot describe] diff --git a/solr/solr-ref-guide/modules/deployment-guide/pages/cli/solr-restart.adoc b/solr/solr-ref-guide/modules/deployment-guide/pages/cli/solr-restart.adoc new file mode 100644 index 00000000000..f153af22996 --- /dev/null +++ b/solr/solr-ref-guide/modules/deployment-guide/pages/cli/solr-restart.adoc @@ -0,0 +1,128 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// +// DO NOT EDIT -- this page is auto-generated from picocli annotations. +// To update: modify the @Command/@Option annotations in the Java source, then run: +// ./gradlew :solr:solr-ref-guide:generateCliDocs + += bin/solr restart +:page-toclevels: 2 + +[WARNING] +==== +This page documents the *experimental* picocli implementation of `bin/solr`, which is not enabled by default. +For what `bin/solr` does by default, see xref:solr-control-script-reference.adoc[]. +See xref:cli/index.adoc[] to enable this implementation and for its known limitations. +==== + +// tag::picocli-generated-man-section-synopsis[] +== Synopsis + +.... +bin/solr restart [-fhqy] [--force] [--user-managed] [--verbose] + [--data-home=<dataHome>] [-e=<example>] + [--example-dir=<exampleDir>] [--host=<host>] [-j=<jettyParams>] + [--jvm-opts=<jvmOpts>] [-k=<key>] [-m=<memory>] [-p=<port>] + [--script-inputs=<values>] [--server-dir=<serverDir>] + [--solr-home=<solrHome>] [-z=<zkHost>] +.... + +// end::picocli-generated-man-section-synopsis[] + +// tag::picocli-generated-man-section-description[] +== Description + +Restarts Solr. + +// end::picocli-generated-man-section-description[] + +// tag::picocli-generated-man-section-options[] +== Options + +*--data-home*=_<dataHome>_:: + Set solr.data.home system property for index data storage; default is solr.solr.home + +*-e*, *--example*=_<example>_:: + Run an example: cloud, techproducts, schemaless, films + +*--example-dir*=_<exampleDir>_:: + Override the directory containing example configurations used when running examples with --example + +*-f*, *--foreground*:: + Start Solr in foreground; default is background with logs to solr-PORT-console.log + +*--force*:: + Override warning when attempting to start Solr as root user + +*-h*, *--help*:: + Print this help message and exit. + +*--host*=_<host>_:: + Specify the hostname this Solr node will advertise to ZooKeeper and other cluster members (SOLR_HOST_ADVERTISE). Defaults to the canonical hostname of the local host. + +*-j*, *--jettyconfig*=_<jettyParams>_:: + Additional Jetty parameters, e.g., -j "--include-jetty-dir=/etc/jetty/custom/server/" + +*--jvm-opts*=_<jvmOpts>_:: + Additional JVM parameters, e.g., --jvm-opts "-verbose:gc" + +*-k*, *--key*=_<key>_:: + Stop key; default is solrrocks + +*-m*, *--memory*=_<memory>_:: + Set JVM heap size, e.g., -m 4g sets -Xms4g -Xmx4g; default is 512m + +*-p*, *--port*=_<port>_:: + Specify the Solr HTTP port; default is 8983. STOP_PORT=($SOLR_PORT-1000), RMI_PORT=($SOLR_PORT+10000) + +*-q*, *--quiet*:: + Set log level to WARN (quiet); default is INFO + +*--script-inputs*=_<values>_:: + Don't prompt for input; comma-delimited list of inputs to use when running examples that accept user input + +*--server-dir*=_<serverDir>_:: + Specify the Solr server directory; default is 'server' + +*--solr-home*=_<solrHome>_:: + Set solr.solr.home system property; default is 'server/solr'. Ignored in examples mode + +*--user-managed*:: + Start Solr in standalone mode. Default is SolrCloud (ZooKeeper) mode. + +*--verbose*:: + Set log level to DEBUG (verbose); default is INFO + +*-y*, *--no-prompt*:: + Don't prompt for input; accept all defaults when running examples + +*-z*, *--zk-host*=_<zkHost>_:: + Zookeeper connection string; default is to start an embedded ZooKeeper on PORT+10000 + +// end::picocli-generated-man-section-options[] + +// tag::picocli-generated-man-section-footer[] +== Examples +[%hardbreaks] + # Restart Solr running on the default port + bin/solr restart + +[%hardbreaks] + # Restart Solr running on a custom port with 2g heap + bin/solr restart -p 8984 -m 2g + +// end::picocli-generated-man-section-footer[]
